SlideShare a Scribd company logo
Building the Internet of Things 
with Raspberry Pi
Who am I? 
I am a Software Developer and Architect at 
Energy Partners 
Caution – I am not an Electronic Engineer! 
Building the Internet of Things 
with Raspberry Pi
Building the Internet of Things 
with Raspberry Pi
Building the Internet of Things 
with Raspberry Pi
Model A Model B Model B+ 
$25 $35 $35 
1 USB port 2 USB ports 4 USB ports 
No Ethernet 10/100 Ethernet 10/100 Ethernet 
SD card slot SD card slot Micro SD card slot 
Building the Internet of Things 
with Raspberry Pi
General-purpose 
input/output pins (GPIO) 
• GPIO pins can be configured 
to be input or output 
• Input values are readable - 
HIGH or LOW (3v3 or 0v) 
• Output values are 
writable/readable 
Building the Internet of Things 
with Raspberry Pi
The Hardware 
Building the Internet of Things 
with Raspberry Pi
Building an Input Circuit 
Opto-coupler / Opto-isolator 
Transfers electrical signals between 
two isolated circuits by using light 
Building the Internet of Things 
with Raspberry Pi
Building an Input Circuit 
Resistor 
Implements electrical resistance 
Reduce current flow 
Building the Internet of Things 
with Raspberry Pi
Pull-up / pull-down resistors 
• Pull-up resistors are connected 
to the high voltage (3.3V) 
• Pull-down resistors are 
connected to ground 
• Initialize an input pin to a 
known state when nothing is 
connected to it 
Building the Internet of Things 
with Raspberry Pi 
Pull-up resistor
Building an Input Circuit - The diagram 
Building the Internet of Things 
with Raspberry Pi
Building an Output Circuit - The 
components 
Transistor 
• Used to amplify and switch electronic 
signals and electrical power 
• A voltage or current applied to one pair of 
the transistor's terminals changes the 
current through another pair of terminals. 
Building the Internet of Things 
with Raspberry Pi
Building an Output Circuit - The 
components 
Relay 
• Electrically operated switch 
• Many relays use an electromagnet to 
mechanically operate a switch 
• To control a circuit by a low-power 
signal 
Building the Internet of Things 
with Raspberry Pi
Building an Output Circuit 
Building the Internet of Things 
with Raspberry Pi
Veroboard / Stripboard 
Building the Internet of Things 
with Raspberry Pi
26pin IDC ribbon cable + crimp 
connector 
Building the Internet of Things 
with Raspberry Pi
Shortcuts! 
Building the Internet of Things 
with Raspberry Pi
Accessories
The Software 
Building the Internet of Things 
with Raspberry Pi
Building the Internet of Things 
with Raspberry Pi
Finding your Pi's hardware revision 
cat /proc/cpuinfo 
Code(s) Model and revision 
2 Model B Revision 1.0 
3 Model B Revision 1.0 + ECN0001 
4, 5, 6 Model B Revision 2.0 
Building the Internet of Things 
with Raspberry Pi
Software considerations 
• The software is the easy 
part! 
• Possible to damage the Pi 
• Triple check your pin 
configuration 
Building the Internet of Things 
with Raspberry Pi
Introducing RPi.GPIO 
• Depending on your distro, probably already 
installed 
• If not, use pip: sudo pip install rpi.gpio 
Building the Internet of Things 
with Raspberry Pi
Basic usage 
#To import the RPi.GPIO module: 
import RPi.GPIO as GPIO 
#Select the pin numbering scheme: 
GPIO.setmode(GPIO.BOARD) 
# or 
GPIO.setmode(GPIO.BCM) 
Building the Internet of Things 
with Raspberry Pi
Exit Cleanly 
• Inputs are safer than outputs 
• Shorting outputs to ground can damage the PI 
• Any ports not reset before script exit will 
remain as is 
• Always perform cleanup before script exits 
Building the Internet of Things 
with Raspberry Pi
Exit Cleanly 
import RPi.GPIO as GPIO 
# the rest of your code goes here 
GPIO.cleanup() 
# remember, a program doesn't necessarily 
# exit at the last line! 
Building the Internet of Things 
with Raspberry Pi
Inputs - Setup 
import RPi.GPIO as GPIO 
#GPIO numbering 
GPIO.setmode(GPIO.BCM) 
channel = 7 
GPIO.setup(channel, GPIO.IN, pull_up_down=GPIO.PUD_UP) 
# or 
GPIO.setup(channel, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) 
Building the Internet of Things 
with Raspberry Pi
Inputs - Polling 
if GPIO.input(channel): 
print('Input was HIGH') 
else: 
print('Input was LOW') 
# Or, in a loop 
while GPIO.input(channel) == GPIO.LOW: 
# wait 10 ms 
time.sleep(0.01) 
Building the Internet of Things 
with Raspberry Pi
Inputs - wait_for_edge() 
• blocks execution until an edge is detected 
• GPIO.RISING, GPIO.FALLING or GPIO.BOTH 
GPIO.wait_for_edge(channel, GPIO.RISING) 
Building the Internet of Things 
with Raspberry Pi
Inputs - event_detected() 
• Designed to be used in a loop with other 
things 
# add rising edge detection on a channel 
GPIO.add_event_detect(channel, GPIO.RISING) 
do_something() 
if GPIO.event_detected(channel): 
print('Button pressed') 
Building the Internet of Things 
with Raspberry Pi
Inputs - Threaded callbacks 
• RPi.GPIO runs a second thread for callback 
functions 
GPIO.add_event_detect(channel, GPIO.RISING, 
callback=my_callback) 
Building the Internet of Things 
with Raspberry Pi
Outputs - Setup 
import RPi.GPIO as GPIO 
GPIO.setmode(GPIO.BOARD) 
GPIO.setup(12, GPIO.OUT) 
Building the Internet of Things 
with Raspberry Pi
Outputs 
#Set output to HIGH 
GPIO.output(12, GPIO.HIGH) 
#Set output to LOW 
GPIO.output(12, GPIO.LOW) 
#Read the state of the output 
GPIO.input(12) 
Building the Internet of Things 
with Raspberry Pi
Example - Bell 
Building the Internet of Things 
with Raspberry Pi
The Raspberry Pi Alarm 
Building the Internet of Things 
with Raspberry Pi
On Github 
github.com/nbroers/hal 
Building the Internet of Things 
with Raspberry Pi
What’s next? 
Building the Internet of Things 
with Raspberry Pi
Questions? 
Building the Internet of Things 
with Raspberry Pi
Parts list 
12V input circuit: 
• Optocoupler: LTV-847 - http://www.mantech.co.za/ProductInfo.aspx?Item=340M0324 
• Resistor: 1K Ohm - http://www.mantech.co.za/ProductInfo.aspx?Item=64M0009 
Output circuit: 
• Resistor: 100k ohm 
• Resistor: 10k ohm 
• Transistor (NPN Transistor): P2N2222AG - http://www.mantech.co.za/ProductInfo.aspx?Item=72M3626 
• Relay: EDR101A1200Z - http://www.mantech.co.za/ProductInfo.aspx?Item=35M1045 
• Diode: 1N4007: http://www.mantech.co.za/ProductInfo.aspx?Item=64M0027 
Extras: 
• 26pin IDC ribbon cable crimp connector - http://www.mantech.co.za/ProductInfo.aspx?Item=14M8762 
• Ribbon cable - http://www.mantech.co.za/ProductInfo.aspx?Item=45M0001 
• Single core cable 
• Veroboard - http://www.mantech.co.za/ProductInfo.aspx?Item=64M0010 
Building the Internet of Things 
with Raspberry Pi
References 
Input Circuit design: 
http://raspberrypihobbyist.blogspot.com/2012/09/gpio-input-circuit_19.html 
Output Circuit design: 
http://raspberrypihobbyist.blogspot.com/2012/10/revision-to-relay-circuit.html 
RPi.GPIO wiki 
http://sourceforge.net/p/raspberry-gpio-python/wiki/Home/ 
Raspberry Pi Technical Info 
http://elinux.org/RPi_Low-level_peripherals 
GPIO quick reference 
http://raspi.tv/2014/rpi-gpio-quick-reference-updated-for-raspberry-pi-b 
Exit Cleanly 
http://raspi.tv/2013/rpi-gpio-basics-3-how-to-exit-gpio-programs-cleanly-avoid-warnings-and-protect-your-pi 
Building the Internet of Things 
with Raspberry Pi
Neil Broers 
@nbroers 
neil@foo.co.za 
github.com/nbroers 
Building the Internet of Things 
with Raspberry Pi

