Saturday, March 4, 2017

Raspberry Pi First Program on LED Blink using Python

 1.Install Python Module RPi.GPIO
   sudo apt-get install python-dev python-rpi.gpio

2. Open Terminal (Command Prompt)
3. Launch IDLE IDE by typing in terminal
        sudo idle

4.  After the IDLE launches, open a new window by FILE>OPEN or Ctrl+N
 5. Type the code below in the window 

LED Config (Source:https://electrosome.com)

import time
import RPi.GPIO as GPIO       ## Import GPIO library
GPIO.setmode(GPIO.BOARD)      ## Use board pin numbering
GPIO.setup(11, GPIO.OUT)      ## Setup GPIO Pin 11 to OUT
while True:
 GPIO.output(11,True)  ## Turn on Led
 time.sleep(1)         ## Wait for one second
 GPIO.output(11,False) ## Turn off Led
 time.sleep(1)         ## Wait for one second
 
6. Save the code by FILE>SAVE or Ctrl+S 
7. Run your code RUN>RUN or Ctrl+F5 
8. The Led will start blinking now.

No comments:

Post a Comment