SlideShare uma empresa Scribd logo
1 de 24
Baixar para ler offline
Pi Maker
Workshop
Powered by:
http://www.inventrom.com/http://www.robotechlabs.com/
Mayank Joneja
botmayank.wordpress.com
botmayank@gmail.com
4.GPIO Access
Mayank Joneja
Warning!
 While the GPIO pins can provide lots of useful control
and sensing ability to the Raspberry Pi, it is important to
remember they are wired directly into the internal core
of the system.
 This means that they provide a very easy way to
introduce bad voltages and currents into the delicate
heart of the Raspberry Pi (this is not good and means it
is easy to break it without exercising a little care).
 http://elinux.org/RPi_Tutorial_EGHS:GPIO_Protection_Cir
cuits
 http://www.rhydolabz.com/index.php?main_page=pr
oduct_info&cPath=80&products_id=1045
Mayank Joneja
 Things we need to protect:
 1) Drawing excess current from the pins (or short-circuiting an output)
 2) Driving over-voltage on an input pin (anything above 3.3V should be
avoided). The PI has protection diodes between the pin and 3V3 and GND,
negative voltages are shorted to GND, but positive voltages greater than
3V3 + one "diode drop" (normally 0.5V) will be shorted to 5V, this means that
if you put a 5V power supply on the GPIO pin you will "feed" the 3V3 supply
with 4.5 Volt (5V - the diode drop) and that may damage 3V3 logic if the 5V
source succeeds in lifting the PI's 3V3 supply to an unsafe value. Note that if
you limit the current (for example with a 10K resistor) the small amount of
current flowing into the 3V3 supply will probably do no harm.
 3) Static shocks, from touching pins without suitable grounding (often called
ESD - ElectroStatic Discharge, occurs when your clothes etc build up an
electrical charge as you move around)
 All of these can potentially break your Raspberry Pi, damage the GPIO
circuits or weaken it over time (reducing its overall life).
Mayank Joneja
GPIO in Python
 The RPi.GPIO python module offers easy access to the GPIO
 The GPIO module comes pre-installed in Raspbian.
 However, in the rare case that you end up flashing a really old image on your SD card, I
guess you’ll need to install/download the RPi.GPIO module
 sudo apt-get update
 sudo apt-get install python-dev
 sudo apt-get install python-rpi.gpio
Mayank Joneja
BCM or BOARD
 There are 2 ways of numbering the IO pins on the 26 pin header on a Raspberry Pi within RPi.GPIO
 BOARD Mode
 This refers to the pin numbers on the P1 header of the Raspberry Pi board
 Advantage:
 Your hardware will always work, regardless of the board revision of the RPi
 You won’t need to rewire your connector or change your code
 BCM Mode:
 Lowest level way of working
 It refers to the channel numbers on the Broadcom SoC
 Disadvantage:
 You will always have to work with a diagram of which channel number goes to which pin on the RPi board
 Your script could break between revisions of the RasPi boards.
Mayank Joneja
Pinout
Mayank Joneja
Condensed Version
Mayank Joneja
 To specify which you are using:
GPIO.setmode(GPIO.BOARD) or GPIO.setmode(GPIO.BCM)
Mayank Joneja
Hookup an LED
 Connect the +ve pin of the LED to 3.3V via a resistor
 Connect the –ve pin of the LED to Ground
Mayank Joneja
Blink!
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7,GPIO.OUT)
GPIO.output(7,True) #to switch on,
#GPIO.output(7,False) #to switch off
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(4,GPIO.OUT)
GPIO.output(4,True) #to switch on,
#GPIO.output(4,False) #to switch off
Mayank Joneja
 To prevent warnings:
 GPIO.setwarnings(False)
 Delay Library:
 time.sleep
Mayank Joneja
The real Blink!
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7,GPIO.OUT)
while(True):
GPIO.output(7,True) #to switch on,
sleep(1) #stay on for 1 second
GPIO.output(7,False) #to switch off
sleep(1) #stay off for 1 second
Mayank Joneja
Pulse Width Modulation
 PWM is one of the most commonly
used techniques of achieving a wide
range of output voltages on a digital
output pin
 Applications:
 Controlling the brightness of an LED
 Speed Control of motors
 Driving Servo motors (Position control)
