You will need the following things:
- Raspberry pi configured (see previos lessons)
- 5 Volt LED bulb(s)
- 2 jumper wires m/f
- 1 wire cutter with wire striper. (often found on long pliers)
First you will need to open terminal.What you need to type in terminal is :
sudo apt-get update
Then you need to install the python development code:
sudo apt-get install python-dev
Then you type:
sudo apt-get install python-rpi.gpio
Now we are done preparing your raspberry pi now lets prepare your cables and LED’s.
😎 First you should cut the Cable
On the same side of the wire strip off about one quarter inch with your wire cutter. You do this by placing the wire into the knot on the bottom. apply a little bit of pressure and pull down and back. After that you should have a striped wire. Do this twice.
With your striped wire you will want to find the LED and attach each of the striped sides of the wire to the LED leads.
Please notice that on of the pins on your LEDs are not the same length. The long LED pin is the positive side and the short LED pin is the negative side. Remember which color wire you attached to the positive side and which on you connected to the negative.
We need to connect the negative pin to any ground pin on your GPIO like in the pictures below. To find the pins on your raspberry pi i also included a pin chart to the raspberry pi 2 middle B, you might need to use Google if you have an older model of the raspberry pi.
Notice i used pin number 9 for my ground pin.
To do this you must connect the other wire to a positive pin out i used pin GPIO 11 after this it is time to write the program!!!!!!!!!!!!!!!!!!!!!!! 😎 😎
Go into the raspberry pi Menu, and under accessories, choose text editor. In your new file type your shebang line, same as before #!/usr/bin/python at the top. Skip a line and add the following code:
import RPi.GPIO as GPIO import time
This sets the words GPIO and time to the commands wee will use for blinking ouor light and pausing. Next you will need the following commands.
GPIO.setmode(GPIO.BOARD) GPIO.setup(11, GPIO.OUT) GPIO.output(11, GPIO.HIGH)
This tells python to let us use the GPIO pin board we then tell it to use the GPIO pin No. 11, to set it up for output, and to send 5v out through the pin. This makes your LED light up.
Now let’s finish our code:
time.sleep(.2) GPIO output(11,GPIO.LOW) GPIO.cleanup()
This is the last of your code, you should now save your file. You should save it to Desktop at least thats what i did. I made my file “test_blink.py”, but you can name yours what ever you want.
Above, “time.sleep(.2)” tells our code to pause for 2.1 seconds, then “GPIO.output(11,GPIO.LOW)” turns the LED off again. “GPIO.cleanup()” tells the pi to clean every thing up, and let other programs use GPIO.
Now it time to make our code executable and run it, just like last lesson. Type the following command into your terminal:
cd Desktop chmod 755 test_blink.py sudo ./test_blink.py
Now your LED will blink.