In this chapter, you come to grips with the control of electronics through the Raspberry Pi’s GPIO connector.
Most of the recipes require the use of solderless breadboard and male-to-female and male-to-male jumper wires (see Recipe 9.8). To maintain compatibility with older 26-pin Raspberry Pi models, all the breadboard examples here only use the top 26 pins common to both GPIO layouts (see Recipe 9.1).
Be sure to check out the accompanying video for this recipe at http://razzpisampler.oreilly.com.
You want to know how to connect an LED to the Raspberry Pi.
Connect an LED to one of the GPIO pins using a 470Ω or 1kΩ series resistor to limit the current. To make this recipe, you will need:
Breadboard and jumper wires (see “Prototyping Equipment”)
470Ω resistor (see “Resistors and Capacitors”)
LED (see “Opto-Electronics”)
Figure 10-1 shows how you can wire this LED using a solderless breadboard and male-to-female jumper leads.
Having connected the LED, we need to be able to turn it on and off using commands from Python.
Start a Python console from the Terminal with superuser access and enter these commands:
$ sudo python >>> import RPi.GPIO as GPIO >>> GPIO.setmode(GPIO.BCM) >>> GPIO.setup(18, GPIO.OUT) >>> GPIO.output(18, ...