Hardware Reference
In-Depth Information
Figure 14-3:
A breadboard
circuit for a
simple LED
output
Remember that Python is case-sensitive, so be sure to type RPi.GPIO exactly as it appears.
To allow Python to understand the concept of time (in other words, to make the LED blink,
rather than just turning it on and off), you'll also need to import the time module. Add the
following line to the project:
import time
With the libraries imported, it's time to address the GPIO ports. The GPIO library makes it easy to
address the general-purpose ports through the instructions GPIO.output and GPIO.input ,
but before you can use them, you'll need to set the GPIO library in board mode—which numbers
the pins according to their physical position on the Raspberry Pi—and initialise the pins as either
inputs or outputs. In this example, Pin 11 is an output, so add the following line to the project:
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT)
Search WWH ::




Custom Search