SlideShare ist ein Scribd-Unternehmen logo
1 von 25
Python in Raspberry Pi
Sudar Muthu (@sudarmuthu)
http://github.com/sudar
http://hardwarefun.com
I love Python ;)
Credit Card Sized
Computer
Basic Electronics
http://en.wikipedia.org/wiki/File:OhmsLaw.svg
GPIO Pins
http://learn.adafruit.com/assets/3052
Setup Python
sudo apt-get install python-dev
sudo apt-get install python-rpi.gpio
Set the status of GPIO Pins
https://github.com/sudar/raspberry-pi-sketches/blob/master/led-blink/led-blink.py
Set the status of GPIO Pins
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)
try:
while True:
GPIO.output(12, GPIO.HIGH)
time.sleep(1)
GPIO.output(12, GPIO.LOW)
time.sleep(1)
finally:
GPIO.cleanup()
https://github.com/sudar/raspberry-pi-sketches/blob/master/led-blink/led-blink.py
Demo
Let there be Light
https://github.com/sudar/raspberry-pi-sketches/blob/master/led-blink/led-blink.py
Changing the brightness of the LED
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)
p = GPIO.PWM(12, 50) # channel=12 frequency=50Hz
p.start(0)
try:
while True:
for dc in range(0, 101, 5):
p.ChangeDutyCycle(dc)
time.sleep(0.1)
for dc in range(100, -1, -5):
p.ChangeDutyCycle(dc)
time.sleep(0.1)
finally:
p.stop()
GPIO.cleanup()
https://github.com/sudar/raspberry-pi-sketches/blob/master/led-blink/pwm.py
Demo
Can you see the brightness changing?
https://github.com/sudar/raspberry-pi-sketches/blob/master/led-blink/pwm.py
Reading the status of the Pin
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
try:
while True:
if GPIO.input(11):
print "Button is on"
else:
print "Button is off"
time.sleep(0.1)
finally:
GPIO.cleanup()
https://github.com/sudar/raspberry-pi-sketches/blob/master/button-input/button-input.py
Reading the status of the Pin
https://github.com/sudar/raspberry-pi-sketches/blob/master/button-input/button-input.py
Demo
What happens when the button is pressed?
https://github.com/sudar/raspberry-pi-sketches/blob/master/button-input/button-input.py
Combining Input and Output
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(12, GPIO.OUT)
try:
while True:
if GPIO.input(11):
print "Button is on"
GPIO.output(12, 1)
else:
GPIO.output(12, 0)
time.sleep(0.1)
finally:
GPIO.cleanup()
https://github.com/sudar/raspberry-pi-sketches/blob/master/button-and-led/button-and-led.py
Combining Input and Output
https://github.com/sudar/raspberry-pi-sketches/blob/master/button-and-led/button-and-led.py
Demo
Let’s control the LED by pressing the button
https://github.com/sudar/raspberry-pi-sketches/blob/master/button-and-led/button-and-led.py
What more can be done?
More protocols
• I2C
• SPI
• Serial
Interacting with webcam
• “PyGame” provides easy interface
• Can get fancy using “opencv”
• Both USB and GPIO interface are supported
Distributed Computing
• Each Pi can be used as cheap node
• Form grids using a cluster of Pi’s
• Can share CPU, memory and disk space
http://www.cl.cam.ac.uk/projects/raspberrypi/t
utorials/distributed-computing/
Limitations
• No built-in Analog to Digital support
• Can’t run Inductive load (motors)
• Is not real-time (CPU might be busy)
• No “safe circuits” present
• Operates at 3.3V and is not directly
compatible with Arduino voltage
Best of two worlds
http://learn.adafruit.com/assets/3199 http://learn.adafruit.com/assets/2123
Links
• Source code -
https://github.com/sudar/raspberry-pi-sketches/
• My blog - http://hardwarefun.com
• Python GPIO -
https://code.google.com/p/raspberry-gpio-
python/
• Distributed computing using Pi -
http://www.cl.cam.ac.uk/projects/raspberrypi/tu
torials/distributed-computing/
Thank you
Sudar Muthu
http://hardwarefun.com

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (19)

