SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

Mais procurados (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
 

Destaque

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

Destaque (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
 

Semelhante a Python in raspberry pi

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

Semelhante a 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
 

Mais de Sudar Muthu

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

Mais de 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
 

Último

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
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
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
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
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 

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/