Flash an Led using your Raspberry Pi and Python

In the following example we will connect an LED and resistor to pin 7 of P1 on our Raspberry PI and we will flash an LED on, here is a picture of this

pi and led_bb

OK we will use python, this tutorial assumes you already have Raspbian , Python and the GPIO library installed. I downloaded the latest NOOBS image and this all appeared to be installed by default

Open the terminal and type in the following

[codesyntax lang=”bash”]

sudo idle

[/codesyntax]

You should see something like this

sudo idle

 

Wait for IDLE to open,  then click File > New to open a new window. Or you can use CTRL + N, you can see this below.

idle window

Now type in the following code

[codesyntax lang=”python”]

import RPi.GPIO as GPIO ## Import GPIO library

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD) ## Use board pin numbering
GPIO.setup(7, GPIO.OUT) ## Setup GPIO Pin 7 to OUT
GPIO.output(7,True) ## Turn on GPIO pin 7

[/codesyntax]

Click File > Save when you are finished (Ctrl + S).

To run your program, click Run > Run (Ctrl + F5), your LED should light

 

Related posts

DS18b20 and the Raspberry PI example