0

I'm having a rather funny issue with GPIO & tactile switch.
The issue is as I understand purely electric.
My RPi is connected to a cheap usb "Extreme Style 5V 3.1A" PSU.
Same power outlet is occupied by a 8+ y/o fridge. What I'm experiencing is a false "button push" every time the fridge compressor kicks in, turns off or "changes gear", so there is as I understand some electrical interference.

What would be a correct way to prevent "electrical noise" from pushing my buttons?

Briefly, code I'm using:

GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
(...)
GPIO.wait_for_edge(pin, GPIO.FALLING)
  • Pretty sure this caused by a momentary voltage drop on the circuit. Anyway, experiment with using a long bounce time (50-100 ms). Hopefully that is enough to smooth out the ripple without noticeably affecting functionality from a human perspective. It is somewhere between hard and impossible to depress a standard tactile switch for less than 1/10th second. – goldilocks Feb 19 '18 at 20:23
  • could also try a filter on the input power, the pi gets pretty finicky when it doesn't get clean power. This problem can be fixed with code, but could cause other issues as well. – Chad G Feb 20 '18 at 0:31
1

Instead of waiting for an edge, you should debounce the switch input. The same code that gets rid of glitches when a button is pressed can also get rid of glitches caused by external events. The link is for the pigpio library, but if you google switch debouncing in software on the Raspberry PI, you will find other possibilities.

  • Thank you for replying. I use "wait for edge" because using while loop with 200ms sleep caused 100% utilization of one core for me :) I will try sleeping 50ms after edge is detected, then check if the input is high and only then treat it as a push. – Wojciechem Feb 19 '18 at 20:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.