Basic Raspberry PI Projects
How to blink an LED using Raspberry Pi and the Python Software?
1. Gather all electronics materials and make the led-resistor circuit first.
Connection: Pin 18 > Led > Resistor > Ground.
2. Open the Raspbian icon menu, select programming and choose Python Idle
3. Once python is open, click File > New File
4. Copy and paste the code (to turn on/off led):
5. OR, copy and paste this code (to blink the led):
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)
while True:
GPIO.output(18, True) # Turn on pin 18
time.sleep(1) # Delay
GPIO.output(18, False) # Turn off pin 18
time.sleep(1) # delay
#GPIO.cleanup()
6. Then save: File > Save
7. To run script: Run > Run Module(F5)
8. To interrupt press Ctrl-C or Ctrl-X
If you plan to use the Terminal:
1. Open terminal.
2. Type: ~ nano filename.py
3. Copy either codes (4 or 5) on the text editor.
4. To save: Ctrl-X > Y > enter
5. To run: ~ sudo python filename.py
6. To stop: Ctrl-C
Raspberry Pi GPIO* :
1. Gather all electronics materials and make the led-resistor circuit first.
Connection: Pin 18 > Led > Resistor > Ground.
2. Open the Raspbian icon menu, select programming and choose Python Idle
3. Once python is open, click File > New File
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)
#print "Led ON"
GPIO.output(18,GPIO.HIGH)
time.sleep(10)
#print "Led OFF"
GPIO.output(18,GPIO.LOW)
5. OR, copy and paste this code (to blink the led):
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)
while True:
GPIO.output(18, True) # Turn on pin 18
time.sleep(1) # Delay
GPIO.output(18, False) # Turn off pin 18
time.sleep(1) # delay
#GPIO.cleanup()
6. Then save: File > Save
7. To run script: Run > Run Module(F5)
8. To interrupt press Ctrl-C or Ctrl-X
If you plan to use the Terminal:
1. Open terminal.
2. Type: ~ nano filename.py
3. Copy either codes (4 or 5) on the text editor.
4. To save: Ctrl-X > Y > enter
5. To run: ~ sudo python filename.py
6. To stop: Ctrl-C
Raspberry Pi GPIO* :
* GPIO = General Purpose Input Output
Comments
Post a Comment