We have a project where we need to connect 5 buttons to the Explorer Hat PRO.
(simple push buttons that are either connected or not.)
4 of them we have connected to the input pins and they work like champs. what is the easiest place to connect the 5th one to? (I know I could make my own pull-ups or pull-downs and use the analog inputs but I am wondering if there is a simpler way.)
Thanks in advance,
Alan
If you use the Pi’s onboard pull-up then you can connect a button between any of the 3v3-only pins and ground. Granted the best choice is probably the “PWM” pin which corresponds to BCM18 on the Pi.
How do I access the BCM18? I am guessing I look through the explorer hat source code to see how the other ones work. Do I have to do anything special to turn on the onboard pull-up for BCM18?
Thanks in advance,
Alan
Under the hood, Explorer HAT uses the RPi.GPIO
library which is pretty well explained here - https://raspi.tv/2013/rpi-gpio-basics-6-using-inputs-and-outputs-together-with-rpi-gpio-pull-ups-and-pull-downs
You’ll be using something a bit like this:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
button = GPIO.input(18) # Read button value
You may want to investigate RPi.GPIO’s interrupt functionality for handling a button press, though.