More Related Content

PDF
Raspberry pi technical documentation
GR Techno Solutions
 
PPTX
Introduction To Raspberry Pi with Simple GPIO pin Control
Pradip Bhandari
 
ODP
Introduction to Raspberry Pi and GPIO
Kris Findlay
 
PPTX
Pi Is For Python
Brad Fortner
 
PDF
Introduction to Raspberry PI
Chandrashekar Babu
 
PPTX
Raspberry pi
Sachin More
 
PPTX
Getting Started with Raspberry Pi
yeokm1
 
PDF
Exploring Raspberry Pi
Lentin Joseph
 
Raspberry pi technical documentation
GR Techno Solutions
 
Introduction To Raspberry Pi with Simple GPIO pin Control
Pradip Bhandari
 
Introduction to Raspberry Pi and GPIO
Kris Findlay
 
Pi Is For Python
Brad Fortner
 
Introduction to Raspberry PI
Chandrashekar Babu
 
Raspberry pi
Sachin More
 
Getting Started with Raspberry Pi
yeokm1
 
Exploring Raspberry Pi
Lentin Joseph
 

What's hot (20)

PPTX
Raspberry Pi Free Session - 20_09_2014
Mandeesh Singh
 
PPT
Raspberry-Pi
Rehan Fazal
 