Prototipare col raspberry pi
Prototipare col raspberry piPrototipare col raspberry pi
Prototipare col raspberry pi
 
Raspberry Pi and Amateur Radio
Raspberry Pi and Amateur RadioRaspberry Pi and Amateur Radio
Raspberry Pi and Amateur Radio
 
Raspberry Pi and Amateur Radio - 2020 update
Raspberry Pi and Amateur Radio - 2020 updateRaspberry Pi and Amateur Radio - 2020 update
Raspberry Pi and Amateur Radio - 2020 update
 
Single Board Computers & Raspberry Pi Basics
Single Board Computers & Raspberry Pi BasicsSingle Board Computers & Raspberry Pi Basics
Single Board Computers & Raspberry Pi Basics
 
Interfacing the Raspberry Pi to the World
Interfacing the Raspberry Pi to the WorldInterfacing the Raspberry Pi to the World
Interfacing the Raspberry Pi to the World
 
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
 
Meng
MengMeng
Meng
 
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
 
Introduction to Raspberry Pi and GPIO
Introduction to Raspberry Pi and GPIOIntroduction to Raspberry Pi and GPIO
Introduction to Raspberry Pi and GPIO
 
Getting Started with Raspberry Pi and Arduino
Getting Started with Raspberry Pi and ArduinoGetting Started with Raspberry Pi and Arduino
Getting Started with Raspberry Pi and Arduino
 
IOT Talking to Webserver - how to
IOT Talking to Webserver - how to IOT Talking to Webserver - how to
IOT Talking to Webserver - how to
 
Micropython on MicroControllers
Micropython on MicroControllersMicropython on MicroControllers
Micropython on MicroControllers
 
Getting Started with MicroPython and LoPy
Getting Started with MicroPython and LoPyGetting Started with MicroPython and LoPy
Getting Started with MicroPython and LoPy
 
DigiPinguïns: demo Raspberry Pi (Koen De Smet)
DigiPinguïns: demo Raspberry Pi (Koen De Smet)DigiPinguïns: demo Raspberry Pi (Koen De Smet)
DigiPinguïns: demo Raspberry Pi (Koen De Smet)
 
Micropython for the iot
Micropython for the iotMicropython for the iot
Micropython for the iot
 
Controlling the internet of things using wearable tech - Design+Code Day; Ara...
Controlling the internet of things using wearable tech - Design+Code Day; Ara...Controlling the internet of things using wearable tech - Design+Code Day; Ara...
Controlling the internet of things using wearable tech - Design+Code Day; Ara...
 
Rassberry pi
Rassberry piRassberry pi
Rassberry pi
 
Wi-Fi Modem For the Commodore 64
Wi-Fi Modem For the Commodore 64Wi-Fi Modem For the Commodore 64
Wi-Fi Modem For the Commodore 64
 
Security System with PIR sensor and Raspberry Pi
Security System with PIR sensor and Raspberry PiSecurity System with PIR sensor and Raspberry Pi
Security System with PIR sensor and Raspberry Pi
 

Andere mochten auch

20 C programs
20 C programs20 C programs
20 C programs
navjoth
 
C programs
C programsC programs
C programs
Minu S
 

Andere mochten auch (20)

Getting started with arduino workshop
Getting started with arduino workshopGetting started with arduino workshop
Getting started with arduino workshop
 
Raspberrypi best ppt
Raspberrypi best ppt Raspberrypi best ppt
Raspberrypi best ppt
 
Connect all your customers on one multichannel platform!
Connect all your customers on one multichannel platform!Connect all your customers on one multichannel platform!
Connect all your customers on one multichannel platform!
 
20 C programs
20 C programs20 C programs
20 C programs
 