Mayank Joneja
PWM on the Pi
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7,GPIO.OUT)
while(True):
for n in range (0,3000):
#90 % duty cycle
GPIO.output(7,True) #to switch on,
sleep(0.010) #stay on for 0.010 second
GPIO.output(7,False) #to switch off
sleep(0.000) #stay off for 0.000 second (what ? I’m making a point you know :P)
for n in range (0,3000):
#10 % duty cycle
GPIO.output(7,True) #to switch on,
sleep(0.001) #stay on for 0.001 second
GPIO.output(7,False) #to switch off
sleep(0.009) #stay off for 0.009 second
The LED glows bright at a 100%
duty cycle first and then dull at
a 10% duty cycle.
The on/off switching is so fast,
that the human eye can’t see
the flickering/blinking at this
frequency due to persistence
of vision
Mayank Joneja
Buttons!
 The simplest input device is a push button
(also called a micro switch)
 A push button maintains an electrical
connection between its terminals as long
as the button is pressed
 When the button is pressed, a connection
is created between T1(or T1’) and T2
or(T2’)
Mayank Joneja
Pulling up/down a pin
 Many times, when nothing is connected to a micro-controller input pin, they remain in a
state of high impedance (HiZ)
 This can be interpreted as either 1 or 0 randomly by the micro.
 In order to avoid this unwanted input, Pull up or pull down resistances are used to force
the pin to a state (VCC or GND) depending on the connection of the pushbutton.
 Pull up involves connecting the pin to VCC via a big resistance like 10k Ohm
 Pull down involves connecting the pin to GND via a big resistance like 10k Ohm
 In either case, the resistor limits the current drawn from the power supply and ensures that
the path through the switch is ,electrically, the path of least resistance for current to flow
through once the switch is pressed.
Mayank Joneja
Connections for pull down
Mayank Joneja
Giggles
import RPi.GPIO as GPIO
from time import sleep
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11,GPIO.IN)
while True:
mybutton = GPIO.input(11)
if mybutton == True:
print ‘giggle’
#Debouncing ??
sleep(0.2)
Press [CTRL]+[C] to terminate
execution via keyboard interrupt
when you’re done 
Mayank Joneja
POP QUIZ (ominous thunder..)
 Write a small code to replicate the switch’s state on the LED (on if pressed, off if not) with:
 GPIO 7 as o/p LED, and 11 as i/p switch
Mayank Joneja
import RPi.GPIO as GPIO
from time import sleep
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11,GPIO.IN)
GPIO.setup(7,GPIO.OUT)
while True:
mybutton = GPIO.input(11)
if mybutton == True:
GPIO.output(7,True)
else:
GPIO.output(7, False)
#Debouncing ??
sleep(0.2)
Mayank Joneja
Scratch
 Scratch is an educational programming language and multimedia authoring tool
 Excellent first language
 Allows you to make interesting games
 GPIO Access on the Raspberry Pi
 http://cymplecy.wordpress.com/2013/04/22/scratch-gpio-version-2-introduction-for-
beginners/
Mayank Joneja
WebIOPi
 The Internet of Things (IoT) refers to uniquely identifiable
objects and their virtual representations in an Internet-like
structure
 WebIOPi is developed and tested on Raspbian
 Only dependency is Python 2.7 or 3.2
 https://learn.adafruit.com/raspberry-pi-garage-door-
opener/web-io-pi
 Cool Project: https://learn.adafruit.com/raspberry-pi-garage-
door-opener/web-io-pi-configuration
wget http://webiopi.googlecode.com/files/WebIOPi-0.6.0.tar.gz
tar xvzf WebIOPi-0.6.0.tar.gz
cd WebIOPi-0.6.0
sudo ./setup.sh
Mayank Joneja
 sudo python –m webiopi 8000
 8000: the port number
 Connect the Raspberry Pi to the network
 Open a browser and go to http://RaspberryPiIP:8000/
 RaspberryPiIP refers to the IP of you Pi eg:192.168.1.10
 You can even add a port redirection on your router and/or use IPv6 to control the GPIO
pins over the internet !
Mayank Joneja
Running WebIOPi
 User is “webiopi”
 Password is “raspberry”
 Glow LED, press Switch
 By choosing the GPIO Header Link on the main page, you will be able to control the GPIO