PDF
Introduction to Raspberrypi
Iheb Ben Salem
 
PPTX
Raspberry pi ppt
PavanKumar3601
 
PPTX
Raspberry Pi (Introduction)
Mandeesh Singh
 
PPTX
Raspberry PI
Software Infrastructure
 
PDF
Raspberry Pi - Lecture 6 Working on Raspberry Pi
Mohamed Abdallah
 
ODP
Raspberry Pi and Amateur Radio
Kevin Hooke
 
PPTX
RASPBERRY PI
VaishaliSrigadhi
 
PDF
IPv6: A Digital Game Changer
CARLOS RALLI-UCENDO
 
PPTX
Raspberry pi
ABHIJITPATRA23
 
PDF
Single Board Computers & Raspberry Pi Basics
Eueung Mulyana
 
PPSX
Low Cost HD Surveillance Camera using Raspberry PI
Varun A M
 
PPT
Raspberry pi
Anija Nair
 
PPT
Raspberry Pi
Tusharkant Behera
 
PPTX
Raspberry Pi Using Python
Seggy Segaran
 
PDF
Raspberry JAM 1 - Setup Raspberry Pi with Raspbian -Vick Nesh
TE4P
 
PPTX
Raspberry pi complete setup
Santosh Kumar Kar
 
PPTX
Introduction to raspberry pi
praveen_23
 
PPTX
Raspberry pi
Vasigaran Senthilkumar
 
Raspberry Pi Free Session - 20_09_2014
Mandeesh Singh
 
Raspberry-Pi
Rehan Fazal
 
Introduction to Raspberrypi
Iheb Ben Salem
 
Raspberry pi ppt
PavanKumar3601
 
Raspberry Pi (Introduction)
Mandeesh Singh
 
Raspberry Pi - Lecture 6 Working on Raspberry Pi
Mohamed Abdallah
 
Raspberry Pi and Amateur Radio
Kevin Hooke
 
RASPBERRY PI
VaishaliSrigadhi
 
IPv6: A Digital Game Changer
CARLOS RALLI-UCENDO
 
Raspberry pi
ABHIJITPATRA23
 
Single Board Computers & Raspberry Pi Basics
Eueung Mulyana
 
Low Cost HD Surveillance Camera using Raspberry PI
Varun A M
 
Raspberry pi
Anija Nair
 
Raspberry Pi
Tusharkant Behera
 
Raspberry Pi Using Python
Seggy Segaran
 
Raspberry JAM 1 - Setup Raspberry Pi with Raspbian -Vick Nesh
TE4P
 
Raspberry pi complete setup
Santosh Kumar Kar
 
Introduction to raspberry pi
praveen_23
 
Ad

Viewers also liked (20)

PDF
[16.01.05] node.js & mqtt
Na-yeon Park
 
PDF
Leveraging Android for the Internet of Things with Eclipse M2M
Benjamin Cabé
 
PDF
Raspberry Pi + Python
Daker Fernandes
 