Computer Logic
Computer LogicComputer Logic
Computer Logic
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
Conditional Loops Python
Conditional Loops PythonConditional Loops Python
Conditional Loops Python
 
Loops in c
Loops in cLoops in c
Loops in c
 
Cloud Computing to Internet of Things
Cloud Computing to Internet of ThingsCloud Computing to Internet of Things
Cloud Computing to Internet of Things
 
Socket Programming In Python
Socket Programming In PythonSocket Programming In Python
Socket Programming In Python
 
Got Python I/O: IoT Develoment in Python via GPIO
Got Python I/O: IoT Develoment in Python via GPIOGot Python I/O: IoT Develoment in Python via GPIO
Got Python I/O: IoT Develoment in Python via GPIO
 
CS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUALCS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUAL
 
Internet of Things for Libraries
Internet of Things for LibrariesInternet of Things for Libraries
Internet of Things for Libraries
 
Using arduino and raspberry pi for internet of things
Using arduino and raspberry pi for internet of thingsUsing arduino and raspberry pi for internet of things
Using arduino and raspberry pi for internet of things
 
C programs
C programsC programs
C programs
 
Multidimensional array in C
Multidimensional array in CMultidimensional array in C
Multidimensional array in C
 
Arduino Robotics workshop day2
Arduino Robotics workshop day2Arduino Robotics workshop day2
Arduino Robotics workshop day2
 
Mastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loopsMastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loops
 
Arduino Robotics workshop Day1
Arduino Robotics workshop Day1Arduino Robotics workshop Day1
Arduino Robotics workshop Day1
 
[Slides] Customer Experience in the Internet of Things by Altimeter Group
[Slides] Customer Experience in the Internet of Things by Altimeter Group[Slides] Customer Experience in the Internet of Things by Altimeter Group
[Slides] Customer Experience in the Internet of Things by Altimeter Group
 

Ähnlich wie Python in raspberry pi

Raspberry pi lcd-shield20x4
Raspberry pi lcd-shield20x4Raspberry pi lcd-shield20x4
Raspberry pi lcd-shield20x4
Iulius Bors
 

Ähnlich wie Python in raspberry pi (20)

manual_2020_Cyber Physical System.pdf
manual_2020_Cyber Physical System.pdfmanual_2020_Cyber Physical System.pdf
manual_2020_Cyber Physical System.pdf
 
Module Workshop NSC "Raspberry pi3 with Python" - Sanusi & Sasmitoh RR
Module Workshop NSC "Raspberry pi3 with Python" - Sanusi & Sasmitoh RRModule Workshop NSC "Raspberry pi3 with Python" - Sanusi & Sasmitoh RR
Module Workshop NSC "Raspberry pi3 with Python" - Sanusi & Sasmitoh RR
 
Hands on Raspberry Pi - Creative Technologists
Hands on Raspberry Pi - Creative TechnologistsHands on Raspberry Pi - Creative Technologists
Hands on Raspberry Pi - Creative Technologists
 
Startup Camp - Git, Python, Django session
Startup Camp - Git, Python, Django sessionStartup Camp - Git, Python, Django session
Startup Camp - Git, Python, Django session
 
AWS ロボを作ろう JAWSUG Kobe
AWS ロボを作ろう JAWSUG KobeAWS ロボを作ろう JAWSUG Kobe
AWS ロボを作ろう JAWSUG Kobe
 
Embedded Rust and more
Embedded Rust and moreEmbedded Rust and more
Embedded Rust and more
 
Raspberry pi lcd-shield20x4
Raspberry pi lcd-shield20x4Raspberry pi lcd-shield20x4
Raspberry pi lcd-shield20x4
 
Chromium Sandbox on Linux (BlackHoodie 2018)
Chromium Sandbox on Linux (BlackHoodie 2018)Chromium Sandbox on Linux (BlackHoodie 2018)
Chromium Sandbox on Linux (BlackHoodie 2018)
 
