Hardware Reference
In-Depth Information
Note
Cats are especially bad for static electricity.
GPIO Input Test
To test out the GPIO input capability, a simple script is presented next (and is available
in the scripts subdirectory as a file named input ). By default, it assumes 0 for the active
low setting, meaning that normal logic applies to the input values. If, on the other hand,
a 1 is used, inverted logic will be applied. Using the script named input , apply one of the
following commands to start it ( ^C to end it):
# ./input 0 # Normal "active high" logic
. . .
# ./input 1 # Use active low logic
The script, of course, can be modified, but as listed, it reads an input on GPIO 25
(GEN6) and presents what it has read to GPIO 24 (GEN5). It additionally reports what has
been read to standard output. If the output (GPIO 24) is wired to an LED, the input status
will be visible in the LED (use Figure 10-6 as a guide for wiring).
The script has its limitations, one of which is that the sleep(1) command is used.
This causes it to have a somewhat sluggish response. If you don't like that, you can
comment out the else and sleep commands. As a consequence, it will hog the CPU,
however, but be more responsive.
#!/bin/bash
ALO="${1:−0}" # 1=active low, else 0
INP=25 # Read from GPIO 25 (GEN6)
OUT=24 # Write t o GPIO 24 (GEN5)
set −eu
trap "close_all" 0
function close_all() {
close $INP
close $OUT
}
function open() { # pin direction
dev=$SYS/gpio$1
if [ ! −d $dev ] ; then
echo $1 >$SYS/export
fi
echo $2 >$dev/direction
echo none >$dev/edge
echo $ALO >$dev/active_low
}
 
 
Search WWH ::




Custom Search