PPT
Raspberry pi : an introduction
LTG Oxford
 
PDF
Raspberry pi a la cfml
ColdFusionConference
 
PPTX
Alvin Edwald Chan - Why internet of things
Reginald Agsalon
 
PDF
Un Raspberry Pi pour bidouiller
Look a box
 
PPTX
Rasberry nodejs install_final
Kwan Yeong Kim
 
PDF
RASPBERRY PI WITH JAVA 8 + Pi4J (Devoxx 2014)
savageautomate
 
ODP
MQTT on Raspberry Pi with node.js
Paul Tanner
 
PPTX
Raspberry Pi - Einführung und Beispielprojekte
Peter Eulberg
 
PPTX
Beacons, Raspberry Pi & Node.js
Jeff Prestes
 
PDF
Home Automation
Cássio Landim
 
PDF
Create connected home devices using a Raspberry Pi, Siri and ESPNow for makers.
Nat Weerawan
 
PPTX
Raspbeery PI IoT
Tony Gerdjikov
 
PDF
Internet das coisas (IoT) com Raspberry, Python e Node.js
Otávio Calaça Xavier
 
PDF
An introduction to workflow-based programming with Node-RED
Boris Adryan
 
PDF
Physical computing with Python and Raspberry Pi
bennuttall
 
PDF
[IoT] MAKE with Open H/W + Node.JS - 1st
Park Jonggun
 
PPT
Hy Wire Car Technology
Vishal Singh
 
[16.01.05] node.js & mqtt
Na-yeon Park
 
Leveraging Android for the Internet of Things with Eclipse M2M
Benjamin Cabé
 
Raspberry Pi + Python
Daker Fernandes
 
Raspberry pi : an introduction
LTG Oxford
 
Raspberry pi a la cfml
ColdFusionConference
 
Alvin Edwald Chan - Why internet of things
Reginald Agsalon
 
Un Raspberry Pi pour bidouiller
Look a box
 
Rasberry nodejs install_final
Kwan Yeong Kim
 
RASPBERRY PI WITH JAVA 8 + Pi4J (Devoxx 2014)
savageautomate
 
MQTT on Raspberry Pi with node.js
Paul Tanner
 
Raspberry Pi - Einführung und Beispielprojekte
Peter Eulberg
 
Beacons, Raspberry Pi & Node.js
Jeff Prestes
 
Home Automation
Cássio Landim
 
Create connected home devices using a Raspberry Pi, Siri and ESPNow for makers.
Nat Weerawan
 
Raspbeery PI IoT
Tony Gerdjikov
 
Internet das coisas (IoT) com Raspberry, Python e Node.js
Otávio Calaça Xavier
 
An introduction to workflow-based programming with Node-RED
Boris Adryan
 
Physical computing with Python and Raspberry Pi
bennuttall
 
[IoT] MAKE with Open H/W + Node.JS - 1st
Park Jonggun
 
Hy Wire Car Technology
Vishal Singh
 
Ad

Similar to Building the Internet of Things with Raspberry Pi (20)

PPTX
M.Tech Internet of Things Unit - III.pptx
AvinashAvuthu2
 
PDF
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
Tomomi Imura
 
PPTX
Unit 3 Complete.pptx
Selvaraj Seerangan
 
PDF
IoT Physical Devices and End Points.pdf
GVNSK Sravya
 
PPTX
Raspberry-Pi, Developing on Raspberry Pi, Difference between Arduino & Raspbe...
Megha Sharma
 
PPTX
Capstone_Project.ppt
Dhruvkumar Panchal
 
PDF
Raspberry Pi GPIO Tutorial - Make Your Own Game Console
RICELEEIO
 
PPTX
IoT for data science Module 5 - Raspberry Pi.pptx
MadhurimaDas52
 
PPTX
Bulb Control using Web App with Raspberry Pi
Sanjay Kumar
 
PDF
Amity Raspberry Jam
Vishal Aditya
 
PPTX
[5]投影片 futurewad樹莓派研習會 141218
CAVEDU Education
 
DOCX
Raspberry Pi
Rukaifra Incorporation
 
PDF
Linux Format - Get Into Linux Today
Heart Disk
 
PDF
02 Raspberry Pi GPIO Interface on Node-RED (Some correction)
Mr.Nukoon Phimsen
 
