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.
}