Hardware Reference
In-Depth Information
GPIO Tester
If you decided to build yourself a prototype board with the Raspberry Pi mounted
on it, you may find this simple shell script useful for checking the wiring of the GPIO
breakout clips. Or perhaps you just want to verify that the connection brought out to
the breadboard is the correct one. Simply supply the GPIO pin number that you want to
blink, on the command line:
$ cat ./gp
#!/bin/bash
GPIO="$1"
SYS=/sys/class/gpio
DEV=/sys/class/gpio/gpio$GPIO
if [ ! −d $DEV ] ; then
# Make pin visible
echo $GPIO >$SYS/export
fi
# Set pin to output
echo out >$DEV/direction
function put() {
# Set value of pin (1 or 0)
echo $1 >$DEV/value
}
while true ; do
put 1
echo "GPIO $GPIO: on"
sleep 1
put 0
echo "GPIO $GPIO: off $(date)"
sleep 1
done
# End
To exercise GPIO 25 (GEN6), use this command (project file scripts/gp ):
# ./gp 25
When testing with an LED and alligator clip lead, ground yourself to the ground pin
first (or better still, a good ground like a water tap). Static electricity can be especially bad
in the winter months. It not only can cause your Pi to reset but also can inflict internal
damage. After discharging yourself to the ground pin, apply the lead and allow time
enough for 1-second-on and 1-second-off events.
 
Search WWH ::




Custom Search