Princeton Wintersession: Software Quality Assurance Tooling
Princeton Wintersession: Software Quality Assurance ToolingPrinceton Wintersession: Software Quality Assurance Tooling
Princeton Wintersession: Software Quality Assurance Tooling
 
Swift hardware hacking @ try! Swift
Swift hardware hacking @ try! SwiftSwift hardware hacking @ try! Swift
Swift hardware hacking @ try! Swift
 
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
 
Hom Class
Hom ClassHom Class
Hom Class
 
Hom Class
Hom ClassHom Class
Hom Class
 
Hom Class
Hom ClassHom Class
Hom Class
 
Project ACRN GPIO mediator introduction
Project ACRN GPIO mediator introductionProject ACRN GPIO mediator introduction
Project ACRN GPIO mediator introduction
 
Meng
MengMeng
Meng
 
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
 
Linux Security APIs and the Chromium Sandbox
Linux Security APIs and the Chromium SandboxLinux Security APIs and the Chromium Sandbox
Linux Security APIs and the Chromium Sandbox
 
IOT in HEALTH CARE .pptx
IOT in HEALTH CARE .pptxIOT in HEALTH CARE .pptx
IOT in HEALTH CARE .pptx
 

Mehr von Sudar Muthu

Capabilities of Arduino (including Due)
Capabilities of Arduino (including Due)Capabilities of Arduino (including Due)
Capabilities of Arduino (including Due)
Sudar Muthu
 

Mehr von Sudar Muthu (20)

A quick preview of WP CLI - Chennai WordPress Meetup
A quick preview of WP CLI - Chennai WordPress MeetupA quick preview of WP CLI - Chennai WordPress Meetup
A quick preview of WP CLI - Chennai WordPress Meetup
 
WordPress Developer tools
WordPress Developer toolsWordPress Developer tools
WordPress Developer tools
 
WordPress Developer Tools to increase productivity
WordPress Developer Tools to increase productivityWordPress Developer Tools to increase productivity
WordPress Developer Tools to increase productivity
 
Unit testing for WordPress
Unit testing for WordPressUnit testing for WordPress
Unit testing for WordPress
 
Unit testing in php
Unit testing in phpUnit testing in php
Unit testing in php
 
How arduino helped me in life
How arduino helped me in lifeHow arduino helped me in life
How arduino helped me in life
 
Having fun with hardware
Having fun with hardwareHaving fun with hardware
Having fun with hardware
 
Hack 101 at IIT Kanpur
Hack 101 at IIT KanpurHack 101 at IIT Kanpur
Hack 101 at IIT Kanpur
 
PureCSS open hack 2013
PureCSS open hack 2013PureCSS open hack 2013
PureCSS open hack 2013
 
Pig workshop
Pig workshopPig workshop
Pig workshop
 
Hands on Hadoop and pig
Hands on Hadoop and pigHands on Hadoop and pig
Hands on Hadoop and pig
 
Lets make robots
Lets make robotsLets make robots
Lets make robots
 
Capabilities of Arduino (including Due)
Capabilities of Arduino (including Due)Capabilities of Arduino (including Due)
Capabilities of Arduino (including Due)
 
Controlling robots using javascript
Controlling robots using javascriptControlling robots using javascript
Controlling robots using javascript
 
Picture perfect hacks with flickr API
Picture perfect hacks with flickr APIPicture perfect hacks with flickr API
Picture perfect hacks with flickr API
 
Hacking 101
Hacking 101Hacking 101
Hacking 101
 
Capabilities of Arduino
Capabilities of ArduinoCapabilities of Arduino
Capabilities of Arduino
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDD
 
Using Javascript in today's world
Using Javascript in today's worldUsing Javascript in today's world
Using Javascript in today's world
 
