The GPIO layout on the Raspberry Pi model B.
We will be using GPIO 17 which is Pin 11.
Installing the library for python.
sudo apt-get install python-dev python-rpi.gpio
Now create a file called blink.py
Add the following lines
import RPi.GPIO as GPIO
This imports the two libraries, the time library provides the delay for the LED to flash and the RPi.GPIO allows us to control the GPIO pins.
pin = 17
This sets pin to 17
This sets the pin mode to BCM so we can reference the pins and sets up pin 17 for output
This is the Loop where the LED is turned on then turned off.
while True: GPIO.output(pin, True) time.sleep(0.5) GPIO.output(pin, False) time.sleep(0.5)
Now connect the positive leg of your LED to pin 17 and the negative to ground.
When you run the code you should see the LED flash.