Hardware Reference
In-Depth Information
Knowing the current draw you want for the LED, the resistor
R
can be calculated
from the following:
R
VV
I
-
=
CC
LED
LED
where
V
CC
is the supply voltage (+3.3 V).
V
LED
is the voltage drop for the LED.
I
LED
is the required current draw for the LED.
For
V
LED
it is best to assume the worst case and assume the lower voltage drop of 1.63 V.
Assuming we need 8 mA to get reasonable brightness from the LED, we can calculate the
resistance of the limiting resistor:
33 163
0 008
208 75
.
-
.
R =
.
. W
=
Since resistors come in standard values, we round up to a standard 10% component
of 220 Ω.
■
rounding resistance down would lead to higher current. It is better to err on the
side of less current.
Note
The LED and the 220 Ω limiting resistor can be wired according to Figure
10-4
(and
shown in Figure
10-6
). When wired this way, a high is written to the GPIO output port to
make current flow through the LED.
The sense of the GPIO port can be altered by the
sysfs
file
active_low
(see
Table
10-5
later in this chapter). Putting the GPIO pin 7 into active low mode reverses the
logic sense, as follows:
# echo 1 >/sys/class/gpio/gpio7/active_low
With this mode in effect, writing a 1 to GPIO pin 7 causes the pin to go “low” on the
output and causes the LED to go off:
# echo 1 >/sys/class/gpio/gpio7/value
If the LED was wired according to Figure
10-5
, it would turn on instead.