Hack u yql-iit-delhi
Hack u yql-iit-delhiHack u yql-iit-delhi
Hack u yql-iit-delhi
 

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Kürzlich hochgeladen (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 

Python in raspberry pi

  • 1. Python in Raspberry Pi Sudar Muthu (@sudarmuthu) http://github.com/sudar http://hardwarefun.com
  • 6. Setup Python sudo apt-get install python-dev sudo apt-get install python-rpi.gpio
  • 7. Set the status of GPIO Pins https://github.com/sudar/raspberry-pi-sketches/blob/master/led-blink/led-blink.py
  • 8. Set the status of GPIO Pins import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) GPIO.setup(12, GPIO.OUT) try: while True: GPIO.output(12, GPIO.HIGH) time.sleep(1) GPIO.output(12, GPIO.LOW) time.sleep(1) finally: GPIO.cleanup() https://github.com/sudar/raspberry-pi-sketches/blob/master/led-blink/led-blink.py
  • 9. Demo Let there be Light https://github.com/sudar/raspberry-pi-sketches/blob/master/led-blink/led-blink.py
  • 10. Changing the brightness of the LED import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) GPIO.setup(12, GPIO.OUT) p = GPIO.PWM(12, 50) # channel=12 frequency=50Hz p.start(0) try: while True: for dc in range(0, 101, 5): p.ChangeDutyCycle(dc) time.sleep(0.1) for dc in range(100, -1, -5): p.ChangeDutyCycle(dc) time.sleep(0.1) finally: p.stop() GPIO.cleanup() https://github.com/sudar/raspberry-pi-sketches/blob/master/led-blink/pwm.py
  • 11. Demo Can you see the brightness changing? https://github.com/sudar/raspberry-pi-sketches/blob/master/led-blink/pwm.py
  • 12. Reading the status of the Pin import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) try: while True: if GPIO.input(11): print "Button is on" else: print "Button is off" time.sleep(0.1) finally: GPIO.cleanup() https://github.com/sudar/raspberry-pi-sketches/blob/master/button-input/button-input.py
  • 13. Reading the status of the Pin https://github.com/sudar/raspberry-pi-sketches/blob/master/button-input/button-input.py
  • 14. Demo What happens when the button is pressed? https://github.com/sudar/raspberry-pi-sketches/blob/master/button-input/button-input.py
  • 15. Combining Input and Output import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(12, GPIO.OUT) try: while True: if GPIO.input(11): print "Button is on" GPIO.output(12, 1) else: GPIO.output(12, 0) time.sleep(0.1) finally: GPIO.cleanup() https://github.com/sudar/raspberry-pi-sketches/blob/master/button-and-led/button-and-led.py
  • 16. Combining Input and Output https://github.com/sudar/raspberry-pi-sketches/blob/master/button-and-led/button-and-led.py
  • 17. Demo Let’s control the LED by pressing the button https://github.com/sudar/raspberry-pi-sketches/blob/master/button-and-led/button-and-led.py
  • 18. What more can be done?
  • 19. More protocols • I2C • SPI • Serial
  • 20. Interacting with webcam • “PyGame” provides easy interface • Can get fancy using “opencv” • Both USB and GPIO interface are supported
  • 21. Distributed Computing • Each Pi can be used as cheap node • Form grids using a cluster of Pi’s • Can share CPU, memory and disk space http://www.cl.cam.ac.uk/projects/raspberrypi/t utorials/distributed-computing/
  • 22. Limitations • No built-in Analog to Digital support • Can’t run Inductive load (motors) • Is not real-time (CPU might be busy) • No “safe circuits” present • Operates at 3.3V and is not directly compatible with Arduino voltage
  • 23. Best of two worlds http://learn.adafruit.com/assets/3199 http://learn.adafruit.com/assets/2123
  • 24. Links • Source code - https://github.com/sudar/raspberry-pi-sketches/ • My blog - http://hardwarefun.com • Python GPIO - https://code.google.com/p/raspberry-gpio- python/ • Distributed computing using Pi - http://www.cl.cam.ac.uk/projects/raspberrypi/tu torials/distributed-computing/