【问题标题】:Stepper motor continues turning after code is finished码完后步进电机继续转动
【发布时间】: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


【解决方案1】:

也许 GPIO.cleanup 将 gpio 输出置于未定义的浮动状态。 尝试在 GPIO.cleanup 之前将 A4988 置于睡眠模式。 A4988 pdf

【讨论】:

  • 谢谢。我通读了一些关于 SLEEP、ENABLE 和 RESET 引脚的 PDF,这给了我更多希望。我今天试试
  • 我一直在查看您正在使用的 RpiMotorLib.A4988Nema 源。奇怪,但它没有停止功能。也许您可以添加自己的 'def stop(self):' 函数。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-03
  • 2019-08-05
  • 2012-06-07
  • 2014-05-02
  • 2015-10-03
  • 2013-11-25
相关资源
最近更新 更多