spm
Posts: 5
Joined: Thu Sep 18, 2014 8:05 am

False signals on GPIO inputs when touching Raspberry headers

Thu Sep 18, 2014 9:13 am

Hi,

I found small problem with my Raspberry model B. I have a simple circuit - GPIO input on raspberry and button with 10k resistor (connected same way like on this page: https://www.cl.cam.ac.uk/projects/raspb ... _switches/). And I have this simple python script for detecting button pushes:

Code: Select all

#!/usr/bin/python

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(25, GPIO.IN)

def button_press(pin):
        print "detected", pin

GPIO.add_event_detect(25, GPIO.RISING, callback=button_press)
raw_input('test')
GPIO.cleanup()
This everythink works as expected - I run script, nothing happen, when I push button script will print detected 25. But accidentally I found other way how to simulate button push without touching it. I take long copper wire (I tested it with cable to my volt meter) and touch with it any pin on GPIO header - no matter if it's +5V, ground, other GPIO... and script also detect button push on my pin. Has anybody some idea how to prevent raspberry detect input in this case? Or did I something wrong?

jdb
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2035
Joined: Thu Jul 11, 2013 2:37 pm

Re: False signals on GPIO inputs when touching Raspberry hea

Thu Sep 18, 2014 10:33 am

You are creating ESD (electrostatic discharge events) when touching a wire to the GPIO pins. This generally creates an extremely short-duration, high amplitude pulse that can upset (or "bounce") logic inputs that have long wires attached or poor debouncing.

The Pi GPIO pins are sampled at 250MHz for edges. Sub-microsecond changes in level can be detected.

- Add a small capacitor (10nF or 100nF) between the GPIO pin and 0V, close to the Pi
- If there are long wires to the button, twist them together.
Rockets are loud.
https://astro-pi.org

User avatar
PeterO
Posts: 4882
Joined: Sun Jul 22, 2012 4:14 pm

Re: False signals on GPIO inputs when touching Raspberry hea

Thu Sep 18, 2014 10:42 am

jdb wrote:You are creating ESD (electrostatic discharge events)
My guess would be simple 50Hz mains hum pickup by capacitive coupling rather than ESD. Pi inputs without pullups or pulldowns are very high impedance and will therefore be sensitive to mains hum pickup.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

spm
Posts: 5
Joined: Thu Sep 18, 2014 8:05 am

Re: False signals on GPIO inputs when touching Raspberry hea

Thu Sep 18, 2014 1:06 pm

jdb wrote: - Add a small capacitor (10nF or 100nF) between the GPIO pin and 0V, close to the Pi
- If there are long wires to the button, twist them together.
It depends what is long. Currently I have all GPIO pins connected with wires to breadboard (which is about 10cm long wires to breadboard). There is placed button with resistor. I've placed 100nF capacitor here but I can still push button touching wires. Is that too long? Should I try to connect capacitor right on RPi pin?
PeterO wrote:My guess would be simple 50Hz mains hum pickup by capacitive coupling rather than ESD. Pi inputs without pullups or pulldowns are very high impedance and will therefore be sensitive to mains hum pickup.
It's better when I remove my 10k resistor and turn on internal RPi pull up resistor?

spm
Posts: 5
Joined: Thu Sep 18, 2014 8:05 am

Re: False signals on GPIO inputs when touching Raspberry hea

Thu Sep 18, 2014 1:27 pm

I've tried to turn on internal pull up resistor but no difference. Interesting is that when I unplug wire from GPIO input pin I can't fake signal with touching. But when I plug 5cm wire to it - only wire, I'm not connecting it to some circuit, I can fake signal (pull up resistor turned on).

User avatar
PeterO
Posts: 4882
Joined: Sun Jul 22, 2012 4:14 pm

Re: False signals on GPIO inputs when touching Raspberry hea

Thu Sep 18, 2014 2:05 pm

spm wrote:I've tried to turn on internal pull up resistor but no difference. Interesting is that when I unplug wire from GPIO input pin I can't fake signal with touching. But when I plug 5cm wire to it - only wire, I'm not connecting it to some circuit, I can fake signal (pull up resistor turned on).
Hmmmm... IF only 5cm of wire will trigger it then I'll change my mind, unlikely to be mains pickup on that short a piece of wire especially with a 10k pull up/down.
It might be worth checking everything is properly earthed. Alex of Raspi.tv had something similar happen when runing a pi in a house in Poland which has some doddgy mains wiring.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

spm
Posts: 5
Joined: Thu Sep 18, 2014 8:05 am

Re: False signals on GPIO inputs when touching Raspberry hea

Fri Sep 19, 2014 8:19 am

I'm testing it in office. Tried to connect power behind UPS but no difference. I have currently connected also some GPIO out pins and uart. They are not connected to my input but it's a few wires which can probably do this things too. As I draw my current circuit I try to disconnect everything and wire just button to RPi. Also I believe that DPS can solve this issue too (as disconnect input wire will help) but it's not easy to test it right now.

I made some progress in software way. When I test value in my callback (try to read input) there is never 1 - it probably means that when my script reach input reads there is no more signal. But it's about rare coincidence to fake two signals in right time. I believe that I can edit script to detect also rise down and count signal length - button push will last few tens of ms but fake signals not. This makes impossible to fake signal but I feel it's still just workaround. So it will be great if anybody found better hardware solution :)

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