Controlling two A4988 stepper drivers - missing steps when using EN pin

Hi all,

I want to drive two A4988 stepper drivers with my arduino, however I have the problem that one of the motors is not stepping correctly, when using the EN pin to frequently turn on/off the motors.


//Simple stepper driver class
class Stepperdriver
	int stepPin;
	int directionPin;
	int enablePin;
	Stepperdriver(int step, int dir, int en)
		//assign selected pins
		stepPin = step;
		directionPin = dir;
		enablePin = en;
		//disable stepper right at the start
		pinMode(enablePin, OUTPUT);
		digitalWrite(enablePin, HIGH);
		pinMode(stepPin, OUTPUT);
		pinMode(directionPin, OUTPUT);
		digitalWrite(stepPin, LOW);
		digitalWrite(directionPin, LOW);
	void Rotate(int steps, int direction)
		//enable stepper driver
		digitalWrite(enablePin, LOW);		
		//set turn direction
		digitalWrite(directionPin, direction);
		for(int i = 0; i < steps; i++)
			//pulse is long enough for stepper driver
			digitalWrite(stepPin, HIGH);
			digitalWrite(stepPin, LOW);
			//controls turning speed
		//disable stepper driver
		digitalWrite(enablePin, HIGH);

This is my simple stepper driver class.

const int Sdir1	=	A0;
const int Sstep1=	A1;
const int SEN1	=	A2;
const int Sdir2	=	A3;
const int Sstep2=	A4;
const int SEN2	=	A5;

Stepperdriver stepper1(Sstep1, Sdir1, SEN1);
Stepperdriver stepper2(Sstep2, Sdir2, SEN2);

void setup() {

void loop() {


This is my sketch.


  • Both steppers turn, they are of the Nema 8 type. Current is limited to 200mA per motor (of 600mA max for these types). Motor power supply is a bench top PSU, nur running into the current limit.
  • Driving this is an Arduino MKR WiFi 1010, powerd via USB, only runnning the stepper class (see above).
  • RST and SLP are connected to each other. A4988 logic power comes from the arduinos VCC (+3.3V).
  • MS1-3 are not connected → full step mode
  • EN/dir/step are connected to arduinos A0-A5 for the two drivers.


  • In my code I am enabling the a4988 No.1, waiting 20ms, stepping 100 steps (half turn) and again disabling the driver. Then doing the same for driver No.2. The problem is now that one of the drivers will loose a few steps on every move, like a small jitter at the beginning of the movement. This is not chip-related, I switched them and the problem was with the same stepper, however it varies, sometimes stepper2 will misstep, sometimes stepper1. The other one will run perfect… I have no idea what could cause this…

P.s. I have scoped the step-signal from the arduino, and the pulses seem well-shaped and evenly spaced… no obvious malformations… (pretty square wave…)

I did some further testing, the problem lies with switching the driver on and off.
if the driver stays on, step precision is maintained (even single steps are no problem, but using EN pin or Sleep pin and the motors will misstep.

Any advice on how this could be redeemed?

When you disable and re-enable a motor there is no guarantee that it will restart at the position where it stopped. It might jump forwards or backwards by one step. If you need to keep track of the position do not disable the motor.

If you need more help please post a complete program.

Stepper Motor Basics
Simple Stepper Code

If I don't move the motor, the coils should be aligned the same way they are when the motor last stopped, or at least be very close since they are not loaded. At least I would expect the motor to realign itself in the time between "Enable" to the first stepping pulse.
Looking at my scope confirms that the a4988 will provide current for a few microsecconds (~100) before actually starting driving the coils.
If I wake up the motor and ask it to go one step, this pre-alignment should pretty much do that. However if I ask for single steps, the motors will move too much or not at all. And this I don't quite get, why the driver has such problems with waking up and going to sleep.

The program is complete as posted above, the class is between pin assignment and calling of stepper1/2. I copied it out to make it a bit more readable.

If I don’t move the motor, the coils should be aligned the same way they are when the motor last stopped, or at least be very close since they are not loaded. At least I would expect the motor to realign itself in the time between “Enable” to the first stepping pulse.

According to your own Reply #1 your expectations are not matched by reality. I don’t know how to change reality.


Really? You should try it sometimes.

However, back to the problem, I am looking for a way to change this specific observed reality in a way that my goal of safely disabeling a stepper is possible. There is no mechanical misalignment of the coils, so it must be a problem of the A4988 driver itself. So I am wondering if it is a limitation of the a4988 itself concerning startup and shutdown protocols or if some other trick is possible to accurately make a step after sleep/disable.

You have not explained why you want to disable the motors - doing that is not the normal way to use stepper motors.