I run this script when the Raspberry Pi boots. When a key is pressed (GPIO 19) the interrupt
function gets called.
If I remove the print("BUTTON PRESSED")
statement on line 10, the interrupt
function seems to be called twice in a row for a single button press.
Any idea why this is the case?
import RPi.GPIO as GPIO
import time
import subprocess
GPIO.setmode(GPIO.BCM)
GPIO.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def interrupt(channel):
print("BUTTON PRESSED")
p = subprocess.Popen(['node', '/btn.js', str(channel)], stdout=subprocess.PIPE)
out = p.stdout.read()
print(out)
GPIO.add_event_detect(19, GPIO.FALLING, callback=interrupt, bouncetime=1000)
try:
while True:
time.sleep(1)
except:
print("Exit GPIO Listener..")
finally
GPIO.cleanup()