I am using a Raspberry Pi 3 and in my particular case, I am using it to sense when either a button is pressed, or power is dropped, both using the same GPIO input.
Both functions work, however, there are small glitches that trigger my shutdown circuit, like plugging into the audio jack or plugging in the HDMI, or lights in the room, looking at it etc...
I've attempted hardware fixes like a cap on the input, to no avail.
I am led to believe that I need to use the
pi.set_glitch_filter to eliminate this issue, however I do not know how to implement it into my code..
Please have a look at what I am working with and hopefully someone here can clear this up some for me.. The particular piece in my code is "acandbutton"
#!/usr/bin/python import sys sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib') import RPi.GPIO as GPIO import xbmc powerholdPin = 24 # board pin 36 acandbuttonPin = 23 # board pin 37 def acandbutton_callback(channel): xbmc.executebuiltin("ShutDown") class Main: GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(acandbuttonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(powerholdPin, GPIO.OUT) GPIO.output(powerholdPin, GPIO.HIGH) GPIO.add_event_detect(acandbuttonPin, GPIO.FALLING, callback=acandbutton_callback, bouncetime=300) while not xbmc.abortRequested: xbmc.sleep(5) class TidyUp: GPIO.remove_event_detect(powerholdPin) GPIO.remove_event_detect(acandbuttonPin) GPIO.cleanup([powerholdPin,acandbuttonPin]) if (__name__ == "__main__"): Main() TidyUp()
The part on the right does everything that it needs to.. The part on the left is getting the spurious activity. It runs well if nothing else electronic is plugged in or switched, like a light in the room, or even my phone plugged into it's charger. It's that sensitive. The power to the PI is consistent and even powered when unplugged due to the UPS, although the intention is to have a clean shutdown when the wall power is either lost or due to a button press. (which both work). It's seeming to pick up on static or other micro-changes also.
Here's a link to another thread of similar issue perhaps..