using a web UI
 Click the out/in button to change the direction
 Click the pins to change the GPIO o/p state

Mais conteúdo relacionado

Mais procurados

Hardware Hacking for JavaScript Engineers
Hardware Hacking for JavaScript EngineersHardware Hacking for JavaScript Engineers
Hardware Hacking for JavaScript EngineersFITC
 
Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013Tom Paulus
 
Raspberry pi-3 b-v1.2-schematics
Raspberry pi-3 b-v1.2-schematicsRaspberry pi-3 b-v1.2-schematics
Raspberry pi-3 b-v1.2-schematicshacguest
 
Raspberry pi-2 b-v1.2-schematics
Raspberry pi-2 b-v1.2-schematicsRaspberry pi-2 b-v1.2-schematics
Raspberry pi-2 b-v1.2-schematicshacguest
 
Ece3140 lab5 writeup
Ece3140 lab5 writeupEce3140 lab5 writeup
Ece3140 lab5 writeupChuck Moyes
 
Buy Arduino Uno r3 india
Buy Arduino Uno r3 indiaBuy Arduino Uno r3 india
Buy Arduino Uno r3 indiaRobomart India
 
Democratizing the Internet of Things
Democratizing the Internet of ThingsDemocratizing the Internet of Things
Democratizing the Internet of ThingsAdam Englander
 
Easy GPS Tracker using Arduino and Python
Easy GPS Tracker using Arduino and PythonEasy GPS Tracker using Arduino and Python
Easy GPS Tracker using Arduino and PythonNúria Vilanova
 
Arduino Information by Arpit Sharma
Arduino Information by Arpit SharmaArduino Information by Arpit Sharma
Arduino Information by Arpit SharmaArpit Sharma
 
Advanced view of projects raspberry pi list raspberry pi projects
Advanced view of projects raspberry pi list   raspberry pi projectsAdvanced view of projects raspberry pi list   raspberry pi projects
Advanced view of projects raspberry pi list raspberry pi projectsWiseNaeem
 
Advanced view of atmega microcontroller projects list 1649 at mega32 avr
Advanced view of atmega microcontroller projects list 1649  at mega32 avrAdvanced view of atmega microcontroller projects list 1649  at mega32 avr
Advanced view of atmega microcontroller projects list 1649 at mega32 avrWiseNaeem
 
Getting started with arduino workshop
Getting started with arduino workshopGetting started with arduino workshop
Getting started with arduino workshopSudar Muthu
 
Raspberry pi lcd-shield20x4
Raspberry pi lcd-shield20x4Raspberry pi lcd-shield20x4
Raspberry pi lcd-shield20x4Iulius Bors
 
I made some more expansion board for M5Stack
I made some more expansion  board for M5StackI made some more expansion  board for M5Stack
I made some more expansion board for M5StackMasawo Yamazaki
 

Mais procurados (17)

Hardware Hacking for JavaScript Engineers
Hardware Hacking for JavaScript EngineersHardware Hacking for JavaScript Engineers
Hardware Hacking for JavaScript Engineers
 
Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013
 
Simply arduino
Simply arduinoSimply arduino
Simply arduino
 
Raspberry pi-3 b-v1.2-schematics
Raspberry pi-3 b-v1.2-schematicsRaspberry pi-3 b-v1.2-schematics
Raspberry pi-3 b-v1.2-schematics
 
Raspberry pi-2 b-v1.2-schematics
Raspberry pi-2 b-v1.2-schematicsRaspberry pi-2 b-v1.2-schematics
Raspberry pi-2 b-v1.2-schematics
 
Ece3140 lab5 writeup
Ece3140 lab5 writeupEce3140 lab5 writeup
Ece3140 lab5 writeup
 
Buy Arduino Uno r3 india
Buy Arduino Uno r3 indiaBuy Arduino Uno r3 india
Buy Arduino Uno r3 india
 
Democratizing the Internet of Things
Democratizing the Internet of ThingsDemocratizing the Internet of Things
Democratizing the Internet of Things
 
Easy GPS Tracker using Arduino and Python
Easy GPS Tracker using Arduino and PythonEasy GPS Tracker using Arduino and Python
Easy GPS Tracker using Arduino and Python
 
