Hi,
this tutorial today, will show how to use the raspberry and the linux installed, to control the GPIO with a simple Python script.
So the ideia, is to use the GPIO 17 and 18, to swith on and off, 2x LED´s.
Each LEd is connected to a GPIO with a serial resistance (1k) to limit the output current.
After a resistance is the LED.
Before connect the GPI check the pin on the raspberry site.
The GPIO of my raspberry is:
The schematic for the connections shall be:
The code of script is:
'''
Created on 23/01/2016
@author: tecbea
'''
# import gpio
import RPi.GPIO as GPIO
# import time
import time
def _ledLoop (io,num,sleep):
for num in range(1,num):
print "io %d on" % io
GPIO.output(io,GPIO.HIGH)
time.sleep(sleep)
print "io %d off" % io
GPIO.output(io,GPIO.LOW)
time.sleep(sleep)
def main():
print ("==init==")
# set mode on gpio 18
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
# output mode
GPIO.setup(17,GPIO.OUT)
GPIO.setup(18,GPIO.OUT)
_ledLoop(17,10,0.5);
_ledLoop(18,10,0.5);
_ledLoop(17,20,0.1);
_ledLoop(18,20,0.1);
# ###############################
if __name__ == "__main__":
main()
best