I have an Arduino connected to a stepper motor with an Easy Driver as follows:
I am controlling the position of the stepper motor using the Serial. This is my code:
#include <AccelStepper.h>
AccelStepper stepper(1, 9, 8);
void setup()
{
Serial.begin(9600);
stepper.setMaxSpeed(10000);
stepper.setAcceleration(5000);
}
void loop()
{
char c;
if(Serial.available())
{
int steps = Serial.parseInt();
Serial.print(steps);
stepper.moveTo(steps);
}
stepper.run();
}
The code works well but I'm facing a problem, when I set a high position value, it starts turning in the opposite direction, like if there was a limit on the steps. Does anyone know why it starts turning to the opposite direction?
I have tried to solve this problem by using:
if (stepper1.distanceToGo() == 0)
{
stepper1.setCurrentPosition(0);
}
so I can set lower values to the serial. But the problem goes back again when the value goes up to the power of 6 (like 1000000).
Any idea?
Thanks!