Arduino Information by Arpit Sharma
Arduino Information by Arpit SharmaArduino Information by Arpit Sharma
Arduino Information by Arpit Sharma
 
Advanced view of projects raspberry pi list raspberry pi projects
Advanced view of projects raspberry pi list   raspberry pi projectsAdvanced view of projects raspberry pi list   raspberry pi projects
Advanced view of projects raspberry pi list raspberry pi projects
 
Advanced view of atmega microcontroller projects list 1649 at mega32 avr
Advanced view of atmega microcontroller projects list 1649  at mega32 avrAdvanced view of atmega microcontroller projects list 1649  at mega32 avr
Advanced view of atmega microcontroller projects list 1649 at mega32 avr
 
Arduino uno
Arduino unoArduino uno
Arduino uno
 
Getting started with arduino workshop
Getting started with arduino workshopGetting started with arduino workshop
Getting started with arduino workshop
 
Raspberry pi lcd-shield20x4
Raspberry pi lcd-shield20x4Raspberry pi lcd-shield20x4
Raspberry pi lcd-shield20x4
 
I made some more expansion board for M5Stack
I made some more expansion  board for M5StackI made some more expansion  board for M5Stack
I made some more expansion board for M5Stack
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 

Destaque

Introduction To Raspberry Pi with Simple GPIO pin Control
Introduction To Raspberry Pi with Simple GPIO pin ControlIntroduction To Raspberry Pi with Simple GPIO pin Control
Introduction To Raspberry Pi with Simple GPIO pin ControlPradip Bhandari
 
Introduction to Raspberry Pi and GPIO
Introduction to Raspberry Pi and GPIOIntroduction to Raspberry Pi and GPIO
Introduction to Raspberry Pi and GPIOKris Findlay
 

Destaque (7)

6.Web Servers
6.Web Servers6.Web Servers
6.Web Servers
 
3.Pi for Python
3.Pi for Python3.Pi for Python
3.Pi for Python
 
2.Accessing the Pi
2.Accessing the Pi2.Accessing the Pi
2.Accessing the Pi
 
5.Playtime
5.Playtime5.Playtime
5.Playtime
 
Gpio pins
Gpio pinsGpio pins
Gpio pins
 
Introduction To Raspberry Pi with Simple GPIO pin Control
Introduction To Raspberry Pi with Simple GPIO pin ControlIntroduction To Raspberry Pi with Simple GPIO pin Control
Introduction To Raspberry Pi with Simple GPIO pin Control
 
Introduction to Raspberry Pi and GPIO
Introduction to Raspberry Pi and GPIOIntroduction to Raspberry Pi and GPIO
Introduction to Raspberry Pi and GPIO
 

Semelhante a 4. GPIO Access

Raspberry Pi Using Python
Raspberry Pi Using PythonRaspberry Pi Using Python
Raspberry Pi Using PythonSeggy Segaran
 
Part-1 : Mastering microcontroller with embedded driver development
Part-1 : Mastering microcontroller with embedded driver development Part-1 : Mastering microcontroller with embedded driver development
Part-1 : Mastering microcontroller with embedded driver development FastBit Embedded Brain Academy
 
Interfacing two wire adc0831 to raspberry pi2 / Pi3
Interfacing two wire adc0831 to raspberry pi2 / Pi3Interfacing two wire adc0831 to raspberry pi2 / Pi3
Interfacing two wire adc0831 to raspberry pi2 / Pi3Dnyanesh Patil
 
Raspberry Pi GPIO Tutorial - Make Your Own Game Console
Raspberry Pi GPIO Tutorial - Make Your Own Game ConsoleRaspberry Pi GPIO Tutorial - Make Your Own Game Console
Raspberry Pi GPIO Tutorial - Make Your Own Game ConsoleRICELEEIO
 
Ins and Outs of GPIO Programming
Ins and Outs of GPIO ProgrammingIns and Outs of GPIO Programming
Ins and Outs of GPIO ProgrammingICS
 
Sensors, actuators and the Raspberry PI using Python
Sensors, actuators and the Raspberry PI using PythonSensors, actuators and the Raspberry PI using Python
Sensors, actuators and the Raspberry PI using PythonDerek Kiong
 
