gpt4 book ai didi

python - 树莓派运行时错误 : Conflicting edge detection already enabled for this GPIO channel

转载 作者:太空宇宙 更新时间:2023-11-04 03:10:45 25 4
gpt4 key购买 nike

我正在按照此处找到的教程进行操作: https://www.linkedin.com/pulse/prepare-your-raspberry-pi-work-aws-iot-kay-lerch

我什至还没有开始它的互联网部分,因为我在电路方面遇到了问题。我使用我的树莓派 3 连接我的电路,如下图所示。 enter image description here

然后我按照教程中所示编写了以下 python 脚本。

import RPi.GPIO as gpio

gpio.setmode(gpio.BOARD)
gpio.setup(7, gpio.IN, pull_up_down=gpio.PUD_DOWN)

def on_pushdown(channel):
print "Button Pushed."

while(True):
gpio.add_event_detect(7, gpio.RISING, callback=on_pushdown, bouncetime=200)
gpio.cleanup()

当我按下按钮时,这应该打印出“Button Pushed”,但我收到以下运行时错误:

Traceback (most recent call last):
File "button.py", line 10, in <module>
gpio.add_event_detect(7, gpio.RISING, callback=on_pushdown, bouncetime=200)
RuntimeError: Conflicting edge detection already enabled for this GPIO channel

我有 RPi.GPIO 版本 0.6.2,这是发布这篇文章时的最新版本。如果有人能提供任何帮助,我将不胜感激。

最佳答案

您拥有的代码不断添加事件检测回调(在 while(True) 循环中)。你想要的是添加一次事件检测回调,然后等待边缘。

page有一个很好的例子,你可能想要通过。

或者,您可以尝试以下方法:

import RPi.GPIO as gpio

gpio.setmode(gpio.BOARD)
gpio.setup(7, gpio.IN, pull_up_down=gpio.PUD_DOWN)

def on_pushdown(channel):
print "Button Pushed."

# only add the detection call once!
gpio.add_event_detect(7, gpio.RISING, callback=on_pushdown, bouncetime=200)

while(True):
try:
# do any other processing, while waiting for the edge detection
sleep(1) # sleep 1 sec
finally:
gpio.cleanup()

关于python - 树莓派运行时错误 : Conflicting edge detection already enabled for this GPIO channel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38125047/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com