Nargousias
Posts: 2
Joined: Tue Dec 29, 2015 10:15 pm

Issue with GPIO input detection

Tue Dec 29, 2015 10:55 pm

Am attempting to use one of the GPIO pins as an input to detect a button push and it is just not working.

Have read thru 100+ postings here and just as many tutorials and have used multiple GPIO ports to attempt this.

Have no issues controlling OUT setup and driving relays, LEDs etc.

From 2015-11-21-raspbian-jessie I issue the following commands:
echo 20 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio20/direction

Then I use cat /sys/class/gpio/gpio20/value to get the current value 0 or 1.

I have tried a button wired in the following configurations:
From Ground thru button and 330 ohm resistor to GPIO pin.
From 3.3v thru button and 330 ohm resistor to GPIO pin.
From Ground thru button to GPIO pin directly.
From 3.3v thru button to GPIO pin directly.
Tried all four with pullup and pulldown.

When pressed or unpressed the value for the GPIO is always 0.
I cant figure out what I am missing. I have a degree in electronics and am probably overthinking it.

PS: Yes I checked the switch. Below is the circuit I am emulating.
http://raspberry.io/media/images/projec ... _schem.png

User avatar
joan
Posts: 14960
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Issue with GPIO input detection

Tue Dec 29, 2015 11:50 pm

Please post a photo of your setup.

Invariably you are not using the GPIO you think you are using. GPIO 20 is connected to pin 38 of the expansion header.

drgeoff
Posts: 10831
Joined: Wed Jan 25, 2012 6:39 pm

Re: Issue with GPIO input detection

Wed Dec 30, 2015 12:35 am

I am tempted to ask which university granted you a degree in electronics.
Quis custodiet ipsos custodes?

Nargousias
Posts: 2
Joined: Tue Dec 29, 2015 10:15 pm

Re: Issue with GPIO input detection

Wed Dec 30, 2015 3:35 pm

Looking back at the schematic I realize that it differs from the specific commands I listed. That was due to using a different port on each unique test. I started with the GPIO ports on the diagram. I ended up at pin 38 (GPIO 20). I changed ports in case a previous test compromised the port itself.

The diagram was only to give an illustration of what I was attempting to accomplish.

I agree that this may sound like someone who cruised thru courses 32 years ago, but this is not rocket science. It is as if I am using a calculator and adding 2+2 and pressing the = and getting 0. (Please note that I don't use RPN calculators)

User avatar
karrika
Posts: 1125
Joined: Mon Oct 19, 2015 6:21 am
Location: Finland

Re: Issue with GPIO input detection

Wed Dec 30, 2015 3:47 pm

Sounds like you are doing everything right. So the push button and/or the resistor is broken. Replace the push button+resistor with a wire. You do not need a resistor for the input.

Return to “Beginners”