【发布时间】:2020-03-31 08:43:09
【问题描述】:
我正在使用 Python 3.7.3 和 A4988 步进电机驱动器在 Raspberry Pi 4 上使用 Nema17 步进电机。我运行下面的代码,它工作正常,但是在代码完成后,步进电机继续以某种零星的方式转动。如何让它在完成代码后停止?我在下面包含了我正在使用的代码。
# 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
【问题讨论】:
-
建议库对于 SO 来说是题外话。您应该做的是在“清理”GPIO 之前明确停止电机。这两个可能但似乎不是一回事。您可能还需要查看清理过程。它可能需要更改,因此它不会无意识地向驱动程序发送移动命令。
标签: python python-3.x raspberry-pi gpio