简体   繁体   中英

Stepper motor continues turning after code is finished

I am playing around with a Nema17 stepper motor on an Raspberry Pi 4 using Python 3.7.3 and a A4988 stepper motor driver. I run the code below and it works fine however after the code is finished, the stepper motor continues to turn in a somewhat sporatic fashion. How do I get it to just stop after it finishes the code? I have included the code I am using below.


# import the library
from RpiMotorLib import RpiMotorLib

#define GPIO pins
GPIO_pins = (17, 27, 22) # Microstep Resolution MS1-MS3 -> GPIO Pin
direction= 24       # Direction -> GPIO Pin
step = 23      # Step -> GPIO Pin

# Declare an named instance of class pass GPIO pins numbers
mymotortest = RpiMotorLib.A4988Nema(direction, step, GPIO_pins, "A4988")


# call the function, pass the arguments
mymotortest.motor_go(False, "Half" , 500, .001, False, .05)

# good practise to cleanup GPIO at some point before exit
GPIO.cleanup()```

P.S I was wondering what would be the best library or way to control a stepper motor? As in, is this the best library to be using or are there better and more precise methods in doing so.

Thank you

Maybe GPIO.cleanup puts the gpio outputs in an undefined, floating state. Try put the A4988 in sleep mode before GPIO.cleanup. A4988 pdf

I confirm the problem with A4988 on Pi Model 4B v1.4. Mace is right, the problem comes from GPIO.cleanup(). For example, removing the GPIO.cleanup() line in the A4988_Nema_Test.py script found on the github solved this issue in my case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM