0% found this document useful (0 votes)
322 views

GPIO RaspberryPi

Ready to use Input and Output circuits are always important to experiment with any microcontroller. The Universal GPIO Board is very useful for beginners, hobbyist and students. It is suitable for carrying out quick experiments with any microcontroller and lets you access numerous peripheral devices. It provides access to pins through male connectors for wiring to the microcontroller development board.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
322 views

GPIO RaspberryPi

Ready to use Input and Output circuits are always important to experiment with any microcontroller. The Universal GPIO Board is very useful for beginners, hobbyist and students. It is suitable for carrying out quick experiments with any microcontroller and lets you access numerous peripheral devices. It provides access to pins through male connectors for wiring to the microcontroller development board.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

2014

Getting Started with Raspberry Pi and interfacing with an


Universal GPIO board

Author: P N KIRAN
Email ID:[email protected]

#9/3,Shree Lakshmi complex,2ndFloor,Opp,To Vivekananda Park,Girinagar,Bangalore-560085.www.tenettech.com

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.

#9/3,Shree Lakshmi complex,2ndFloor,Opp,To Vivekananda Park,Girinagar,Bangalore-560085.www.tenettech.com

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

o Select the drive letter of the SD card in the device box.


o Be careful to select the correct drive; if you get the wrong one you can destroy
your computer's hard disk! .
o Click Write
o And wait for the write to complete.

#9/3,Shree Lakshmi complex,2ndFloor,Opp,To Vivekananda Park,Girinagar,Bangalore-560085.www.tenettech.com

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

#9/3,Shree Lakshmi complex,2ndFloor,Opp,To Vivekananda Park,Girinagar,Bangalore-560085.www.tenettech.com

#9/3,Shree Lakshmi complex,2ndFloor,Opp,To Vivekananda Park,Girinagar,Bangalore-560085.www.tenettech.com

Interfacing 8 LEDs with Raspberry Pi:


Lets start with a quick introduction to the Raspberry Pi GPIO (General Purpose Input Output).There
are 26 GPIO pins in total including 3.3V (2), 5V (2) and GND (4). Raspberry Pi can set to HIGH
(taking the value 1) by connecting it to a voltage supply, or set to LOW (taking the value 0) by
connecting it to the ground and treat it as an output or it can detect the pin and treat as an input.
Raspberry Pi GPIO PIN OUT

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:

#9/3,Shree Lakshmi complex,2ndFloor,Opp,To Vivekananda Park,Girinagar,Bangalore-560085.www.tenettech.com

Raspberry Pi :

GPIO Board:

#9/3,Shree Lakshmi complex,2ndFloor,Opp,To Vivekananda Park,Girinagar,Bangalore-560085.www.tenettech.com

Pin Configurations:
Pi

GPIO BOARD

L1

L2

L3

L4

10

L5

11

L6

12

L7

13

L8

VCC

GND

#9/3,Shree Lakshmi complex,2ndFloor,Opp,To Vivekananda Park,Girinagar,Bangalore-560085.www.tenettech.com

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

#9/3,Shree Lakshmi complex,2ndFloor,Opp,To Vivekananda Park,Girinagar,Bangalore-560085.www.tenettech.com

Interfacing Push button with Raspberry Pi:


Push Button is a simple switch mechanism for controlling some aspect of a machine or a
process.Pushbutton is a component that connects two points in a circuit when you press it. For
example turns on an LED when you press the button.
Raspberry Pi Pinout:
Lets start with a quick introduction to the Raspberry Pi GPIO (General Purpose Input Output).There
are 26 GPIO pins in total including 3.3V (2), 5V (2) and GND (4). Raspberry Pi can set to HIGH
(taking the value 1) by connecting it to a voltage supply, or set to LOW (taking the value 0) by
connecting it to the ground and treat it as an output or it can detect the pin and treat as an input.

#9/3,Shree Lakshmi complex,2ndFloor,Opp,To Vivekananda Park,Girinagar,Bangalore-560085.www.tenettech.com

Hardware:
Raspberry Pi Model B
Power Cable
Push Button 4
Jumper wiresMale to Female
Connections:

Raspberry Pi:

#9/3,Shree Lakshmi complex,2ndFloor,Opp,To Vivekananda Park,Girinagar,Bangalore-560085.www.tenettech.com

GPIO BOARD :

Pin Configurations:
Pi

GPIO BOARD

SW1

10

SW2

11

SW3

12

SW4

VCC

GND

#9/3,Shree Lakshmi complex,2ndFloor,Opp,To Vivekananda Park,Girinagar,Bangalore-560085.www.tenettech.com

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

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
sudo python filename.py