PDF
Raspberry Pi
Selvaraj Seerangan
 
PPTX
IoT Aquarium 2
Benjamin Chodroff
 
PPTX
Java Webinar #9: “Raspberry Pi Platform for Java Programmers”
GlobalLogic Ukraine
 
PPTX
Raspberry pi led blink
vishal choudhary
 
PPTX
Got Python I/O: IoT Develoment in Python via GPIO
Adam Englander
 
PPTX
Python-in-Embedded-systems.pptx
TuynLCh
 
M.Tech Internet of Things Unit - III.pptx
AvinashAvuthu2
 
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
Tomomi Imura
 
Unit 3 Complete.pptx
Selvaraj Seerangan
 
IoT Physical Devices and End Points.pdf
GVNSK Sravya
 
Raspberry-Pi, Developing on Raspberry Pi, Difference between Arduino & Raspbe...
Megha Sharma
 
Capstone_Project.ppt
Dhruvkumar Panchal
 
Raspberry Pi GPIO Tutorial - Make Your Own Game Console
RICELEEIO
 
IoT for data science Module 5 - Raspberry Pi.pptx
MadhurimaDas52
 
Bulb Control using Web App with Raspberry Pi
Sanjay Kumar
 
Amity Raspberry Jam
Vishal Aditya
 
[5]投影片 futurewad樹莓派研習會 141218
CAVEDU Education
 
Linux Format - Get Into Linux Today
Heart Disk
 
02 Raspberry Pi GPIO Interface on Node-RED (Some correction)
Mr.Nukoon Phimsen
 
Raspberry Pi
Selvaraj Seerangan
 
IoT Aquarium 2
Benjamin Chodroff
 
Java Webinar #9: “Raspberry Pi Platform for Java Programmers”
GlobalLogic Ukraine
 
Raspberry pi led blink
vishal choudhary
 
Got Python I/O: IoT Develoment in Python via GPIO
Adam Englander
 
Python-in-Embedded-systems.pptx
TuynLCh
 

Recently uploaded (20)

PDF
A REACT POMODORO TIMER WEB APPLICATION.pdf
Michael624841
 
PDF
Why Should Businesses Extract Cuisine Types Data from Multiple U.S. Food Apps...
devilbrown689
 
PPTX
Materi_Pemrograman_Komputer-Looping.pptx
RanuFajar1
 
PDF
QAware_Mario-Leander_Reimer_Architecting and Building a K8s-based AI Platform...
QAware GmbH
 
PDF
The Future of Smart Factories Why Embedded Analytics Leads the Way
Varsha Nayak
 
PPTX
Presentation of Computer CLASS 2 .pptx
darshilchaudhary558
 
PPTX
Services offered by Dynamic Solutions in Pakistan
DaniyaalAdeemShibli1
 
PDF
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
Hironori Washizaki
 
PPTX
10 Hidden App Development Costs That Can Sink Your Startup.pptx
Lunar Web Solution
 
PDF
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
PPTX
Hire Expert Blazor Developers | Scalable Solutions by OnestopDA
OnestopDA
 
PDF
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
Q-Advise
 
PDF
Bandai Playdia The Book - David Glotz
BluePanther6
 
PDF
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
PDF
Rise With SAP partner in Mumbai.........
pts464036
 
PPTX
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PPTX
Audio Editing and it's techniques in computer graphics.pptx
fosterbayirinia3
 
PDF
Exploring AI Agents in Process Industries
amoreira6
 
PDF
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
ESUG
 
PPT
Order to Cash Lifecycle Overview R12 .ppt
nbvreddy229
 
A REACT POMODORO TIMER WEB APPLICATION.pdf
Michael624841
 
Why Should Businesses Extract Cuisine Types Data from Multiple U.S. Food Apps...
devilbrown689
 
Materi_Pemrograman_Komputer-Looping.pptx
RanuFajar1
 
QAware_Mario-Leander_Reimer_Architecting and Building a K8s-based AI Platform...
QAware GmbH
 
The Future of Smart Factories Why Embedded Analytics Leads the Way
Varsha Nayak
 
Presentation of Computer CLASS 2 .pptx
darshilchaudhary558
 
Services offered by Dynamic Solutions in Pakistan
DaniyaalAdeemShibli1
 
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
Hironori Washizaki
 
