Hardware Reference
In-Depth Information
Floating Potentials
The beginning student may be puzzled about “glitches” seen by some GPIO inputs (28 or
29). When a GPIO input without a pull-up resistor is unattached, the line can “float,” or
change over time, due to static electrical buildup. Unless a pull-up or pull-down resistor
is attached (or configured), the pin can assume intermediate voltages. A voltage in the
range of V IL = 0 . 8 V to V IH = 1 . 3 V is ambiguous to the Pi. Input voltages in this range may
read randomly as 1s or 0s.
If you are using a loose wire or alligator clip to apply high or low signals
to an input GpIO pin, be very careful to avoid static electricity, which can cause damage.
Use a ground strap or hold onto the pi's ground to bleed any static away, while changing
connections. Static electricity may also cause your raspberry pi to reset. a real ground,
like a water tap, is best for bleeding off static.
Caution
When using a button or switch, for example, use a pull-up resistor to +3.3 V (or
configure the SoC to use one). In this manner, high is immediately seen by the input
when the switch or button is temporarily unconnected.
Note
a switch is temporarily disconnected while changing its poles.
Reading Events
One of the shortcomings of the input script is that it must poll the input pin's value
continuously, to see if the value has changed. In a multiprocessing environment like
Linux, it is rude to burn the CPU like this (hence the compromise with the sleep
command). A better design would have the program wait for a change on the input pin,
allowing other processes to use the CPU while it waits.
The GPIO driver within the kernel is, in fact, able to do that, though not usable by
shell commands. The C program evinput.c is an example program that takes advantage
of this capability and is presented next. It uses the poll(2) system call to accomplish this.
The basic procedure used is this:
1.
The GPIO pin X is configured for input.
The value of /sys/class/gpio/gpioX/edge has been
configured for the edge(s) to be reported (see Table 10-5 ).
2.
When querying the input pin, the open file descriptor for /
sys/class/gpio/gpioX/value is provided to the poll(2) call
(line 111).
3.
 
 
Search WWH ::




Custom Search