#9/3,Shree Lakshmi complex,2ndFloor,Opp,To Vivekananda Park,Girinagar,Bangalore-560085.www.tenettech.com

Interfacing 7 SEGMENT with Raspberry Pi 7 SEGMENT:


A seven-segment display (SSD), or seven-segment indicator, is a form of electronic display device
for displaying decimal numerals that is an alternative to the more complex dot matrix displays.
Application Areas:
Digital Clocks,
Electronic meters
Electronic Devices for Displaying Numerical Informations.
Lets start with a quick introduction to the Raspberry Pi GPIO (General Purpose Input Output).There
are 26 GPIO pins in total including 3.3V (2), 5V (2) and GND (4). Raspberry Pi can set to HIGH
(taking the value 1) by connecting it to a voltage supply, or set to LOW (taking the value 0) by
connecting it to the ground and treat it as an output or it can detect the pin and treat as an input.
Raspberry Pi GPIO PIN OUT

Hardware:
Raspberry Pi Model B
Power Cable
7 Segment
Jumper wiresFemale to Female

#9/3,Shree Lakshmi complex,2ndFloor,Opp,To Vivekananda Park,Girinagar,Bangalore-560085.www.tenettech.com

Connections:

GPIO BOARD:

#9/3,Shree Lakshmi complex,2ndFloor,Opp,To Vivekananda Park,Girinagar,Bangalore-560085.www.tenettech.com

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)

#9/3,Shree Lakshmi complex,2ndFloor,Opp,To Vivekananda Park,Girinagar,Bangalore-560085.www.tenettech.com

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)

#9/3,Shree Lakshmi complex,2ndFloor,Opp,To Vivekananda Park,Girinagar,Bangalore-560085.www.tenettech.com

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

#9/3,Shree Lakshmi complex,2ndFloor,Opp,To Vivekananda Park,Girinagar,Bangalore-560085.www.tenettech.com

Interfacing Buzzer with Raspberry Pi:


Buzzer:
Buzzer or Beeper is an audio signaling device which may be mechanical, electromechanical
or piezoelectric.
Application Areas:
Alarm Device
Timer
Microwave Ovens
Household Appliances
Lets start with a quick introduction to the Raspberry Pi GPIO (General Purpose Input Output).There
are 26 GPIO pins in total including 3.3V (2), 5V (2) and GND (4). Raspberry Pi can set to HIGH
(taking the value 1) by connecting it to a voltage supply, or set to LOW (taking the value 0) by
connecting it to the ground and treat it as an output or it can detect the pin and treat as an input.
Raspberry Pi GPIO PIN OUT

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

#9/3,Shree Lakshmi complex,2ndFloor,Opp,To Vivekananda Park,Girinagar,Bangalore-560085.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)

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

#9/3,Shree Lakshmi complex,2ndFloor,Opp,To Vivekananda Park,Girinagar,Bangalore-560085.www.tenettech.com

Interfacing Potentiometer with Raspberry Pi


Potentiometer:
A potentiometer is a simple knob that provides a variable resistance. By turning the shaft of the
potentiometer, we change the amount of resistance on either side of the wiper which is connected to
the center pin of the potentiometer.
Application Areas:
Audio control
Television
Motion Control
Lets start with a quick introduction to the Raspberry Pi GPIO (General Purpose Input Output).There
are 26 GPIO pins in total including 3.3V (2), 5V (2) and GND (4). Raspberry Pi can set to HIGH
(taking the value 1) by connecting it to a voltage supply, or set to LOW (taking the value 0) by
connecting it to the ground and treat it as an output or it can detect the pin and treat as an input.
Raspberry Pi GPIO PIN OUT

Hardware:
Raspberry Pi Model B
Power Cable
POT
Jumper wiresMale to Female

#9/3,Shree Lakshmi complex,2ndFloor,Opp,To Vivekananda Park,Girinagar,Bangalore-560085.www.tenettech.com

Connections:

Raspberry Pi:

#9/3,Shree Lakshmi complex,2ndFloor,Opp,To Vivekananda Park,Girinagar,Bangalore-560085.www.tenettech.com

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

#9/3,Shree Lakshmi complex,2ndFloor,Opp,To Vivekananda Park,Girinagar,Bangalore-560085.www.tenettech.com

x=0
while True:
change = get_encoder_turn()
if change !==0:
x = x + change
print (x)

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

Training
Daily and weekly Deals
For queries:[email protected]
Contact:080-26722726

#9/3,Shree Lakshmi complex,2ndFloor,Opp,To Vivekananda Park,Girinagar,Bangalore-560085.www.tenettech.com

You might also like