ESP32-S3 / NEMA17 / TMC stepper driver. Need it to run at a consistent speed

89 views
Skip to first unread message

Brian Hayward

unread,
Aug 23, 2024, 12:19:45 AMAug 23
to accelstepper

Using an ESP32-S3 w/a TMC 2209 driver and a nema 17 motor.

I would ultimately like to run this motor at 5 revolutions per hour, but in the mean time I'm just trying to get it to run at a constant speed smoothly at any speed.

With the following code, It moves a short distance, then stops, pauses for 2-3 seconds.   Then moves a short distance, and stops, pauses for 2-3 seconds, and so on.  The short distance is 50 steps, which matches what I passed to setSpeed().

During the pause, the motor is not locked - I can turn the shaft.  While moving, it cannot be turned.  Sometimes it shifts backward a tiny bit after stopping.

AccelStepper myStepper(1, stepPin, dirPin);

void setup()
{
myStepper.setMaxSpeed(1000); // this limits the value of setSpeed(). Raise it if you like.
myStepper.setSpeed(50); // runSpeed() will run the motor at this speed - set it to whatever you like.
}

void loop()
{
myStepper.runSpeed(); // This will run the motor forever.
}



Brian Hayward

unread,
Aug 23, 2024, 1:47:40 AMAug 23
to accelstepper

OK - I got it to work.  I had a buck converter powering the ESP32 at 5V but when I plugged in the USB, it seems to have fried the buck converter.  I believe it was causing VIO / ESP32 power to fluctuate and this caused the issues.
Now running directly off of USB + 12V for just the stepper driver.   It is running consistently.

I also found that using setSpeed(0.5) works as well.   So achieving 5 revolutions per hour is definitely possible.

Last question is how do I control direction?   Do I have to swap the wires around?

Jim Larson

unread,
Aug 30, 2024, 12:47:03 AMAug 30
to accelstepper
Glad you got your problem worked out! And thanks for sharing the solution.
Regarding reversing direction of the motor. I presume the motor turns the "wrong" way when you provide a positive direction. To change that behavior, you can indeed swap any pair of wires from the motor. You could also use setPinsInverted(true,false,false) This will invert the sense of the direction pin. That function is described in the  Missing Manual.

HTH.
                   -jim

Reply all
Reply to author
Forward
0 new messages