I have two buttons connected to pins 16 and 20. The one going to pin 20 works well, actually too well. Sometimes when I press it, it records the press two times. The other button which is connected to pin 16 sometimes works and sometimes doesn't. I checked the wiring and connections and that's not it. I have a script that helps me check functionality, and the button is literally just not getting registered every other press or so. Sometimes I can press it 5 times in a row and it will see it, and then I click and click and nothing for 3-4 seconds.
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def print_msg(x):
print("Button {} was pushed!".format(x))
while True:
input_01 = GPIO.input(16)
input_02 = GPIO.input(20)
input_03 = GPIO.input(21)
if input_01 == False:
print_msg(1)
time.sleep(0.2)
if input_02 == False:
print_msg(2)
time.sleep(0.2)
if input_03 == False:
print_msg(3)
time.sleep(0.2)