[英]Raspberry-pi gpio input not stable
I have a strange problem with raspberry (3B) ang GPIO as Input. 我将树莓(3B)和GPIO用作输入存在一个奇怪的问题。 I'm actually just experimenting and trying to get a pushbutton press without side effects.
我实际上只是在尝试并尝试获得没有副作用的按钮按下。
#!/usr/bin/python
import RPi.GPIO as GPIO
from time import sleep
red_channel = 23
GPIO.setmode(GPIO.BCM)
GPIO.setup(red_channel, GPIO.IN, pull_up_down=GPIO.PUD_UP) # pin is up to 3.3V
try:
while True:
state = GPIO.input(red_channel)
if state == 0: # when pin pulled down
print 'red pressed', state
sleep(0.3)
except KeyboardInterrupt:
GPIO.cleanup()
When I run the code and only come with my hand in the near of the jumper wires or even move them, button pressure will be detected. 当我运行代码并仅将我的手放在跳线附近或什至移动跳线时,将检测到按钮压力。 And at this point I don't get why!
在这一点上,我不明白为什么! Did I get something wrong?
我做错了吗?
Thanks for your help! 谢谢你的帮助!
I can't help thinking that you've got a short or dodgy link in this somewhere. 我不禁会以为您在某处与此之间存在短促或狡猾的联系。
I'd take off the PI, and test the board with a multi-meter in continuity mode. 我将取下PI,然后在连续模式下用万用表测试电路板。 Check what happens when you wiggle the cables etc.
检查当您扭动电缆等时会发生什么。
Any short or wrong link should then show up as long as you test logically 只要您进行逻辑测试,任何短或错误的链接都应出现
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.