问题描述
我正在学习此处找到的教程:
然后我编写了以下 python 脚本,如教程中所示.
将 RPi.GPIO 导入为 gpiogpio.setmode(gpio.BOARD)gpio.setup(7, gpio.IN, pull_up_down=gpio.PUD_DOWN)定义 on_pushdown(通道):打印按下按钮".而(真):gpio.add_event_detect(7,gpio.RISING,回调=on_pushdown,bouncetime=200)gpio.cleanup()
当我按下按钮时,这应该打印出Button Pushed",但出现以下运行时错误:
回溯(最近一次调用最后一次):文件button.py",第 10 行,在 <module> 中gpio.add_event_detect(7,gpio.RISING,回调=on_pushdown,bouncetime=200)运行时错误:已为此 GPIO 通道启用了冲突边缘检测
我有 RPi.GPIO 版本 0.6.2,这是本文发布时的最新版本.如果有人能提供任何帮助,我将不胜感激.
您的代码不断添加事件检测回调(在 while(True)
循环中).您想要的是添加一次事件检测回调,然后等待边缘.
这个页面有一个很好的例子,你可能想看看.
或者,您可以尝试以下操作:
将 RPi.GPIO 导入为 gpiogpio.setmode(gpio.BOARD)gpio.setup(7, gpio.IN, pull_up_down=gpio.PUD_DOWN)定义 on_pushdown(通道):打印按下按钮".# 只添加一次检测调用!gpio.add_event_detect(7,gpio.RISING,回调=on_pushdown,bouncetime=200)而(真):尝试:# 做任何其他处理,同时等待边缘检测sleep(1) # 休眠 1 秒最后:gpio.cleanup()
I was following a tutorial found here: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.
I then wrote the following python script as shown in the tutorial.
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()
This should print out "Button Pushed" when I push the button but I get the following runtime error:
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
I have RPi.GPIO version 0.6.2 which is the latest version at the time o fthis post. I would appreciate any help that anyone can provide.
The code you have is adding an event detection callback constantly (in the while(True)
loop). What you want is to add the event detection callback once and then wait for an edge.
This page has a good example you might want to go through.
Alternatively, you could try something like:
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()
这篇关于Raspberry Pi RuntimeError:已为此 GPIO 通道启用了冲突边缘检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!