GPIO RaspberryPi
GPIO RaspberryPi
Author: P N KIRAN
Email ID:[email protected]
Introduction:
This easy step by step guide will help you set up your raspberry pi and get started
Hardware requriment:
Raspberry pi
8GB Micro sd card
Software requriment :
Raspbian Debian Wheezy
Raspberry pi :
The Raspberry Pi is a credit-card sized computer that plugs into your TV and a keyboard. It is a
capable little computer which can be used in electronics projects, and for many of the things that your
desktop PC does, like spreadsheets, word-processing and games. It also plays high-definition video.
We want to see it being used by kids all over the world to learn how computers work, how to
manipulate the electronic world around them, and how to program.. for more info please visit the link
click here.
Raspbian: The officially recommended official distribution from the Foundation,based on Debian.
Note that raspbian.org is a community site, not operated by the Foundation. If youre looking for the
official distribution, visit the downloads page at raspberrypi.org.
Getting Started
Step 1:
Download Raspberry pi official Operating system Raspbian . For downloading this
OS please visit the link click here
Step 2:
Prepare your SD Card:
Plug an micro sd card in to an card reader and plug in to an pc format this micro sd
card using sd formater. For downloading this sd formater please visit the link click
here
SD card setup (copying the image to an SD card using on windows)
o Extract the image file 2013-09-09-wheezy-raspbian.img from the downloaded
.zip file.
o Write an downloaded OS in to an micro SD card using win32 disk imager .for
downloading this win32 disk imager please click here.
o Extract the executable from the zip file and run the Win32DiskImager utility.
You may need to run the utility as Administrator
o Insert the SD card into your SD card reader and check what drive letter it was
assigned.
o You can easily see the drive letter (for example F:) by looking in the left
column of Windows Explorer.
o If the card is not new, you should format it; otherwise Win32DiskImager may
hang.
o Select the 2013-09-09-wheezy-raspbian.img image file you extracted earlier
Step 3 :
Prepare and Connect
Insert your prepared micro SD Card in to an Raspberry pi Micro SD card slot .
Plug the HDMI output into your TV or monitor. Make sure your monitor is on.
Plug in the power supply. In general, try to make sure everything else is
hooked up before connecting the power.
Turn raspberry pi board on by plugging the micro usb Power cabel(5v,1A dc)
Step 4 :
Then Raspberry Pi, power it on, and it should boot up. There is an option in the configure script
that comes up to expand the partitions to use all of the SD card if you have used one larger than
8GB..
It will ask login id and password
start the graphical interface:
o raspberrypi login: pi
o Password: raspberry
o pi@raspberrypi ~ $ startx
Hardware:
Raspberry Pi Model B
Power Cable
LED 8
Breadboard
Jumper wiresMale to Female
If you do not have any of these components, make and online order from the following link.
www.tenettech.com
Connections:
Raspberry Pi :
GPIO Board:
Pin Configurations:
Pi
GPIO BOARD
L1
L2
L3
L4
10
L5
11
L6
12
L7
13
L8
VCC
GND
Code:
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BOARD)
from array import *
a = array('i',[3,5,7,8,10,11,12,13])
for i in range(0,8):
GPIO.setup(a[i],GPIO.OUT)
GPIO.output(a[i],GPIO.LOW)
sleep(0.04)
while 1:
for i in range(0,8):
GPIO.output(a[i],GPIO.HIGH)
sleep(0.04)
GPIO.output(a[i],GPIO.LOW)
sleep(0.04)
for i in range(0,8):
GPIO.output(a[7-i],GPIO.HIGH)
sleep(0.04)
GPIO.output(a[7-i],GPIO.LOW)
sleep(0.04)
Open Your Leafpad or nano editor from your LXterminal:
sudo leafpad filename.py
Type the above code in the editor and save the file. To run the code type the following command.
Once started running the programming led blinks from left to right and right to left.
sudo python filename.py
Hardware:
Raspberry Pi Model B
Power Cable
Push Button 4
Jumper wiresMale to Female
Connections:
Raspberry Pi:
GPIO BOARD :
Pin Configurations:
Pi
GPIO BOARD
SW1
10
SW2
11
SW3
12
SW4
VCC
GND
Code:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(8,GPIO.IN)
GPIO.setup(10,GPIO.IN)
GPIO.setup(11,GPIO.IN)
GPIO.setup(12,GPIO.IN)
while True:
if GPIO.input(8):
print First button has been pressed
elif GPIO.input(10):
print Second button has been pressed
elif GPIO.input(11):
print Third button has been pressed
else:
print Fourth button has been pressed
Hardware:
Raspberry Pi Model B
Power Cable
7 Segment
Jumper wiresFemale to Female
Connections:
GPIO BOARD:
Pin configurations:
Pi
GPIO BOARD
22
17
27
18
23
24
25
DP
CODE:
import RPi.GPIO as GPIO
import time
GPIO.setmode (GPIO.BCM)
GPIO.setup(22, GPIO.OUT)
GPIO.setup(17, GPIO.OUT)
GPIO.setup(27, GPIO.OUT)
GPIO.setup(4, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)
GPIO.setup(23, GPIO.OUT)
GPIO.setup(24, GPIO.OUT)
GPIO.setup(25, GPIO.OUT)
while True:
GPIO.output(4, GPIO.LOW)
time.sleep(.5)
GPIO.output(17, GPIO.LOW)
time.sleep(.5)
GPIO.output(27, GPIO.LOW)
time.sleep(.5)
GPIO.output(22, GPIO.LOW)
time.sleep(.5)
GPIO.output(18, GPIO.LOW)
time.sleep(.5)
GPIO.output(23, GPIO.LOW)
time.sleep(.5)
GPIO.output(25, GPIO.LOW)
time.sleep(.5)
GPIO.output(24, GPIO.LOW)
time.sleep(.5)
GPIO.output(24, GPIO.HIGH)
time.sleep(.5)
GPIO.output(24, GPIO.LOW)
time.sleep(.5)
GPIO.output(24, GPIO.HIGH)
time.sleep(.5)
GPIO.output(24, GPIO.LOW)
time.sleep(.5)
GPIO.output(24, GPIO.HIGH)
time.sleep(.5)
GPIO.output(4, GPIO.HIGH)
time.sleep(.5)
GPIO.output(17, GPIO.HIGH)
time.sleep(.5)
GPIO.output(27, GPIO.HIGH)
time.sleep(.5)
GPIO.output(22, GPIO.HIGH)
time.sleep(.5)
GPIO.output(18, GPIO.HIGH)
time.sleep(.5)
GPIO.output(23, GPIO.HIGH)
time.sleep(.5)
GPIO.output(25, GPIO.HIGH)
time.sleep(.5)
GPIO.output(24, GPIO.LOW)
time.sleep(.5)
GPIO.output(24, GPIO.HIGH)
time.sleep(.5)
GPIO.output(24, GPIO.LOW)
time.sleep(.5)
GPIO.output(24, GPIO.HIGH)
time.sleep(.5)
GPIO.output(24, GPIO.LOW)
time.sleep(.5)
GPIO.output(24, GPIO.HIGH)
time.sleep(.5)
Open Your Leafpad or nano editor from your LXterminal:
sudo leafpad filename.py
Type the above code in the editor and save the file. To run the code type the following
command. Once started running the programming led blinks from left to right and right to left.
sudo python filename.py
Hardware:
Raspberry Pi Model B
Power Cable
Buzzer
Breadboard
Jumper wiresMale to Female
If you do not have any of these components, make and online order from the following link.
www.tenettech.com
Circuit Diagram
Code:
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode (GPIO.BOARD)
GPIO.setup(12,GPIO.OUT)
while 1:
GPIO.output(12,GPIO.HIGH)
sleep(1)
GPIO.output(12,GPIO.LOW)
sleep(1)
Hardware:
Raspberry Pi Model B
Power Cable
POT
Jumper wiresMale to Female
Connections:
Raspberry Pi:
GPIO BOARD:
CODE:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
Input_A=18
Input_B=23
GPIO.setup (input_A, GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.setup (input_B, GPIO.IN,pull_up_down=GPIO.PUD_UP)
old_a=True
old_b=True
def get_encoder_turn():
global old_a,old_b
result=0
new_a = GPIO.input(input_A)
new_b = GPIO.input(input_B)
if new_a !=old_a or new_b != old_b:
if old_a == 0 and new_b != old_b:
result = (old_b * 2 ==1:
elif old_b == 0 and new_b ==1:
result = (old_a * 2 - 1)
old_a,old_b = new_a, new_b
time.sleep(0.001)
return result
x=0
while True:
change = get_encoder_turn()
if change !==0:
x = x + change
print (x)
Type the above code in the editor and save the file. To run the code type the following
command. Once started running the programming led blinks from left to right and right to left.
sudo python filename.py
Training
Daily and weekly Deals
For queries:[email protected]
Contact:080-26722726