I want to control a stepper motor (SY42STH38- 1684A) with a raspberry pi using the motor driver TMC2130. It has 3 operating mode and i’m chosing the step/dir one. This should be easy, i have soldered the SPI_mode to GND to disable it as per the datasheet and connected the two pins STEP/DIR to the 27 and 22 gpios of the raspberry pi. Here is the code i would like to use, a very simple one but i don’t have the correct output.
#include <iostream>
#include <unistd.h>
#include <pigpio.h>
using namespace std;
const uint8_t DIR_PIN = 27;
const uint8_t STEP_PIN = 22;
void init()
{
gpioSetMode(DIR_PIN, PI_OUTPUT);
gpioSetMode(STEP_PIN, PI_OUTPUT);
}
void StepMotor()
{
for (int i = 0; i < 100; ++i)
{
gpioWrite(STEP_PIN, 1);
usleep(5000); // 1ms delay
gpioWrite(STEP_PIN, 0);
usleep(5000); // 1ms delay
}
sleep(3);
}
int main()
{
if (gpioInitialise() < 0)
{
cerr << "pigpio initialization failed." << endl;
return -1;
}
init();
sleep (0.1);
while (true)
{
gpioWrite(DIR_PIN, 0);
cout << "Clockwise rotation" << endl;
StepMotor();
//sleep(3); // 3 seconds pause
gpioWrite(DIR_PIN, 1);
cout << "Counter-clockwise rotation" << endl;
StepMotor();
//sleep(3); // 3 seconds pause
}
gpioTerminate();
return 0;
}
I am powering my motor with 6V and have calculated the Vref to be approximately 1.7A (ajutsed with the driver potentiometer). I also have connected the SCK and SDI pin to GND so i have fullSteps.
I have trie changing the delay between when the step pin is HIGH and LOW, the value of the tension send to the motor. I was expecting to have the motor do a full rotation one way then the other but I only feel and hear the motor vibrating. Sometimes it moves a bit but not as much as I would expect.
Juliette Lavender is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.