简体   繁体   English

树莓派GPIO输入不稳定

[英]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. 我实际上只是在尝试并尝试获得没有副作用的按钮按下。

setup 设定

Hardware 硬件

  • PIN 16 (GPIO 26) as IN PIN 16(GPIO 26)作为IN
  • PIN 6 as GND PIN 6为GND
  • 2 open Jumper wires on the pins for better debugging. 引脚上有2条开放的跳线,以便进行更好的调试。 Later there will be pushbutton behind 稍后会有按钮

Software 软件

  • Raspbian 9.4 stretch Raspbian 9.4拉伸
  • Kernel 4.9.80-v7+ (newest over normal apt-get) 内核4.9.80-v7 +(比常规apt-get最新)
  • RPi.GPIO version 0.63 RPi.GPIO版本0.63

code

#!/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()

Problem 问题

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? 我做错了吗?

Solutions already tried 解决方案已经尝试过

  • new wires 新电线
  • other ports 其他港口
  • other raspberry (same version)! 其他覆盆子(相同版本)!
  • OS new installed and GPIO Libs fresh installed 全新安装操作系统,并重新安装GPIO库
  • Breadboard between (same effect) 面包板之间(效果相同)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM