us3rnotfound
Posts: 7
Joined: Sat Jan 12, 2019 5:51 pm

Static shock causing false GPIO detection

Sat Jan 12, 2019 6:00 pm

I have added a power button to my Raspberry Pi 3 b+. It is just a NO momentary switch tied to GPIO pins 5 (GPIO3) and 6 (GND). I've programmed a Python script that runs on startup to detect a falling edge from GPIO3, and shutdown the system when that falling edge is detected. Also I programmed it to use the built-in pull down resistor, no physical resistor was soldered in.

Now the problem. The other day I was walking across my living room carpet to turn on the pi and just touching the case turned it on. I understand I should try and add a 10nF or 100nF capacitor to stop this quick discharge from turning on the Pi. Where should I add it? I'm thinking in series to GPIO3, between the switch and GPIO3, right?

User avatar
Imperf3kt
Posts: 1904
Joined: Tue Jun 20, 2017 12:16 am
Location: Australia

Re: Static shock causing false GPIO detection

Sat Jan 12, 2019 7:28 pm

What is your case made out of? If it is conductive, are you sure it's not shorting anywhere?
Even with static electricity, the Pi shouldn't turn on by touching the case. In most scenarios, static electricity would damage your electronics, not turn them on.
Google is ubiquitous - learn to use it!
https://opensource.com/life/16/10/how-ask-technical-questions

wh7qq
Posts: 1234
Joined: Thu Oct 09, 2014 2:50 am

Re: Static shock causing false GPIO detection

Sat Jan 12, 2019 7:41 pm

It is possible to generate some extreme voltages when walking across carpeting, especially synthetics, with leather soled shoes. Steve Wozniak of Apple Computer fame has a nice video on the subject and you can probably find it on line somewhere (try https://www.youtube.com/watch?v=hLOQ7zOWGAA). The RPi is pretty robust but the kinds of voltages you can generate, especially in a cold, dry climate, can potentially damage most electronic devices. Check out the video if you can...worth watching.

That said, if the case and switch are non-conductive, an external pull-down on the GPIO pins might help...say 4.7k or 10k. If the case is metal and shares ground with the RPi, all bets are off.

User avatar
davidcoton
Posts: 3549
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Static shock causing false GPIO detection

Sat Jan 12, 2019 9:24 pm

us3rnotfound wrote:
Sat Jan 12, 2019 6:00 pm
I understand I should try and add a 10nF or 100nF capacitor to stop this quick discharge from turning on the Pi. Where should I add it?
Any capacitor added to remove stray pickup should be in parallel withthe switch contacts.
Signature retired

User avatar
Burngate
Posts: 5715
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Static shock causing false GPIO detection

Sun Jan 13, 2019 10:47 am

us3rnotfound wrote:
Sat Jan 12, 2019 6:00 pm
... a NO momentary switch tied to GPIO pins 5 (GPIO3) and 6 (GND)... Also I programmed it to use the built-in pull down resistor, no physical resistor was soldered in.
Note: GPIO 3 (and also GPIO 2, pin 3) already has an external 1k8 pull-up, so the internal 50k pull-down won't make much difference.

us3rnotfound
Posts: 7
Joined: Sat Jan 12, 2019 5:51 pm

Re: Static shock causing false GPIO detection

Sun Jan 13, 2019 2:43 pm

Burngate wrote:
Sun Jan 13, 2019 10:47 am
us3rnotfound wrote:
Sat Jan 12, 2019 6:00 pm
... a NO momentary switch tied to GPIO pins 5 (GPIO3) and 6 (GND)... Also I programmed it to use the built-in pull down resistor, no physical resistor was soldered in.
Note: GPIO 3 (and also GPIO 2, pin 3) already has an external 1k8 pull-up, so the internal 50k pull-down won't make much difference.
So when the system is halted (after the sudo shutdown OS command is issued), does the system wait for GPIO3 to go low to boot back up? Would a really quick pulse to ground cause it to boot, or is it still sampling at 250MHz while halted?

Here's a couple of images of my situation.
https://imgur.com/a/IM9R3DK

It is a metal case with plastic sides, but the 4 columns are metal. The system is on after I walked across the carpet of my office and tapped on the metal top. I couldn't get it to turn on tapping the case without the top on. Also, removing one wire of the power switch, I couldn't get it to turn on via a careful buildup of some charge via the carpet.

So should I try to solder a 100nF cap to the switch? That would be the easiest for me since the lugs are exposed.

us3rnotfound
Posts: 7
Joined: Sat Jan 12, 2019 5:51 pm

Re: Static shock causing false GPIO detection

Sun Jan 13, 2019 2:46 pm

One more thing, just now I plugged in the unplugged switch wire while it was running, and just doing that triggered a system shutdown. I am confused as to why that happened? The switch is open, so just plugging in a wire to one of the GPIO inputs shouldn't register a falling edge, I mean the signal wire from the switch is floating but in my Python code I do have some bouncetime 200ms I think.

us3rnotfound
Posts: 7
Joined: Sat Jan 12, 2019 5:51 pm

Re: Static shock causing false GPIO detection

Sun Jan 13, 2019 2:53 pm

wh7qq wrote:
Sat Jan 12, 2019 7:41 pm
It is possible to generate some extreme voltages when walking across carpeting, especially synthetics, with leather soled shoes. Steve Wozniak of Apple Computer fame has a nice video on the subject and you can probably find it on line somewhere (try https://www.youtube.com/watch?v=hLOQ7zOWGAA). The RPi is pretty robust but the kinds of voltages you can generate, especially in a cold, dry climate, can potentially damage most electronic devices. Check out the video if you can...worth watching.

That said, if the case and switch are non-conductive, an external pull-down on the GPIO pins might help...say 4.7k or 10k. If the case is metal and shares ground with the RPi, all bets are off.
I do have a metal case. So there's no other choice but to have a non-conductive case? Should I insulate the RPi from the case?

User avatar
davidcoton
Posts: 3549
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Static shock causing false GPIO detection

Sun Jan 13, 2019 9:33 pm

us3rnotfound wrote:
Sun Jan 13, 2019 2:43 pm
So should I try to solder a 100nF cap to the switch? That would be the easiest for me since the lugs are exposed.
Yes
Signature retired

us3rnotfound
Posts: 7
Joined: Sat Jan 12, 2019 5:51 pm

Re: Static shock causing false GPIO detection

Mon Jan 14, 2019 6:58 pm

davidcoton wrote:
Sun Jan 13, 2019 9:33 pm
us3rnotfound wrote:
Sun Jan 13, 2019 2:43 pm
So should I try to solder a 100nF cap to the switch? That would be the easiest for me since the lugs are exposed.
Yes
Don't I need a series resistor with it for an RC time constant? I don't want to damage anything by having only a cap.

Edit: I found a very similar problem here: viewtopic.php?t=108485

Should I try and make the LPF RC circuit that user GHP mentions, with the 100 ohm/0.1uF?

User avatar
davidcoton
Posts: 3549
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Static shock causing false GPIO detection

Mon Jan 14, 2019 7:13 pm

With 10nF (try that first) or 100nF it's not essential. But still good practice to put 1K in series with the GPIO input in case of accidental programming as an output. You don't want a resistor directly in series with the capacitor across the switch.
Signature retired

us3rnotfound
Posts: 7
Joined: Sat Jan 12, 2019 5:51 pm

Re: Static shock causing false GPIO detection

Mon Jan 14, 2019 11:06 pm

Just installed a 100nF capacitor onto the switch lugs and no dice, still does it. But admittedly it's a little harder to trigger it.

All i'm doing is tapping my finger on the lid while moving my socked foot across the carpet just enough (like 1 or 2 foot-long passes).

Are we sure there's an external pull-up resistor on the board for GPIO3?

Idahowalker
Posts: 443
Joined: Wed Jan 03, 2018 5:43 pm

Re: Static shock causing false GPIO detection

Tue Jan 15, 2019 2:14 am

Got an Ohm meter? If so what is the resistance reading between the case and the RPi common, GND?

Ohm with and without cables connected. Connect one cable at a time and ohm. If you get less then Infinity that's a problem. When you take the Ohm measurements do not touch the case or the ohm meter leads with your hand or other body part. Ohm one part of the case to the other, infinity?

Take the unit apart, clean out the dust, even the tiny bits of dust.

Other steps, wrap the case in foil, poke holes in the foil for air flow, and hook a ground to the foil. Ground being the 3rd wire from the power plug. The GPIO pin labeled ground is not really ground, more it is a circuit common.

Get a humidifer and run it.

Also, try not to zap the RPi anymore then needed. With common room conditions you can generate 5,000 volts per inch of spark, basically, Those tiny junctions inside those chips cannot take much of such treatment.
Without knowing why you are deleting my postings, I will not know how...

User avatar
Burngate
Posts: 5715
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Static shock causing false GPIO detection

Tue Jan 15, 2019 10:30 am

us3rnotfound wrote:
Mon Jan 14, 2019 11:06 pm
Are we sure there's an external pull-up resistor on the board for GPIO3?
On the schematic PDF it's labelled R23
On the board it's one of the three small unlabelled components near pin 9 of the header, beside the metal-topped chip with the raspberry logo on it.
R23 R24.png
R23 R24.png (75.35 KiB) Viewed 175 times

us3rnotfound
Posts: 7
Joined: Sat Jan 12, 2019 5:51 pm

Re: Static shock causing false GPIO detection

Wed Jan 16, 2019 8:56 pm

Idahowalker wrote:
Tue Jan 15, 2019 2:14 am
Got an Ohm meter? If so what is the resistance reading between the case and the RPi common, GND?

Ohm with and without cables connected. Connect one cable at a time and ohm. If you get less then Infinity that's a problem. When you take the Ohm measurements do not touch the case or the ohm meter leads with your hand or other body part. Ohm one part of the case to the other, infinity?

Take the unit apart, clean out the dust, even the tiny bits of dust.

Other steps, wrap the case in foil, poke holes in the foil for air flow, and hook a ground to the foil. Ground being the 3rd wire from the power plug. The GPIO pin labeled ground is not really ground, more it is a circuit common.

Get a humidifer and run it.

Also, try not to zap the RPi anymore then needed. With common room conditions you can generate 5,000 volts per inch of spark, basically, Those tiny junctions inside those chips cannot take much of such treatment.
Ohmeter reads infinity RPi gnd to case, with and without cables from switch connected. Any point on case to any point on case is infinity as well. If I probe across the pushbutton terminals, it's infinity disconnected and 60 x 200k = 12MOhm connected.

Should I connect a stronger pullup resistor to the GPIO input?

Return to “Troubleshooting”