I'm currently having trouble with my project. I'm using a Raspberry Pi 3B+ with an InnoMaker Hifi Amp Hat and some push buttons.
import time
import signal
import os
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
debounceTime = 300
btn1 = 24
btn2 = 25
btn3 = 13
btn4 = 12
btn5 = 16
def cb_btn1(channel):
print('Button 1 pressed')
def cb_btn2(channel):
print('Button 2 pressed')
def cb_btn3(channel):
print('Button 3 pressed')
def cb_btn4(channel):
print('Button 4 pressed')
def cb_btn5(channel):
print('Button 5 pressed')
class GracefulExit:
kill_now = False
def __init__(self):
signal.signal(signal.SIGINT, self.exit_gracefully)
signal.signal(signal.SIGTERM, self.exit_gracefully)
def exit_gracefully(self,signum, frame):
self.kill_now = True
GPIO.setup(btn1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(btn2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(btn3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(btn4, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(btn5, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(btn1, GPIO.FALLING, callback=cb_btn1, bouncetime=debounceTime)
GPIO.add_event_detect(btn2, GPIO.FALLING, callback=cb_btn2, bouncetime=debounceTime)
GPIO.add_event_detect(btn3, GPIO.FALLING, callback=cb_btn3, bouncetime=debounceTime)
GPIO.add_event_detect(btn4, GPIO.FALLING, callback=cb_btn4, bouncetime=debounceTime)
GPIO.add_event_detect(btn5, GPIO.FALLING, callback=cb_btn5, bouncetime=debounceTime)
def main():
app_killer = GracefulExit()
while not app_killer.kill_now:
try:
time.sleep(0.5)
except BaseException:
GPIO.cleanup()
print "Encountered an axeption."
break
print "End of the program."
GPIO.cleanup()
if __name__ == '__main__':
main()
I've tried with external pull-up/down and also adding a 0.1uF cap between 3.3V / GND and the GPIO.
I'm not using any pins that the Hat is supposed to use (GPIOs 18 to 21) according to the manual
My setup us currently on a breadboard, maybe I'm getting EMI with the jumpers wires...
I'm using a good quality power supply so I hope the problem isn't coming from here... For reference it's a Mean Well GSM40A12-P1J
I've discovered that touching the metal Ethernet/USB port with the metal tip of an USB flash drive or the tips of my multimeter probe trigger almost all my GPIO each times.
Is there something that I'm missing to get reliable input?
Edit:
Ok I'm slowly putting the pieces together. In order to make pigpiod
running on a non full raspbian image in addition to sudo apt install pigpiod
I had to run sudo apt install python3-pigpio
pigpiod
, I've installed it viasudo apt install pigpiod
and running viasudo pigpiod
. Trying to run the script tells meImportError: No module named pigpio
. Is there any additional package to install? I can't see on PyPl any python module calledpigpio
onlyapigpio
but I'm assuming that this is totally different?ps -aux
I can seeroot 2400 6.3 0.1 9976 1632 ? SLsl 04:07 0:12 pigpiod
but then when I trypython monitor.py
I haveTraceback (most recent call last): File "monitor.py", line 12, in <module> import pigpio ImportError: No module named pigpio
If I trysudo pigpiod
again I have2019-10-17 05:49:58 initInitialise: Can't lock /var/run/pigpio.pid Can't initialise pigpio library
./monitor.py 12 13 16 24 25