Problems sleeping a stepper using A4988

I have some code that runs on an Arduino that I’m using to control two stepper motors. I recently modified my code to sleep the stepper motors when not moving them. Previously, I would move the steppers to specific positions, but not sleep. Now I’m sleeping the stepper after moving it to the desired position.

I’m seeing some strange behavior. If I move the steppers many steps (say 10), they seem to move about as far as I’m telling them to. But if I move them individual steps (sleeping in between each step), then they just “twitch” but don’t move. So somehow sleeping the steppers between individual steps keeps them from moving, whereas if I only sleep them after moving many steps, they do move.

According to the data sheet, you need to wait a millisecond after coming out of sleep mode before issuing a step command, which I’m doing. I’ve also tried increasing that wait time, but that doesn’t work either.

It’s as if the first step command after coming out of sleep mode is ignored.

Any thoughts as to what’s going on or how to troubleshoot this?


- Dave

One thought - am I wrong to expect the stepper to stay in the same position after entering sleep mode? There’s no force being applied to it, so I would think it should hold its position unless the magnets in the stepper are causing it to move.

Hello, Dave.

Could you tell me which stepper motors you are using and what you have set the current limit to on your stepper drivers? Also, are you using a microstepping mode on your stepper drivers?


are these. The ones I’m controlling are the SY39ST34-0166A motors - current/phase of 160mA and resistance/phase of 75 ohms. The current limit reading as per the datasheet should be .064 volts - correct? I actually have it set to .052 volts. That’s slightly low, but it’s very difficult to adjust the pot to get .064 on the nose. I wouldn’t think that the problem could be caused by them being too low anyway - otherwise I’d have problems moving the stepper, wouldn’t I? The only issue I have is with it doing a single step followed by a sleep. If I single step them without sleeping between steps, it works fine.

Regarding microstepping - no, I’m not doing that.

- Dave

It sounds like those are 12 volt motors. If you are using a 12 V power supply, there is no need to limit the current. That will improve the full step performance from the present setting.

Hello, Dave.

It is possible that the timing in your code is not leaving the coils in the stepper motor energized for a long enough time for the rotor to reach the position of the next step. If you post your code here, I can look at the timings to see if they are obviously too short. Also, if you post some pictures of your testing setup that shows your stepper motor, I might be able to see something mechanical that could be causing the problem.


Sorry, a picture wouldn’t tell you much I’m afraid. Everything is inside an enclosure. Can you just tell me what the timings should be? If I move the motor without a sleep, it moves fine. If I have a sleep between steps, I have this problem. The data sheet days to wait a millisecond after waking. Are there any other delays I should put in there?

Hello, Dave.

I recommend waiting a full second after stepping the motor before putting the driver to sleep and seeing how the motor behaves. Once you have verified this works, you can try to slowly reduce the time after you step and before you sleep to see if you can get your system to behave the way you would like.


Ok, I played with this some more and have an update.

Firstly - Jim, I am using a 24v power supply, so limiting the current is required - correct?

And regarding Nathan’s suggestions:

I tried waiting a full second after waking the motor before sending a step command, and that didn’t help.

I then changed my code so that the motors aren’t told to sleep after individual steps. As I said before, it works fine when I do that - I can send single steps, or groups of steps, and the motors move to where I tell them to and stay there.

But this time, I added a button so when I press the button, the motors are “put to sleep”. When I do this, the motors stay where they are when put to sleep, but when they are woken, they move. There seems to be certain positions that they “like” to go to when woken.

So a sample sequence of what I’m seeing is:

  1. I send 3 step commands to move the motor clockwise.
  2. The motor moves 3 steps.
  3. I wait a little, look at the motor, …, everything’s fine - it’s holding its position.
  4. I tell the motor to sleep.
  5. The motor sleeps, but stays in the same position.
  6. I tell the motor to wake.
  7. The motor moves a couple of steps back to the nearest “preferred position”.

I haven’t figured out how many spots in the motor’s possible positions that it “likes”. There are several. I did verify that if I put the motor in one of these spots, then sleep it, then wake it, it stays there. But if it’s in an adjacent spot, if I sleep then wake it, it jumps over to the preferred spot when it’s woken.

So do you know what’s causing this behavior? Is it an attribute of my stepper motors? Is this something caused by the A4988?

I realized that your problem is from the driver going back to its home position when it comes out of sleep mode, so until you take enough steps that the motor is mechanically closer to its next electrical home position, it’s going to keep jumping back to the closest home position behind it. There is more about the home position in the description of the sleep mode on page 10 and in figure 9 on page 14 of the datasheet.

Our new AMIS-30543 Stepper Motor Driver Carrier boards have some additional features that might allow you to change the current limit to the steppers at different portions of the drive cycle without going into a sleep mode.


That’s talking about the home microstep position though. Is that relevant to me, since I’m not micro stepping? Can you please explain?

And - if that is indeed my problem, could I use “disable” instead of sleep, if I want to stop sending power to the motors when not in use, while keeping them in the same position?

Even in full step mode, you go through four steps to one cycle (otherwise, you wouldn’t be able to step forward and backward). Only one of those four states is the home position that the driver goes to after being reset. Using the enable line instead of sleep should address your problem, though you might still have some mechanical cogging that causes your shaft to move a bit when you disable and enable the motor. You might also consider keeping track of which step you’re on, and go to a home position (e.g. a multiple of 4 for full step) before sleeping the driver.


Aha! That clears things up. I’m not sure what you mean by “mechanical cogging”, but I’ll play with using Enable instead of Sleep and see what that does.

I’m back on this, and was hoping you could clear something up. Above, you said that I could use “Enable” instead of “Sleep” if I want to cut power to the steppers when not in use. Can you please explain the difference between Enable and Sleep? It sounds like the problem is that the motors want to go to a home position when power is cut. So if I use Enable to cut power, wouldn’t the same thing happen?

Hello, Dave.

The ENABLE pin on the A4988 disables the output of the FETs on the IC (which control power to the coils on the stepper motor), but the internal logic circuitry remains active. The SLEEP mode disables more of the internal circuitry on the IC. You can find a more detailed description of the two functions on page 10 of the A4988 datasheet.