代码完成后,步进电机继续转动

2024-09-30 04:28:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在玩一个NEM17步进电机在一个树莓皮4使用Python 3.7.3和A4988步进电机驱动器。我运行下面的代码,它工作良好,但在代码完成后,步进电机继续以一种有点零散的方式转动。如何让它在完成代码后停止?我在下面包含了我正在使用的代码


# 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

Tags: theto代码importgpiosteplibrarypin

热门问题