因此,我创建了另一个程序,可以顺时针和逆时针运行步进电机,其中有一个斜坡上升和斜坡下降,并在GPIO 16和26上添加限制器开关,以停止
pi.wave_send_using_mode(wid2, pigpio.WAVE_MODE_ONE_SHOT_SYNC)
发出一个链波,这是我的代码:
import time
import pigpio
START_DELAY=600
FINAL_DELAY=500
STEP=1
GPIO=20
pi = pigpio.pi()
pi.set_mode(GPIO, pigpio.OUTPUT)
pi.set_mode(21, pigpio.OUTPUT)
pi.set_mode(26,pigpio.INPUT)
pi.set_mode(16,pigpio.INPUT)
#pi.write(21,1)
pi.wave_clear()
statee = 0
try:
while True:
pi.write(21,statee)
pi.wave_clear()
wf=[]
offset = pi.wave_get_micros()
for delay in range(START_DELAY, FINAL_DELAY, -STEP):
wf.append(pigpio.pulse(1<<GPIO, 0, delay))
wf.append(pigpio.pulse(0, 1<<GPIO, delay))
for i in range(500):
wf.append(pigpio.pulse(1<<GPIO, 0, FINAL_DELAY))
wf.append(pigpio.pulse(0, 1<<GPIO, FINAL_DELAY))
wf.append(pigpio.pulse(0, 0, offset))
for delay in range(FINAL_DELAY, START_DELAY, STEP):
wf.append(pigpio.pulse(1<<GPIO, 0, delay))
wf.append(pigpio.pulse(0, 1<<GPIO, delay))
pi.wave_add_generic(wf)
wid2 = pi.wave_create()
#pi.wave_send_once(wid2)
pi.wave_send_using_mode(wid2, pigpio.WAVE_MODE_ONE_SHOT_SYNC)
if pi.read(26) == 0:
pi. wave_tx_stop()
pi.stop()
if pi.read(16) == 0:
pi.wave_tx_stop()
pi.stop()
time.sleep(0.75)
if statee == 0:
statee = 1
elif statee == 1:
statee = 0
except KeyboardInterrupt:
print ("\nCtrl-C pressed. Stopping PIGPIO and exiting...")
pi.wave_tx_stop()
pi.stop()
当Motor在5-10分钟左右运行时会出现问题,我会给出如下错误消息:
Traceback (most recent call last):
File "/home/pi/Desktop/ramp.py", line 49, in <module>
if pi.read(16) == 0:
File "/usr/local/lib/python3.4/dist-packages/pigpio.py", line 1401, in read
return _u2i(_pigpio_command(self.sl, _PI_CMD_READ, gpio, 0))
File "/usr/local/lib/python3.4/dist-packages/pigpio.py", line 989, in _pigpio_command
sl.s.send(struct.pack('IIII', cmd, p1, p2, 0))
AttributeError: 'NoneType' object has no attribute 'send'
那么,我的代码中出现错误的原因是什么?这是因为
pi.read(26)
和
pi.read(16)
? 还有其他停止或终止的方法吗
在it过程中?非常感谢。
小提示:我通过follow设置pigpiod守护进程在引导时启动(
https://raspberrypi.stackexchange.com/questions/70568/how-to-run-pigpiod-on-boot
KimSJ答案),运行pigpiod的方法是否会导致此错误?非常感谢。
更新:
在我清除后
pi.stop()
在…上
圆周率。阅读(26)
和
圆周率。阅读(26)
并将pigpiod版本更新为v68,所有操作都正确无误地运行