I’m working with a Nema 17 adafruit stepper motor, item #324, running on Raspberry Pi 4b (Bookworm OS) with an Adafruit DC & Stepper Motor HAT for Raspberry Pi ID: 2348.
I have a problem where the motor runs at top speed for a few seconds, then slows down and doesn’t speed back up. No excessive heat noted on motor or pi. You can see exactly what I’m talking about here https://youtube.com/shorts/vlc2USj2kgw. Sorry about the rumbling in the background, had a fan going in a closed room. Watch the amperage display in the back which jumps when the motor slows down. During high speed it’s pulling ~0.10 amps, when it slows down it pulls almost double that. It does seem to stutter a time or two also.
I have ran a number of tests, and it seems to do this randomly on 99% of the runs.
The motor is ran from the terminal using the python3 test program shown below.
from adafruit_motor import stepper
from adafruit_motorkit import MotorKit
# Below initialises the variable kit to be our I2C Connected Adafruit Motor HAT
kit = MotorKit(i2c=board.I2C())
for i in range(4000):
# The below line will de-energise the Stepper Motor so it can freely move
I need to be able to do a consistent run without the motor slowing down. Putting a time.sleep in it doesn’t reliably fix the problem.
Any and all suggestions are greatly appreciated.
Not sure what this is off the top of my head, but what sort of delay did you try between steps? How does it behave under load? I’ve seen steppers do this on 3D printers when you command them to move too fast.
It’s a pretty wacky theory, but it could be that the Python interpreter speeds up as it works out you’re doing this one thing many times, and this is too fast for the motor.
Have you tested the motor under different conditions to compare the behaviour. For instance, using step(1…) instead of onestep(), or step(4000, …) instead of the loop, or reverse direction, or step with the different stepping styles (SINGLE, DOUBLE, INTERLEAVED or MICROSTEP). How these different conditions affect the motor will give a clue as to where the problem is.
@Greg259479 The Adafruit example uses a delay after each step. This delay is commented out in the code you listed. Maybe the program is trying to drive the stepper too often and it gets lost.
Try putting a delay in and vary it to achieve what you need.
It’s supposed to be a 200 step/rev motor. If I change it to 200 steps, it usually doesn’t run a complete revolution, but seems to be about 90 degrees less then a complete rev.
Hadn’t thought about the python interpreter idea.
I tried the sleep with 0.001, 0.001 and 0.01 seconds and it still has the slowdown issue. At 0.01 seconds sleep it draws about 0.30 amps, 3 times as much as high speed. Don’t know if that’s normal or not.
I think you are misinterpreting your meter. Digital meters are slow at responding and they take sometimes quite some time to settle. I would suggest that the stepper requires current is short bursts as the coils are energised and at higher speeds the meter is not responding fast enough. At slower speeds the meter has more time to catch up thus reading higher.
The only real way is to measure the current with an oscilloscope fitted with a current probe which I doubt you will have access to.
If you really need to know the peak current I can describe a method without an oscilloscope but is a bit messy.
The software is only concerned about steps per revolution so it can calculate the stepping speed required to rotate the motor at a defined RPM. If it’s set wrongly the only effect is to drive the motor at a different RPM. It would not produce the result you are seeing.
The usual reason for getting something other than a full turn at 200 steps is that the driver is microstepping, but that would create a 1/2 or 1/4 revolution, not 3/4. So the likely reason for less than a full turn is that the motor is missing steps. This indicates that the step rate is too high or the power supply is not providing enough current.
Without looking further into it the delay stood out as a possible problem.
My experience with stepper motors is limited.
I did not experience what you describe when I was using one.
As it is Adafruit products and software, they might be able to help you further.
Or someone else on this forum with more experience might be able to help.
All the best