Time: 10 minutes
Difficulty: Easy
You will need:
- A Raspberry Pi.
- A way to access its terminal.
- A breadboard.
- A 220 ohm resistor.
- An LED
- An Internet connection on your Pi.
- 2 Jumper Wires
Steps:
- If you don't have the GPIO library, you'll need to install it by typing sudo apt-get install python-dev python-rpi.gpio. If you get an error message, try typing sudo apt-get update --fix-missing and try again
- Wire up your pi exactly as shown. Be sure to do the wiring with the Pi unplugged.
- Type sudo nano /home/pi/Desktop/RPiLED.py
- Copy and paste the following code into the nano editor.
- import RPi.GPIO as GPIO import timedef blink(pin):GPIO.output(pin,GPIO.HIGH)time.sleep(1)GPIO.output(pin,GPIO.LOW)time.sleep(1)returnGPIO.setmode(GPIO.BOARD)GPIO.setup(11, GPIO.OUT)for i in range(0,50):blink(11)GPIO.cleanup()
- Exit the nano editor by pressing CTRL+X, Y, and Enter.
- Right now, running RPiLED.py will cause the LED to blink 50 times. You can change how many times the LED blinks by changing the highlighted text above.
- Try running your script by typing sudo python RPiLED.py in the terminal.
- If it does not work, check your wiring. If you don't see a problem, try using a different LED.
The code for RPiLED came from www.rpiblog.com.
No comments:
Post a Comment