SoupLab
Posts: 5
Joined: Fri Dec 21, 2012 3:44 am

Pins registering input when I touch the pin / attach a wire.

Wed Mar 13, 2013 7:46 pm

Hey all,

I'm trying to register a button, and it's saying I'm pressing it all the time - so I unplugged everything but the one wire coming off of the pins and it was still registering. .. even shows at touching when I just touch it with my finger.

Are the pins fried?

I'm using this:

Code: Select all

import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(24, GPIO.IN)
count = 0
while True:
inputValue = GPIO.input(24)
if (inputValue == True):
count = count + 1
print("Button pressed " + str(count) + " times.")
time.sleep(.3)
time.sleep(.01)
I've tried swapping over to other pins, but all act the same.

Any help is appreciated, I can't work it out.

User avatar
rpdom
Posts: 14741
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Pins registering input when I touch the pin / attach a w

Wed Mar 13, 2013 7:53 pm

How have you wired the button to the pin? Button between pin and 0v or button to 3.3v?

Have you used a pull up/down resistor, or configured the internal pull-up/down resistors?
If not, the pin will "float" with random values and you touching it may be enough to trigger it with leakage current.

User avatar
abishur
Posts: 4477
Joined: Thu Jul 28, 2011 4:10 am
Location: USA
Contact: Website

Re: Pins registering input when I touch the pin / attach a w

Wed Mar 13, 2013 7:55 pm

My off the cuff thought is you need to specify if their internal resistor should be a pull up or pull down. Right now it would appear it is set to pull up (therefore it defaults high or always on). If you're using BCM pin 24 then at the bash prompt type in

Code: Select all

sudo gpio mode 5 down


This will set pin 5 (as numbered by the gpio utility) to default to zero

More information on pin numbering can be found here:

https://projects.drogon.net/raspberry-pi/wiringpi/pins/

And more info on the different functions can be found here

https://projects.drogon.net/raspberry-p ... o-utility/
https://projects.drogon.net/raspberry-p ... functions/
Dear forum: Play nice ;-)

SoupLab
Posts: 5
Joined: Fri Dec 21, 2012 3:44 am

Re: Pins registering input when I touch the pin / attach a w

Wed Mar 13, 2013 8:04 pm

Thanks for your reply guys!

Sorry, I should really explain in full..

I have a capacitive sensor running on an Arduino nano - which is working great. set to output onto pin 13 (which I can see working through the internal LED, and I've used my multimeter to measure each stage)- Which passes through a 5V to 3.3V regulator (Input / GND / Output).

The output of that regular is set to a Pin 4 of the PI
That output (and pin 4 ) is also hooked up with a resistor which is running to ground on the Pi.
Last edited by SoupLab on Wed Mar 13, 2013 8:07 pm, edited 1 time in total.

SoupLab
Posts: 5
Joined: Fri Dec 21, 2012 3:44 am

Re: Pins registering input when I touch the pin / attach a w

Wed Mar 13, 2013 8:07 pm

The arduino output it set to latching - It stays high until you press it again.

User avatar
jojopi
Posts: 3078
Joined: Tue Oct 11, 2011 8:38 pm

Re: Pins registering input when I touch the pin / attach a w

Wed Mar 13, 2013 10:06 pm

If you connect only a wire or a finger to a GPIO, or you connect the GPIO to an external circuit but do not connect the ground of the external circuit to the ground of the Pi, then the wire acts as an antenna picking up electrical noise from the environment. Without a pull-up or pull-down enabled, the GPIO will tend to go up and down in time with your local 50/60Hz mains.

I am not sure that you can rely on the 3.3V regulator as a level converter. When you put 5V on the input you get 3.3V on the output, but when you put 0V on the input the regulator has no power, and its output might just be floating. If that is the case then again you want a pull-down on the GPIO. To enable that with RPi.GPIO:

Code: Select all

GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

Return to “Interfacing (DSI, CSI, I2C, etc.)”