I have a strange problem with raspberry (3B) ang GPIO as Input. I'm actually just experimenting and trying to get a pushbutton press without side effects.
setup
Hardware
- PIN 16 (GPIO 26) as IN
- PIN 6 as GND
- 2 open Jumper wires on the pins for better debugging. Later there will be pushbutton behind
Software
- Raspbian 9.4 stretch
- Kernel 4.9.80-v7+ (newest over normal apt-get)
- RPi.GPIO version 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
- Breadboard between (same effect)
Thanks for your help!
if state == 0: print 'red pressed'
is going to print it is pressed when the button is not pressed sinceGPIO.input(red_channel)
will returnFalse
only then, was this a typo in the code? – nj2237red pressed
every 0.3 seconds without pressing the button – nj2237True
orFalse
? – nj2237