Raspberry Pi controls an EasyDriver and stepper motor, but results are inconsistent and the system fails regularly. Can't figure out why.

Long text:
Hi all,

I have a small setup where a stepper motor is supposed to drive a chopper wheel to modulate a signal. Counting steps is not a requirement since the motor comes with an encoder, but a stable speed is a requirement. I'm using the pigpio library (more specifically, the hardware_PWM function) to set the RPM on pin (12) on the Raspberry. Since setting it to full speed instantaneously does not make the stepper motor move at all, I've coded a small ramp-up in speed. The testing script I use has it ramp up to 32000 ppm (20 Hz / 1200 RPM), stay there for a few seconds and then ramp down again.

I've been having a regular issue where at any point during ramp-up, stable running or ramp-down (although usually ramp-up) the motor appears to lose its 'grip' on the rotating shaft and the chopper. From that moment on, the chopper will slow down to 0RPM, but the motor will continue to try and accelerate (ramp-up) or keep speed (stable RPM), causing a whine/buzz different from regular operation. I currently think it must be some sort of timing issue, as in my limited understanding a stepper motor can be compared to a swing in that you'd need to "push" at the right moment, or it'll do nothing or actually slow down. Is it possible that at some random point a timing mismatch between the pulse train and the "ideal push timings" occurs, causing this issue to happen? Surprisingly, others with similar setups and near-identical codes report no issues.

I realize this is probably a mix of Raspberry Pi, hardware and pigpio, but I hope this rings a bell with someone who can help me out, it'd be much appreciated!

Some specs, in case they help:
Motor: NEMA08-17-01D-AMT112S (https://www.cuidevices.com/product/resource/nema08-amt112s.pdf)
Power supply: LPV-150-24 (Repurposed LED-driver, https://www.meanwell-web.com/nl-nl/ac-dc-single-output-led-driver-constant-voltage-c-lpv--150--24)
Driver: EasyDriver ROB-12779 (https://www.sparkfun.com/products/12779)
Testing code: https://pastebin.com/tKS0jvDA (There's a typo in line 7 which is not in the actual code ;) )
Demo of error: https://www.youtube.com/watch?v=KtLGCtxPLPw
Demo notes: In the first cycle, it fails during spin-up, you can hear the frequency increasing but the shaft slows down. In the second attempt, it gets up to speed as it should, and then fails while slowing down, at which point the tune you hear is caused by the mass of the chopper effectively driving an unpowered motor :)

EDIT 29/04: Added code listing to post as requested:

import datetime
import time
import pigpio
import numpy as np
import Rpi.GPIO as GPIO
GPIO.setup(6, GPIO.OUT)
GPIO.output(6,0)    #Enable motor
pi = pigpio.pi()
freq_startup_diff = 100
freq_startup_wait = 0.01
motor_freq = 32000
startup_range = np.arange(0,motor_freq+1,freq_startup_diff)
print('Motor starting')
for freq in startup_range:
  print("Frequency equals {}".format(freq))
print('Motor started.')
print('Motor stopping.')
stop_range = np.flip(startup_range)
for freq in stop_range:
  print("Frequency equals {}".format(freq))
GPIO.output(6,1)    # Disable motor
print('Motor stopped.')
  • 2
    You might be better off asking a version of this question on our larger sibling site, Electrical Engineering.
    – goldilocks
    Apr 28, 2021 at 21:25
  • 1
    please include the actual code listing, not a link to code
    – jsotola
    Apr 29, 2021 at 1:12
  • There are many reasons why a stepping motor is not stable. I have a couple of posts on EESE on using a variety of motor drivers with satisfactory results. The most recent experiment is still in progress: electronics.stackexchange.com/questions/561492/…. You might find from this post a lot of references on my older testing. Cheers.
    – tlfong01
    Apr 29, 2021 at 3:04
  • My experiment using A4899: electronics.stackexchange.com/questions/560123/…
    – tlfong01
    Apr 29, 2021 at 3:06
  • 1
    Appreciate all the comments, will have a look at the suggested sites and tips! tlfong01 is right in that this is not a MickeyMouse hobby project per se, but the use of cheap/common hardware in this prototype was intentional. Since I don't need any accurate stepping counter or special performance, just accelerating to high (but well within specs!) speeds I didn't think an EasyDriver would cause any issues.
    – SvB
    Apr 29, 2021 at 12:10


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.