10 Hidden App Development Costs That Can Sink Your Startup.pptx
Lunar Web Solution
 
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
Hire Expert Blazor Developers | Scalable Solutions by OnestopDA
OnestopDA
 
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
Q-Advise
 
Bandai Playdia The Book - David Glotz
BluePanther6
 
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
Rise With SAP partner in Mumbai.........
pts464036
 
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Audio Editing and it's techniques in computer graphics.pptx
fosterbayirinia3
 
Exploring AI Agents in Process Industries
amoreira6
 
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
ESUG
 
Order to Cash Lifecycle Overview R12 .ppt
nbvreddy229
 

Building the Internet of Things with Raspberry Pi

  • 1. Building the Internet of Things with Raspberry Pi
  • 2. Who am I? I am a Software Developer and Architect at Energy Partners Caution – I am not an Electronic Engineer! Building the Internet of Things with Raspberry Pi
  • 3. Building the Internet of Things with Raspberry Pi
  • 4. Building the Internet of Things with Raspberry Pi
  • 5. Model A Model B Model B+ $25 $35 $35 1 USB port 2 USB ports 4 USB ports No Ethernet 10/100 Ethernet 10/100 Ethernet SD card slot SD card slot Micro SD card slot Building the Internet of Things with Raspberry Pi
  • 6. General-purpose input/output pins (GPIO) • GPIO pins can be configured to be input or output • Input values are readable - HIGH or LOW (3v3 or 0v) • Output values are writable/readable Building the Internet of Things with Raspberry Pi
  • 7. The Hardware Building the Internet of Things with Raspberry Pi
  • 8. Building an Input Circuit Opto-coupler / Opto-isolator Transfers electrical signals between two isolated circuits by using light Building the Internet of Things with Raspberry Pi
  • 9. Building an Input Circuit Resistor Implements electrical resistance Reduce current flow Building the Internet of Things with Raspberry Pi
  • 10. Pull-up / pull-down resistors • Pull-up resistors are connected to the high voltage (3.3V) • Pull-down resistors are connected to ground • Initialize an input pin to a known state when nothing is connected to it Building the Internet of Things with Raspberry Pi Pull-up resistor
  • 11. Building an Input Circuit - The diagram Building the Internet of Things with Raspberry Pi
  • 12. Building an Output Circuit - The components Transistor • Used to amplify and switch electronic signals and electrical power • A voltage or current applied to one pair of the transistor's terminals changes the current through another pair of terminals. Building the Internet of Things with Raspberry Pi
  • 13. Building an Output Circuit - The components Relay • Electrically operated switch • Many relays use an electromagnet to mechanically operate a switch • To control a circuit by a low-power signal Building the Internet of Things with Raspberry Pi
  • 14. Building an Output Circuit Building the Internet of Things with Raspberry Pi
  • 15. Veroboard / Stripboard Building the Internet of Things with Raspberry Pi
  • 16. 26pin IDC ribbon cable + crimp connector Building the Internet of Things with Raspberry Pi
  • 17. Shortcuts! Building the Internet of Things with Raspberry Pi
  • 19. The Software Building the Internet of Things with Raspberry Pi
  • 20. Building the Internet of Things with Raspberry Pi
  • 21. Finding your Pi's hardware revision cat /proc/cpuinfo Code(s) Model and revision 2 Model B Revision 1.0 3 Model B Revision 1.0 + ECN0001 4, 5, 6 Model B Revision 2.0 Building the Internet of Things with Raspberry Pi
  • 22. Software considerations • The software is the easy part! • Possible to damage the Pi • Triple check your pin configuration Building the Internet of Things with Raspberry Pi
  • 23. Introducing RPi.GPIO • Depending on your distro, probably already installed • If not, use pip: sudo pip install rpi.gpio Building the Internet of Things with Raspberry Pi
  • 24. Basic usage #To import the RPi.GPIO module: import RPi.GPIO as GPIO #Select the pin numbering scheme: GPIO.setmode(GPIO.BOARD) # or GPIO.setmode(GPIO.BCM) Building the Internet of Things with Raspberry Pi
  • 25. Exit Cleanly • Inputs are safer than outputs • Shorting outputs to ground can damage the PI • Any ports not reset before script exit will remain as is • Always perform cleanup before script exits Building the Internet of Things with Raspberry Pi
  • 26. Exit Cleanly import RPi.GPIO as GPIO # the rest of your code goes here GPIO.cleanup() # remember, a program doesn't necessarily # exit at the last line! Building the Internet of Things with Raspberry Pi
  • 27. Inputs - Setup import RPi.GPIO as GPIO #GPIO numbering GPIO.setmode(GPIO.BCM) channel = 7 GPIO.setup(channel, GPIO.IN, pull_up_down=GPIO.PUD_UP) # or GPIO.setup(channel, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) Building the Internet of Things with Raspberry Pi
  • 28. Inputs - Polling if GPIO.input(channel): print('Input was HIGH') else: print('Input was LOW') # Or, in a loop while GPIO.input(channel) == GPIO.LOW: # wait 10 ms time.sleep(0.01) Building the Internet of Things with Raspberry Pi
  • 29. Inputs - wait_for_edge() • blocks execution until an edge is detected • GPIO.RISING, GPIO.FALLING or GPIO.BOTH GPIO.wait_for_edge(channel, GPIO.RISING) Building the Internet of Things with Raspberry Pi
  • 30. Inputs - event_detected() • Designed to be used in a loop with other things # add rising edge detection on a channel GPIO.add_event_detect(channel, GPIO.RISING) do_something() if GPIO.event_detected(channel): print('Button pressed') Building the Internet of Things with Raspberry Pi
  • 31. Inputs - Threaded callbacks • RPi.GPIO runs a second thread for callback functions GPIO.add_event_detect(channel, GPIO.RISING, callback=my_callback) Building the Internet of Things with Raspberry Pi
  • 32. Outputs - Setup import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(12, GPIO.OUT) Building the Internet of Things with Raspberry Pi
  • 33. Outputs #Set output to HIGH GPIO.output(12, GPIO.HIGH) #Set output to LOW GPIO.output(12, GPIO.LOW) #Read the state of the output GPIO.input(12) Building the Internet of Things with Raspberry Pi
  • 34. Example - Bell Building the Internet of Things with Raspberry Pi
  • 35. The Raspberry Pi Alarm Building the Internet of Things with Raspberry Pi
  • 36. On Github github.com/nbroers/hal Building the Internet of Things with Raspberry Pi
  • 37. What’s next? Building the Internet of Things with Raspberry Pi
  • 38. Questions? Building the Internet of Things with Raspberry Pi
  • 39. Parts list 12V input circuit: • Optocoupler: LTV-847 - http://www.mantech.co.za/ProductInfo.aspx?Item=340M0324 • Resistor: 1K Ohm - http://www.mantech.co.za/ProductInfo.aspx?Item=64M0009 Output circuit: • Resistor: 100k ohm • Resistor: 10k ohm • Transistor (NPN Transistor): P2N2222AG - http://www.mantech.co.za/ProductInfo.aspx?Item=72M3626 • Relay: EDR101A1200Z - http://www.mantech.co.za/ProductInfo.aspx?Item=35M1045 • Diode: 1N4007: http://www.mantech.co.za/ProductInfo.aspx?Item=64M0027 Extras: • 26pin IDC ribbon cable crimp connector - http://www.mantech.co.za/ProductInfo.aspx?Item=14M8762 • Ribbon cable - http://www.mantech.co.za/ProductInfo.aspx?Item=45M0001 • Single core cable • Veroboard - http://www.mantech.co.za/ProductInfo.aspx?Item=64M0010 Building the Internet of Things with Raspberry Pi
  • 40. References Input Circuit design: http://raspberrypihobbyist.blogspot.com/2012/09/gpio-input-circuit_19.html Output Circuit design: http://raspberrypihobbyist.blogspot.com/2012/10/revision-to-relay-circuit.html RPi.GPIO wiki http://sourceforge.net/p/raspberry-gpio-python/wiki/Home/ Raspberry Pi Technical Info http://elinux.org/RPi_Low-level_peripherals GPIO quick reference http://raspi.tv/2014/rpi-gpio-quick-reference-updated-for-raspberry-pi-b Exit Cleanly http://raspi.tv/2013/rpi-gpio-basics-3-how-to-exit-gpio-programs-cleanly-avoid-warnings-and-protect-your-pi Building the Internet of Things with Raspberry Pi
  • 41. Neil Broers @nbroers [email protected] github.com/nbroers Building the Internet of Things with Raspberry Pi