Light a LED through Python programming on raspberry Pi
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install rpi.gpio
sudo raspi-config
advanced options > I2C > > ENABLE > YES (to enable)
to check type lsmod | grep i2c_
.. it returns something like i2c_BCM2708
sudo raspi-config
advanced options > SPI > ENABLE >YES (to enable)
to check, type lsmod | grep spi_
.. it will also return something similar
To create a file
sudo nano led_blink.py
Type the following code in the file:
#import the GPIO and time package
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.OUT)
# loop through 50 times, on/off for 1 second
for i in range(50):
GPIO.output(7,True)
time.sleep(1)
GPIO.output(7,False)
time.sleep(1)
GPIO.cleanup()
Save using CTRL+X > Y > Enter to confirm
Now Connect the LED
LED is connected to pin7 which is the fourth row (pin) in the inner column of pins. Use a 220 ohms resistor in series to limit current
Now type the following to run the code
sudo python led_blink.py