Digital output, it is very wonderful features of a Raspberry Pi(RPi), RPi has some GPIO pins(General Purpose Input Output) which is helps to give digital data to digital output devices like led, Relay, Seven segment, led cube, led matrix etc.
In Digital world mainly two things are their which is ON & OFF; in uP language we can say that is 1 & 0 or 5v & Gnd. In case of RPi GPIO pin generate 5v or high signal to turn on led and gnd or low signal to turn off led.
So lets start how its work !!!
Digital Operation in RPi
INSTALL DEPENDENCY:
- Check any Python package installed in RPi
- Open terminal paste below code
python
python3
- If python and python3 is Not installed copy the below code and paste in terminal.
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python
sudo apt-get install pyhton3
DIGITAL OUTPUT
Install GPIO library for python
sudo apt-get install python-rpi.gpio python3-rpi.gpio
CIRCUIT CONNECTION:
Led is connected to GPIO2 which is pin3 of RPi as we know RPi generate 5v but led workings on 3v for that purpose we need one Resistor ie. 220E which is connected series with led and led cathode is connected to Gnd of RPi(pin6)
CODE:
import RPi.GPIO as GPIO ## Import GPIO library
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD) ## Use board pin numbering
GPIO.setup(3, GPIO.OUT) ## Setup Pin 3 to OUTPUT
while True:
#Infinite Loop
GPIO.output(3, True) ## Turn on pin 3
print ("led on")
time.sleep(1)
GPIO.output(3,False) ## Turn off pin 3
print ("led off")
time.sleep(1)
NOTE:
- Save above code in .py
- E.g.: led_blink.py
- Run code in terminal
python led_blink.py
Terminal
- If use Thonny IDE
Thonny IDE
Comments
Admin
Thanks For The Supprt.
2001-03-20 11:44:26Admin
Hi Sai, Thanks For the Reply :)
2001-03-20 06:57:09Sai Tat Sat
Hi Ramesh, GPIO Stands For General-purpose input/output , A general-purpose input/output is an uncommitted digital signal pin on an integrated circuit or electronic circuit board whose behavior—including whether it acts as input or output—is controllable by the user at run time.
2001-03-20 06:47:08Leave a Reply