Recently received my first Raspberry Pie and needed to get input sensors, especially a reed switch and also testing a Hall Effect Sensor
Reed Switch with Hardware Pull Down ( Resistors )
On the Pie this looks like
Reed Switch with Internal Pull Down Resistor
see below , gpios 0-8 are pulled high, the rest are pulled low. They are all inputs. Those initial power on states can not be changed – it’s wired into the SoC. So if you are wanting to use below make sure you use GPIO over 8 so it can withstand a reboot
Hall Effect Sensor with Hardware Pull Down ( Resistors )
This has three pins ( Extra Digital Out ) so needs to be Wired differently , we just need to protect the GPIO Pins
I used GPIO’s 4,5,6
#enables GPIO 4
echo 4 > /sys/class/gpio/export
#marks 4 as input ( not Output )
sudo echo in > /sys/class/gpio/gpio4/direction
#Configure the gpios to trigger an interrupt on both edge ( An edge is the name of a transition from HIGH to LOW (falling edge) ) – LOW to HIGH (rising edge).
echo both > /sys/class/gpio/gpio4/edge
#ActiveType
constant to select active high, which means that logical true
corresponds with high voltage. active low, which means that logical true
corresponds with low voltage. 0 (false) or 1 (true)
echo 0 > /sys/class/gpio/gpio4/active_low
How to read the current value of GPIO
cat /sys/class/gpio/gpio4/value
raspi-gpio get 4
How to set GPIO Pull Down
On Boot gpios 0-8 are pulled high, the rest are pulled low. They are all inputs. Those initial power on states can not be changed – it’s wired into the SoC
raspi-gpio set 4 pd
pu set GPIO in-pad pull up
pd set GPIO pin-pad pull down