Con7968 let's get physical - io programming using pi4 j
Con7968   let's get physical - io programming using pi4 jCon7968   let's get physical - io programming using pi4 j
Con7968 let's get physical - io programming using pi4 jsavageautomate
 
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi [Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi Tomomi Imura
 
[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218CAVEDU Education
 
Getting Started with Raspberry Pi - USC 2013
Getting Started with Raspberry Pi - USC 2013Getting Started with Raspberry Pi - USC 2013
Getting Started with Raspberry Pi - USC 2013Tom Paulus
 
Building the Internet of Things with Raspberry Pi
Building the Internet of Things with Raspberry PiBuilding the Internet of Things with Raspberry Pi
Building the Internet of Things with Raspberry PiNeil Broers
 
ScratchGPIO, Raspberry Pi & BerryClip
ScratchGPIO, Raspberry Pi & BerryClipScratchGPIO, Raspberry Pi & BerryClip
ScratchGPIO, Raspberry Pi & BerryClipDavid Dryden
 
Raspberry-Pi GPIO
Raspberry-Pi GPIORaspberry-Pi GPIO
Raspberry-Pi GPIOSajib Sen
 

Semelhante a 4. GPIO Access (20)

Raspberry pi led blink
Raspberry pi led blinkRaspberry pi led blink
Raspberry pi led blink
 
Day4
Day4Day4
Day4
 
PPT+.pdf
PPT+.pdfPPT+.pdf
PPT+.pdf
 
Raspberry Pi Using Python
Raspberry Pi Using PythonRaspberry Pi Using Python
Raspberry Pi Using Python
 
Part-1 : Mastering microcontroller with embedded driver development
Part-1 : Mastering microcontroller with embedded driver development Part-1 : Mastering microcontroller with embedded driver development
Part-1 : Mastering microcontroller with embedded driver development
 
PPT+.pdf
PPT+.pdfPPT+.pdf
PPT+.pdf
 
Interfacing two wire adc0831 to raspberry pi2 / Pi3
Interfacing two wire adc0831 to raspberry pi2 / Pi3Interfacing two wire adc0831 to raspberry pi2 / Pi3
Interfacing two wire adc0831 to raspberry pi2 / Pi3
 
Raspberry Pi GPIO Tutorial - Make Your Own Game Console
Raspberry Pi GPIO Tutorial - Make Your Own Game ConsoleRaspberry Pi GPIO Tutorial - Make Your Own Game Console
Raspberry Pi GPIO Tutorial - Make Your Own Game Console
 
Ins and Outs of GPIO Programming
Ins and Outs of GPIO ProgrammingIns and Outs of GPIO Programming
Ins and Outs of GPIO Programming
 
Sensors, actuators and the Raspberry PI using Python
Sensors, actuators and the Raspberry PI using PythonSensors, actuators and the Raspberry PI using Python
Sensors, actuators and the Raspberry PI using Python
 
Con7968 let's get physical - io programming using pi4 j
Con7968   let's get physical - io programming using pi4 jCon7968   let's get physical - io programming using pi4 j
Con7968 let's get physical - io programming using pi4 j
 
Raspberry pi and pi4j
Raspberry pi and pi4jRaspberry pi and pi4j
Raspberry pi and pi4j
 
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi [Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
 
[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218
 
Getting Started with Raspberry Pi - USC 2013
Getting Started with Raspberry Pi - USC 2013Getting Started with Raspberry Pi - USC 2013
Getting Started with Raspberry Pi - USC 2013
 
Atomic pi Mini PC
Atomic pi Mini PCAtomic pi Mini PC
Atomic pi Mini PC
 
Atomic PI apug
Atomic PI apugAtomic PI apug
Atomic PI apug
 
Building the Internet of Things with Raspberry Pi
Building the Internet of Things with Raspberry PiBuilding the Internet of Things with Raspberry Pi
Building the Internet of Things with Raspberry Pi
 
ScratchGPIO, Raspberry Pi & BerryClip
ScratchGPIO, Raspberry Pi & BerryClipScratchGPIO, Raspberry Pi & BerryClip
ScratchGPIO, Raspberry Pi & BerryClip
 
Raspberry-Pi GPIO
Raspberry-Pi GPIORaspberry-Pi GPIO
Raspberry-Pi GPIO
 

Último

the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 

Último (20)

the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 

4. GPIO Access

  • 1. Pi Maker Workshop Powered by: http://www.inventrom.com/http://www.robotechlabs.com/ Mayank Joneja botmayank.wordpress.com botmayank@gmail.com 4.GPIO Access
  • 2. Mayank Joneja Warning!  While the GPIO pins can provide lots of useful control and sensing ability to the Raspberry Pi, it is important to remember they are wired directly into the internal core of the system.  This means that they provide a very easy way to introduce bad voltages and currents into the delicate heart of the Raspberry Pi (this is not good and means it is easy to break it without exercising a little care).  http://elinux.org/RPi_Tutorial_EGHS:GPIO_Protection_Cir cuits  http://www.rhydolabz.com/index.php?main_page=pr oduct_info&cPath=80&products_id=1045
  • 3. Mayank Joneja  Things we need to protect:  1) Drawing excess current from the pins (or short-circuiting an output)  2) Driving over-voltage on an input pin (anything above 3.3V should be avoided). The PI has protection diodes between the pin and 3V3 and GND, negative voltages are shorted to GND, but positive voltages greater than 3V3 + one "diode drop" (normally 0.5V) will be shorted to 5V, this means that if you put a 5V power supply on the GPIO pin you will "feed" the 3V3 supply with 4.5 Volt (5V - the diode drop) and that may damage 3V3 logic if the 5V source succeeds in lifting the PI's 3V3 supply to an unsafe value. Note that if you limit the current (for example with a 10K resistor) the small amount of current flowing into the 3V3 supply will probably do no harm.  3) Static shocks, from touching pins without suitable grounding (often called ESD - ElectroStatic Discharge, occurs when your clothes etc build up an electrical charge as you move around)  All of these can potentially break your Raspberry Pi, damage the GPIO circuits or weaken it over time (reducing its overall life).
  • 4. Mayank Joneja GPIO in Python  The RPi.GPIO python module offers easy access to the GPIO  The GPIO module comes pre-installed in Raspbian.  However, in the rare case that you end up flashing a really old image on your SD card, I guess you’ll need to install/download the RPi.GPIO module  sudo apt-get update  sudo apt-get install python-dev  sudo apt-get install python-rpi.gpio
  • 5. Mayank Joneja BCM or BOARD  There are 2 ways of numbering the IO pins on the 26 pin header on a Raspberry Pi within RPi.GPIO  BOARD Mode  This refers to the pin numbers on the P1 header of the Raspberry Pi board  Advantage:  Your hardware will always work, regardless of the board revision of the RPi  You won’t need to rewire your connector or change your code  BCM Mode:  Lowest level way of working  It refers to the channel numbers on the Broadcom SoC  Disadvantage:  You will always have to work with a diagram of which channel number goes to which pin on the RPi board  Your script could break between revisions of the RasPi boards.
  • 8. Mayank Joneja  To specify which you are using: GPIO.setmode(GPIO.BOARD) or GPIO.setmode(GPIO.BCM)
  • 9. Mayank Joneja Hookup an LED  Connect the +ve pin of the LED to 3.3V via a resistor  Connect the –ve pin of the LED to Ground
  • 10. Mayank Joneja Blink! import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(7,GPIO.OUT) GPIO.output(7,True) #to switch on, #GPIO.output(7,False) #to switch off import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(4,GPIO.OUT) GPIO.output(4,True) #to switch on, #GPIO.output(4,False) #to switch off
  • 11. Mayank Joneja  To prevent warnings:  GPIO.setwarnings(False)  Delay Library:  time.sleep
  • 12. Mayank Joneja The real Blink! import RPi.GPIO as GPIO from time import sleep GPIO.setmode(GPIO.BOARD) GPIO.setup(7,GPIO.OUT) while(True): GPIO.output(7,True) #to switch on, sleep(1) #stay on for 1 second GPIO.output(7,False) #to switch off sleep(1) #stay off for 1 second
  • 13. Mayank Joneja Pulse Width Modulation  PWM is one of the most commonly used techniques of achieving a wide range of output voltages on a digital output pin  Applications:  Controlling the brightness of an LED  Speed Control of motors  Driving Servo motors (Position control)
  • 14. Mayank Joneja PWM on the Pi import RPi.GPIO as GPIO from time import sleep GPIO.setmode(GPIO.BOARD) GPIO.setup(7,GPIO.OUT) while(True): for n in range (0,3000): #90 % duty cycle GPIO.output(7,True) #to switch on, sleep(0.010) #stay on for 0.010 second GPIO.output(7,False) #to switch off sleep(0.000) #stay off for 0.000 second (what ? I’m making a point you know :P) for n in range (0,3000): #10 % duty cycle GPIO.output(7,True) #to switch on, sleep(0.001) #stay on for 0.001 second GPIO.output(7,False) #to switch off sleep(0.009) #stay off for 0.009 second The LED glows bright at a 100% duty cycle first and then dull at a 10% duty cycle. The on/off switching is so fast, that the human eye can’t see the flickering/blinking at this frequency due to persistence of vision
  • 15. Mayank Joneja Buttons!  The simplest input device is a push button (also called a micro switch)  A push button maintains an electrical connection between its terminals as long as the button is pressed  When the button is pressed, a connection is created between T1(or T1’) and T2 or(T2’)
  • 16. Mayank Joneja Pulling up/down a pin  Many times, when nothing is connected to a micro-controller input pin, they remain in a state of high impedance (HiZ)  This can be interpreted as either 1 or 0 randomly by the micro.  In order to avoid this unwanted input, Pull up or pull down resistances are used to force the pin to a state (VCC or GND) depending on the connection of the pushbutton.  Pull up involves connecting the pin to VCC via a big resistance like 10k Ohm  Pull down involves connecting the pin to GND via a big resistance like 10k Ohm  In either case, the resistor limits the current drawn from the power supply and ensures that the path through the switch is ,electrically, the path of least resistance for current to flow through once the switch is pressed.
  • 18. Mayank Joneja Giggles import RPi.GPIO as GPIO from time import sleep GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) GPIO.setup(11,GPIO.IN) while True: mybutton = GPIO.input(11) if mybutton == True: print ‘giggle’ #Debouncing ?? sleep(0.2) Press [CTRL]+[C] to terminate execution via keyboard interrupt when you’re done 
  • 19. Mayank Joneja POP QUIZ (ominous thunder..)  Write a small code to replicate the switch’s state on the LED (on if pressed, off if not) with:  GPIO 7 as o/p LED, and 11 as i/p switch
  • 20. Mayank Joneja import RPi.GPIO as GPIO from time import sleep GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) GPIO.setup(11,GPIO.IN) GPIO.setup(7,GPIO.OUT) while True: mybutton = GPIO.input(11) if mybutton == True: GPIO.output(7,True) else: GPIO.output(7, False) #Debouncing ?? sleep(0.2)
  • 21. Mayank Joneja Scratch  Scratch is an educational programming language and multimedia authoring tool  Excellent first language  Allows you to make interesting games  GPIO Access on the Raspberry Pi  http://cymplecy.wordpress.com/2013/04/22/scratch-gpio-version-2-introduction-for- beginners/
  • 22. Mayank Joneja WebIOPi  The Internet of Things (IoT) refers to uniquely identifiable objects and their virtual representations in an Internet-like structure  WebIOPi is developed and tested on Raspbian  Only dependency is Python 2.7 or 3.2  https://learn.adafruit.com/raspberry-pi-garage-door- opener/web-io-pi  Cool Project: https://learn.adafruit.com/raspberry-pi-garage- door-opener/web-io-pi-configuration wget http://webiopi.googlecode.com/files/WebIOPi-0.6.0.tar.gz tar xvzf WebIOPi-0.6.0.tar.gz cd WebIOPi-0.6.0 sudo ./setup.sh
  • 23. Mayank Joneja  sudo python –m webiopi 8000  8000: the port number  Connect the Raspberry Pi to the network  Open a browser and go to http://RaspberryPiIP:8000/  RaspberryPiIP refers to the IP of you Pi eg:192.168.1.10  You can even add a port redirection on your router and/or use IPv6 to control the GPIO pins over the internet !
  • 24. Mayank Joneja Running WebIOPi  User is “webiopi”  Password is “raspberry”  Glow LED, press Switch  By choosing the GPIO Header Link on the main page, you will be able to control the GPIO using a web UI  Click the out/in button to change the direction  Click the pins to change the GPIO o/p state