Raspberry Pi RuntimeError:已为此 GPIO 通道启用冲突边缘检测

2023-12-10

我正在遵循此处找到的教程:https://www.linkedin.com/pulse/prepare-your-raspberry-pi-work-aws-iot-kay-lerch

I have not even begun the internet part of it as I was having issues with the circuit. I wired my circuit just like it is shown in this diagram below using my raspberry pi 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)环形)。您想要的是添加一次事件检测回调,然后等待边缘。

This 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()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Raspberry Pi RuntimeError:已为此 GPIO 通道启用冲突边缘检测 的相关文章

随机推荐