Hi all.
Hardware:
-Elegoo Uno R3
-17HS4023 stepper (supplied 12V)
-DRV8825 driver with expansion board (full step, 200 steps per revolution)
I am new to both Arduino / programming / this forum. Kindly excuse me for any stupid mistakes.
In the code below, I ask it to take 200 steps, while printing each taken step.
The problem is that it seems to print more steps than actually taken, or perhaps the stepper is taking more steps than instructed.
#include <AccelStepper.h>
AccelStepper mtr(AccelStepper::DRIVER, 6, 7);
int spd = 300;
int stp = 200;
void setup()
{
Serial.begin(9600);
mtr.setMaxSpeed(1000);
mtr.setCurrentPosition(0);
}
void loop()
{
int i = 1;
while (mtr.currentPosition() != stp)
{
mtr.setSpeed(spd);
mtr.moveTo(stp);
mtr.runSpeedToPosition();
Serial.println(String(i++) + "/" + String(stp));
}
while (1);
}
Print out from Serial Monitor:
1/200
2/200
3/200
......
198/200
199/200
200/200
201/200
202/200
203/200
204/200
205/200
206/200
207/200
208/200
209/200
210/200
As you can see, it prints out beyond 200, as I click reset, sometimes it ends at 210, sometimes 209, sometimes 208, just not 200.
Alternatively, if I swap line 22 with
Serial.println(String(mtr.currentPosition()) + "/" + String(stp));
then I get many 0/200 at the beginning before the steps start to add up.
0/200
0/200
0/200
0/200
0/200
0/200
1/200
2/200
3/200
4/200
5/200
6/200
7/200
8/200
9/200
10/200
......
Any insight is appreciated.