Hi, i have a nema 17 stepper motor not work normally it start vibrating when i set the speed of rotation at 200 steps per second or under , but when i set the speed at 210 and above it work perfectly .
#include <AccelStepper.h>
//Define stepper motor connections
#define dirPin 2
#define stepPin 3
//Create stepper object
AccelStepper stepper(1,stepPin,dirPin); //motor interface type must be set to 1 when using a driver.
void setup()
{
stepper.setMaxSpeed(1000); //maximum steps per second
}
void loop()
{
stepper.setCurrentPosition(0); //set the current position to 0
//run the motor forward at 200 steps/second until the motor reaches 400 steps (2 revolutions).
while(stepper.currentPosition() != 400)
{
stepper.setSpeed(200);
stepper.runSpeed();
}
stepper.setCurrentPosition(0); //reset the position
delay(1000);
}
You should be setting the acceleration in setup() too, not just max speed, as its dependent on your electrical and mechanical setup.
stepper.setAcceleration(...)
Experimentation will determine the highest acceleration your system can reliably handle. In the AccelStepper
library acceleration is given in terms of (micro)steps per second per second. Try something like 1000 in the
first instance.