SlideShare una empresa de Scribd logo
1 de 67
Descargar para leer sin conexión
Getting Started with
Raspberry Pi
Tom Paulus
www.tompaulus.com
@tompaulus
Recommended
 Books
Hardware
Model B
Model A
Raspberry
 Pi
Text
“Take
 a
 bite!”
CPU
Broadcom ARM11
SoC
Broadcom ARM11
SoC
Clock
Speed
Up to 1GHz
ClockSpeed*
Up to 1GHz
ClockSpeed*
Memory 256 MB 512 MB
USB 1 USB Port 2 USB Ports
Network None Onboard Ethernet
Model
 BModel
 A
Arduino
 UNO
 
 :
 
 Arduino
 MEGA
 
 :
 
 
 Raspberry
 Pi
 
UNO MEGA DUE Pi Model A Pi Model B
Operating
Voltage
SRAM
FLASH-
Memory
Clock Speed
USB Host
Network
Audio /Video
Current I/O
pins
Digital I/O Pins
Analog Input
Pins
Price
5V 5V 3.3V 3.3V 3.3V
2 KB 8 KB 96 KB 265 MB 512 MB
32 KB 256 KB 512 KB up to 64 MB up to 64 MB
16 MHz 16 MHz 84 MHz 700 MHz* 700 MHz*
n/a n/a 1 1 2
n/a n/a n/a n/a
10/100 wired
Ethernet RJ45
n/a n/a n/a
HDMI, Composite
Video,
TRS-audio jack
HDMI, Composite
Video,
TRS-audio jack
40 mA 40 mA total 130 mA 2 to 16 mA 2 to 16 mA
14 (6 PWM) 54 (15 PWM) 54 (12 PWM) 17 (1 PWM) 17 (1 PWM)
6 16
12
2DAC Analog Out
0* 0*
$30 $59 $50 $25 $35
Initial Setup
http://www.raspberrypi.org/downloads
Recommended
 SD
 Cards
•Class
 4
 Minimum
•2
 GB
 or
 More
•Major
 Brands
 are
 Better!
Creating Your Image
1. Download and Unzip the .img from www.raspberrypi.com
2. Format the SD Card to clear all Data
Windows Users:
Use
Win32DiskImager
Mac Users:
Use
Raspberry PI SD Installer OS X
Demo
GPIO
sudo apt-get install python-dev python-pip
sudo easy_install -U distribute
sudo pip install RPi.GPIO
Preparing
 Python
Simple
 Blink
 App
from time import sleep
import RPi.GPIO as GPIO
 
GPIO.setmode(GPIO.BCM)
#use the common numeration,
#also the one found on the Adafruit Cobbler
 
led = 21                    # GPIO Port to which the LED is
connected
delay = .5
GPIO.setup(led, GPIO.OUT)   # Set 'led' as and Output
 
print Press CTRL+C to exit
 
try:
    while True:
        GPIO.output(led, True)   # led On
        sleep(delay)             # wait 'delay' seconds
        GPIO.output(led, False)  # led Off
        sleep(delay)             # wait another 'delay' seconds
 
except KeyboardInterrupt:
    GPIO.output(led, False)
 
finally:
    GPIO.cleanup()
blink.py
Hardware
Demo
Analogue
 Input
MCP3008 8-Channel 10-Bit ADC With SPI Interface
Ra!berryPi
wi ADC
SPI requires four signals:
clock (SCLK)
master output/slave input (MOSI)
master input/slave output (MISO)
slave select (SS) or (CS) chip-select
Ra!berryPi
Se#al Pe#pheral Interface Bus - SPI
pi@raspberrypi ~ $ cat /etc/modprobe.d/raspi-blacklist.conf
# blacklist spi and i2c by default (many users don't need them)
blacklist spi-bcm2708
blacklist i2c-bcm2708
Loading Kernel Modules:
Edit the raspi-blacklist.conf, so that the spi module gets loaded,
Reboot, and confirm with lsmod that ‘spidev’ and ‘spi_bcm2708’ are now loaded and
ls /dev/spi* shows two spi devices: /dev/spidev0.0 and /dev/spidev0.1
Installing Dependencies:
sudo apt-get install python-dev git-core
Install Python bindings for Linux SPI access through spidev:
cd ~
git clone git://github.com/doceme/py-spidev
cd py-spidev/
sudo python setup.py install
... which creates /usr/local/lib/python2.7/dist-packages/spidev.so
SPI
I2C
SPI
IN =[0000 0001][1CNL ----][---- ----]
(8+channel) 4
OUT=[---- ----][---- -XXX][XXXX XXXX] (10bit)
((r[1]  3)  8) + r[2]
IN =[0000 0001][1CNL ----][---- ----]
(8+channel) 4
OUT=[---- ----][---- -XXX][XXXX XXXX]
r[0] ((r[1]  3)  8) + r[2]
r = spi.xfer2( [1, (8+chnnl)4, 0] )
return ((r[1]  3)  8) + r[2]
def analogRead(port, bus=0, ce=0):
    Read the given ADC port and preform the necessary shifting of bits
    spi.open(bus, ce)      # CE port that the MCP3008 is connected to
    if (port  7) or (port  0):
        print 'analogRead -- Port Error, Must use a port between 0 and 7'
        return -1
    r = spi.xfer2([1, (8 + port)  4, 0])
    value = ((r[1]  3)  8) + r[2]
    spi.close()
    return value
import time
import spidev
import RPi.GPIO as GPIO
 
# This program reads an analogue value form a potentiometer attached to port 0 on the MCP3008 Chip
 
spi = spidev.SpiDev()
pot_adc = 0
statusLED = 23          # GPIO port that our Status led is connected to
 
GPIO.setmode(GPIO.BCM)
GPIO.setup(statusLED, GPIO.OUT)
 
print Press CTRL+C to exit
 
try:
    while True:
        GPIO.output(statusLED, True)   # Status Led On
        print analogRead(pot_adc)    # Print read value
        time.sleep(.125)               # Wait a little
        GPIO.output(statusLED, False)  # Status Led Off
        time.sleep(.175)               # Wait a bit longer
 
except KeyboardInterrupt:
    GPIO.output(statusLED, False)
 
finally:
    GPIO.cleanup()
ADC1.py
Hardware
But, That’s Just Ugly!
Let’s Add a Display

Más contenido relacionado

La actualidad más candente

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...ArabNet ME
 
Cassiopeia Ltd - standard Arduino workshop
Cassiopeia Ltd - standard Arduino workshopCassiopeia Ltd - standard Arduino workshop
Cassiopeia Ltd - standard Arduino workshoptomtobback
 
Rumba CNERT presentation
Rumba CNERT presentationRumba CNERT presentation
Rumba CNERT presentationARCFIRE ICT
 
Experiment write-vhdl-code-for-realize-all-logic-gates
Experiment write-vhdl-code-for-realize-all-logic-gatesExperiment write-vhdl-code-for-realize-all-logic-gates
Experiment write-vhdl-code-for-realize-all-logic-gatesRicardo Castro
 
Hackathon Taiwan 5th : Arduino 101
Hackathon Taiwan  5th : Arduino 101 Hackathon Taiwan  5th : Arduino 101
Hackathon Taiwan 5th : Arduino 101 twunishen
 
[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218CAVEDU Education
 
Digital System Design Lab Report - VHDL ECE
Digital System Design Lab Report - VHDL ECEDigital System Design Lab Report - VHDL ECE
Digital System Design Lab Report - VHDL ECERamesh Naik Bhukya
 
Integrare Arduino con Unity
Integrare Arduino con UnityIntegrare Arduino con Unity
Integrare Arduino con UnityCodemotion
 
Solution manual 8051 microcontroller by mazidi
Solution manual 8051 microcontroller by mazidiSolution manual 8051 microcontroller by mazidi
Solution manual 8051 microcontroller by mazidiMuhammad Abdullah
 
LED Blinking Using Raspberry Pi
LED Blinking Using Raspberry PiLED Blinking Using Raspberry Pi
LED Blinking Using Raspberry PiArjun R Krishna
 
Starting with Arduino
Starting with Arduino Starting with Arduino
Starting with Arduino MajdyShamasneh
 
Digital system design practical file
Digital system design practical fileDigital system design practical file
Digital system design practical fileArchita Misra
 
Micrcontroller iv sem lab manual
Micrcontroller iv sem lab manualMicrcontroller iv sem lab manual
Micrcontroller iv sem lab manualRohiniHM2
 
Ir remote kit_blink.pde
Ir remote kit_blink.pdeIr remote kit_blink.pde
Ir remote kit_blink.pdeCore Pale
 
Physical Computing with the Arduino platform and Ruby
Physical Computing with the Arduino platform and RubyPhysical Computing with the Arduino platform and Ruby
Physical Computing with the Arduino platform and Rubymdweezer
 

La actualidad más candente (20)

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...
 
Cassiopeia Ltd - standard Arduino workshop
Cassiopeia Ltd - standard Arduino workshopCassiopeia Ltd - standard Arduino workshop
Cassiopeia Ltd - standard Arduino workshop
 
Rumba CNERT presentation
Rumba CNERT presentationRumba CNERT presentation
Rumba CNERT presentation
 
Experiment write-vhdl-code-for-realize-all-logic-gates
Experiment write-vhdl-code-for-realize-all-logic-gatesExperiment write-vhdl-code-for-realize-all-logic-gates
Experiment write-vhdl-code-for-realize-all-logic-gates
 
Hackathon Taiwan 5th : Arduino 101
Hackathon Taiwan  5th : Arduino 101 Hackathon Taiwan  5th : Arduino 101
Hackathon Taiwan 5th : Arduino 101
 
Arduino Workshop 2011.05.31
Arduino Workshop 2011.05.31Arduino Workshop 2011.05.31
Arduino Workshop 2011.05.31
 
[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218
 
Programming arduino makeymakey
Programming arduino makeymakeyProgramming arduino makeymakey
Programming arduino makeymakey
 
8-bit Emulator Programming with Go
8-bit Emulator Programming with Go8-bit Emulator Programming with Go
8-bit Emulator Programming with Go
 
Digital System Design Lab Report - VHDL ECE
Digital System Design Lab Report - VHDL ECEDigital System Design Lab Report - VHDL ECE
Digital System Design Lab Report - VHDL ECE
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Integrare Arduino con Unity
Integrare Arduino con UnityIntegrare Arduino con Unity
Integrare Arduino con Unity
 
Solution manual 8051 microcontroller by mazidi
Solution manual 8051 microcontroller by mazidiSolution manual 8051 microcontroller by mazidi
Solution manual 8051 microcontroller by mazidi
 
Utft
UtftUtft
Utft
 
LED Blinking Using Raspberry Pi
LED Blinking Using Raspberry PiLED Blinking Using Raspberry Pi
LED Blinking Using Raspberry Pi
 
Starting with Arduino
Starting with Arduino Starting with Arduino
Starting with Arduino
 
Digital system design practical file
Digital system design practical fileDigital system design practical file
Digital system design practical file
 
Micrcontroller iv sem lab manual
Micrcontroller iv sem lab manualMicrcontroller iv sem lab manual
Micrcontroller iv sem lab manual
 
Ir remote kit_blink.pde
Ir remote kit_blink.pdeIr remote kit_blink.pde
Ir remote kit_blink.pde
 
Physical Computing with the Arduino platform and Ruby
Physical Computing with the Arduino platform and RubyPhysical Computing with the Arduino platform and Ruby
Physical Computing with the Arduino platform and Ruby
 

Destacado

Environmental Protection in China
Environmental Protection in ChinaEnvironmental Protection in China
Environmental Protection in ChinaStartup China
 
Search Marketing e User Experience per progetti ad alto ROI
Search Marketing e User Experience per progetti ad alto ROISearch Marketing e User Experience per progetti ad alto ROI
Search Marketing e User Experience per progetti ad alto ROINereo Sciutto
 
#NISMIL News Impact Milan: Online reputation for journalists
#NISMIL News Impact Milan: Online reputation for journalists#NISMIL News Impact Milan: Online reputation for journalists
#NISMIL News Impact Milan: Online reputation for journalistsBarbara Sgarzi
 
Nereo Sciutto Iab Seminar 2008 Misurazione
Nereo Sciutto Iab Seminar 2008 MisurazioneNereo Sciutto Iab Seminar 2008 Misurazione
Nereo Sciutto Iab Seminar 2008 MisurazioneNereo Sciutto
 
The State of Climate Change 2014
The State of Climate Change 2014The State of Climate Change 2014
The State of Climate Change 2014Mashable
 
An Introduction to Using ICT in RE
An Introduction to Using ICT in REAn Introduction to Using ICT in RE
An Introduction to Using ICT in RESusan Kambalu
 
Uno, nessuno e centomila: come rendere adattabile il contenuto ad una realtà ...
Uno, nessuno e centomila: come rendere adattabile il contenuto ad una realtà ...Uno, nessuno e centomila: come rendere adattabile il contenuto ad una realtà ...
Uno, nessuno e centomila: come rendere adattabile il contenuto ad una realtà ...Daniela Costantini
 
Fallire è un po' morire e un po' no
Fallire è un po' morire e un po' noFallire è un po' morire e un po' no
Fallire è un po' morire e un po' noMentine
 
Research and design methods hxd2013
Research and design methods hxd2013Research and design methods hxd2013
Research and design methods hxd2013Megan Grocki
 
James Tate - DMUG 2014
James Tate -  DMUG 2014James Tate -  DMUG 2014
James Tate - DMUG 2014IES / IAQM
 
Perché non facciamo più quello che ci piace - Italian Agile Day 2012
Perché non facciamo più quello che ci piace - Italian Agile Day 2012Perché non facciamo più quello che ci piace - Italian Agile Day 2012
Perché non facciamo più quello che ci piace - Italian Agile Day 2012Ilaria Mauric
 
Version Control Will Save Your (Product Design & UX) Life
Version Control Will Save Your (Product Design & UX) LifeVersion Control Will Save Your (Product Design & UX) Life
Version Control Will Save Your (Product Design & UX) LifeJonathan Berger
 
PEOPLE DON’T LOOK FOR IMPORTANT NEWS, IMPORTANT CONTENT LOOKS FOR PEOPLE
PEOPLE DON’T LOOK FOR IMPORTANT NEWS, IMPORTANT CONTENT LOOKS FOR PEOPLEPEOPLE DON’T LOOK FOR IMPORTANT NEWS, IMPORTANT CONTENT LOOKS FOR PEOPLE
PEOPLE DON’T LOOK FOR IMPORTANT NEWS, IMPORTANT CONTENT LOOKS FOR PEOPLELuca Della Dora
 
The State of Environmental Migration (2014: Review of 2013)
The State of Environmental Migration (2014: Review of 2013)The State of Environmental Migration (2014: Review of 2013)
The State of Environmental Migration (2014: Review of 2013)Graciela Mariani
 
I Non Che Aiutano A Crescere Corso Di Blog
I Non Che Aiutano A Crescere Corso Di BlogI Non Che Aiutano A Crescere Corso Di Blog
I Non Che Aiutano A Crescere Corso Di BlogGianluca Diegoli
 
Farm Management software for Fleet Management and GPS vehicle monitoring prov...
Farm Management software for Fleet Management and GPS vehicle monitoring prov...Farm Management software for Fleet Management and GPS vehicle monitoring prov...
Farm Management software for Fleet Management and GPS vehicle monitoring prov...victoryermak
 

Destacado (20)

The Real Cost of Offshoring
The Real Cost of OffshoringThe Real Cost of Offshoring
The Real Cost of Offshoring
 
Dirty 30 report_finale
Dirty 30 report_finaleDirty 30 report_finale
Dirty 30 report_finale
 
Environmental Protection in China
Environmental Protection in ChinaEnvironmental Protection in China
Environmental Protection in China
 
Search Marketing e User Experience per progetti ad alto ROI
Search Marketing e User Experience per progetti ad alto ROISearch Marketing e User Experience per progetti ad alto ROI
Search Marketing e User Experience per progetti ad alto ROI
 
#NISMIL News Impact Milan: Online reputation for journalists
#NISMIL News Impact Milan: Online reputation for journalists#NISMIL News Impact Milan: Online reputation for journalists
#NISMIL News Impact Milan: Online reputation for journalists
 
Nereo Sciutto Iab Seminar 2008 Misurazione
Nereo Sciutto Iab Seminar 2008 MisurazioneNereo Sciutto Iab Seminar 2008 Misurazione
Nereo Sciutto Iab Seminar 2008 Misurazione
 
I periodici online
I periodici onlineI periodici online
I periodici online
 
Euklid (1)
Euklid (1)Euklid (1)
Euklid (1)
 
The State of Climate Change 2014
The State of Climate Change 2014The State of Climate Change 2014
The State of Climate Change 2014
 
An Introduction to Using ICT in RE
An Introduction to Using ICT in REAn Introduction to Using ICT in RE
An Introduction to Using ICT in RE
 
Uno, nessuno e centomila: come rendere adattabile il contenuto ad una realtà ...
Uno, nessuno e centomila: come rendere adattabile il contenuto ad una realtà ...Uno, nessuno e centomila: come rendere adattabile il contenuto ad una realtà ...
Uno, nessuno e centomila: come rendere adattabile il contenuto ad una realtà ...
 
Fallire è un po' morire e un po' no
Fallire è un po' morire e un po' noFallire è un po' morire e un po' no
Fallire è un po' morire e un po' no
 
Research and design methods hxd2013
Research and design methods hxd2013Research and design methods hxd2013
Research and design methods hxd2013
 
James Tate - DMUG 2014
James Tate -  DMUG 2014James Tate -  DMUG 2014
James Tate - DMUG 2014
 
Perché non facciamo più quello che ci piace - Italian Agile Day 2012
Perché non facciamo più quello che ci piace - Italian Agile Day 2012Perché non facciamo più quello che ci piace - Italian Agile Day 2012
Perché non facciamo più quello che ci piace - Italian Agile Day 2012
 
Version Control Will Save Your (Product Design & UX) Life
Version Control Will Save Your (Product Design & UX) LifeVersion Control Will Save Your (Product Design & UX) Life
Version Control Will Save Your (Product Design & UX) Life
 
PEOPLE DON’T LOOK FOR IMPORTANT NEWS, IMPORTANT CONTENT LOOKS FOR PEOPLE
PEOPLE DON’T LOOK FOR IMPORTANT NEWS, IMPORTANT CONTENT LOOKS FOR PEOPLEPEOPLE DON’T LOOK FOR IMPORTANT NEWS, IMPORTANT CONTENT LOOKS FOR PEOPLE
PEOPLE DON’T LOOK FOR IMPORTANT NEWS, IMPORTANT CONTENT LOOKS FOR PEOPLE
 
The State of Environmental Migration (2014: Review of 2013)
The State of Environmental Migration (2014: Review of 2013)The State of Environmental Migration (2014: Review of 2013)
The State of Environmental Migration (2014: Review of 2013)
 
I Non Che Aiutano A Crescere Corso Di Blog
I Non Che Aiutano A Crescere Corso Di BlogI Non Che Aiutano A Crescere Corso Di Blog
I Non Che Aiutano A Crescere Corso Di Blog
 
Farm Management software for Fleet Management and GPS vehicle monitoring prov...
Farm Management software for Fleet Management and GPS vehicle monitoring prov...Farm Management software for Fleet Management and GPS vehicle monitoring prov...
Farm Management software for Fleet Management and GPS vehicle monitoring prov...
 

Similar a Getting Started With Raspberry Pi - UCSD 2013

Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1Tom Paulus
 
Python-in-Embedded-systems.pptx
Python-in-Embedded-systems.pptxPython-in-Embedded-systems.pptx
Python-in-Embedded-systems.pptxTuynLCh
 
01_DIGITAL IO.pptx
01_DIGITAL IO.pptx01_DIGITAL IO.pptx
01_DIGITAL IO.pptxssuser593a2d
 
Arduino workshop
Arduino workshopArduino workshop
Arduino workshopmayur1432
 
Scottish Ruby Conference 2010 Arduino, Ruby RAD
Scottish Ruby Conference 2010 Arduino, Ruby RADScottish Ruby Conference 2010 Arduino, Ruby RAD
Scottish Ruby Conference 2010 Arduino, Ruby RADlostcaggy
 
Magnetic door lock using arduino
Magnetic door lock using arduinoMagnetic door lock using arduino
Magnetic door lock using arduinoSravanthi Sinha
 
Raspberry Pi I/O控制與感測器讀取
Raspberry Pi I/O控制與感測器讀取Raspberry Pi I/O控制與感測器讀取
Raspberry Pi I/O控制與感測器讀取艾鍗科技
 
20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Jorisimec.archive
 
Using ARM Dev.Board in physical experimental instruments
Using ARM Dev.Board in physical experimental instrumentsUsing ARM Dev.Board in physical experimental instruments
Using ARM Dev.Board in physical experimental instrumentsa_n0v
 
Arduino 8-step drum sequencer 3 channels
Arduino 8-step drum sequencer 3 channelsArduino 8-step drum sequencer 3 channels
Arduino 8-step drum sequencer 3 channelstomtobback
 
Linux+sensor+device-tree+shell=IoT !
Linux+sensor+device-tree+shell=IoT !Linux+sensor+device-tree+shell=IoT !
Linux+sensor+device-tree+shell=IoT !Dobrica Pavlinušić
 
Introducing the Arduino
Introducing the ArduinoIntroducing the Arduino
Introducing the ArduinoCharles A B Jr
 
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
 
Intel galileo gen 2
Intel galileo gen 2Intel galileo gen 2
Intel galileo gen 2srknec
 

Similar a Getting Started With Raspberry Pi - UCSD 2013 (20)

Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1
 
Python-in-Embedded-systems.pptx
Python-in-Embedded-systems.pptxPython-in-Embedded-systems.pptx
Python-in-Embedded-systems.pptx
 
01_DIGITAL IO.pptx
01_DIGITAL IO.pptx01_DIGITAL IO.pptx
01_DIGITAL IO.pptx
 
Arduino workshop
Arduino workshopArduino workshop
Arduino workshop
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Raspberry pi led blink
Raspberry pi led blinkRaspberry pi led blink
Raspberry pi led blink
 
Scottish Ruby Conference 2010 Arduino, Ruby RAD
Scottish Ruby Conference 2010 Arduino, Ruby RADScottish Ruby Conference 2010 Arduino, Ruby RAD
Scottish Ruby Conference 2010 Arduino, Ruby RAD
 
How to use an Arduino
How to use an ArduinoHow to use an Arduino
How to use an Arduino
 
Magnetic door lock using arduino
Magnetic door lock using arduinoMagnetic door lock using arduino
Magnetic door lock using arduino
 
Raspberry Pi I/O控制與感測器讀取
Raspberry Pi I/O控制與感測器讀取Raspberry Pi I/O控制與感測器讀取
Raspberry Pi I/O控制與感測器讀取
 
20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris
 
Using ARM Dev.Board in physical experimental instruments
Using ARM Dev.Board in physical experimental instrumentsUsing ARM Dev.Board in physical experimental instruments
Using ARM Dev.Board in physical experimental instruments
 
Arduino 8-step drum sequencer 3 channels
Arduino 8-step drum sequencer 3 channelsArduino 8-step drum sequencer 3 channels
Arduino 8-step drum sequencer 3 channels
 
Linux+sensor+device-tree+shell=IoT !
Linux+sensor+device-tree+shell=IoT !Linux+sensor+device-tree+shell=IoT !
Linux+sensor+device-tree+shell=IoT !
 
Introducing the Arduino
Introducing the ArduinoIntroducing the Arduino
Introducing the Arduino
 
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
 
Em s7 plc
Em s7 plcEm s7 plc
Em s7 plc
 
Arduino Programming Basic
Arduino Programming BasicArduino Programming Basic
Arduino Programming Basic
 
Intel galileo gen 2
Intel galileo gen 2Intel galileo gen 2
Intel galileo gen 2
 

Último

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 2024The Digital Insurer
 
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 StreamsRoshan Dwivedi
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
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...Neo4j
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Último (20)

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
 
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
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
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...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

Getting Started With Raspberry Pi - UCSD 2013

  • 1. Getting Started with Raspberry Pi Tom Paulus www.tompaulus.com @tompaulus
  • 9.  a
  • 10.  bite!” CPU Broadcom ARM11 SoC Broadcom ARM11 SoC Clock Speed Up to 1GHz ClockSpeed* Up to 1GHz ClockSpeed* Memory 256 MB 512 MB USB 1 USB Port 2 USB Ports Network None Onboard Ethernet Model
  • 12.  A
  • 13.
  • 15.  UNO
  • 16.  
  • 17.  :
  • 18.  
  • 21.  
  • 22.  :
  • 23.  
  • 24.  
  • 26.  Pi
  • 27.  
  • 28. UNO MEGA DUE Pi Model A Pi Model B Operating Voltage SRAM FLASH- Memory Clock Speed USB Host Network Audio /Video Current I/O pins Digital I/O Pins Analog Input Pins Price 5V 5V 3.3V 3.3V 3.3V 2 KB 8 KB 96 KB 265 MB 512 MB 32 KB 256 KB 512 KB up to 64 MB up to 64 MB 16 MHz 16 MHz 84 MHz 700 MHz* 700 MHz* n/a n/a 1 1 2 n/a n/a n/a n/a 10/100 wired Ethernet RJ45 n/a n/a n/a HDMI, Composite Video, TRS-audio jack HDMI, Composite Video, TRS-audio jack 40 mA 40 mA total 130 mA 2 to 16 mA 2 to 16 mA 14 (6 PWM) 54 (15 PWM) 54 (12 PWM) 17 (1 PWM) 17 (1 PWM) 6 16 12 2DAC Analog Out 0* 0* $30 $59 $50 $25 $35
  • 32.  SD
  • 34.  4
  • 36.  GB
  • 37.  or
  • 40.  are
  • 42. Creating Your Image 1. Download and Unzip the .img from www.raspberrypi.com 2. Format the SD Card to clear all Data Windows Users: Use Win32DiskImager Mac Users: Use Raspberry PI SD Installer OS X
  • 43.
  • 44. Demo
  • 45. GPIO
  • 46.
  • 47. sudo apt-get install python-dev python-pip sudo easy_install -U distribute sudo pip install RPi.GPIO Preparing
  • 51.  App
  • 52. from time import sleep import RPi.GPIO as GPIO   GPIO.setmode(GPIO.BCM) #use the common numeration, #also the one found on the Adafruit Cobbler   led = 21                    # GPIO Port to which the LED is connected delay = .5 GPIO.setup(led, GPIO.OUT)   # Set 'led' as and Output   print Press CTRL+C to exit   try:     while True:         GPIO.output(led, True)   # led On         sleep(delay)             # wait 'delay' seconds         GPIO.output(led, False)  # led Off         sleep(delay)             # wait another 'delay' seconds   except KeyboardInterrupt:     GPIO.output(led, False)   finally:     GPIO.cleanup() blink.py
  • 54. Demo
  • 57. MCP3008 8-Channel 10-Bit ADC With SPI Interface Ra!berryPi wi ADC
  • 58. SPI requires four signals: clock (SCLK) master output/slave input (MOSI) master input/slave output (MISO) slave select (SS) or (CS) chip-select Ra!berryPi Se#al Pe#pheral Interface Bus - SPI
  • 59. pi@raspberrypi ~ $ cat /etc/modprobe.d/raspi-blacklist.conf # blacklist spi and i2c by default (many users don't need them) blacklist spi-bcm2708 blacklist i2c-bcm2708 Loading Kernel Modules: Edit the raspi-blacklist.conf, so that the spi module gets loaded, Reboot, and confirm with lsmod that ‘spidev’ and ‘spi_bcm2708’ are now loaded and ls /dev/spi* shows two spi devices: /dev/spidev0.0 and /dev/spidev0.1 Installing Dependencies: sudo apt-get install python-dev git-core Install Python bindings for Linux SPI access through spidev: cd ~ git clone git://github.com/doceme/py-spidev cd py-spidev/ sudo python setup.py install ... which creates /usr/local/lib/python2.7/dist-packages/spidev.so SPI
  • 61. IN =[0000 0001][1CNL ----][---- ----] (8+channel) 4 OUT=[---- ----][---- -XXX][XXXX XXXX] (10bit) ((r[1] 3) 8) + r[2]
  • 62. IN =[0000 0001][1CNL ----][---- ----] (8+channel) 4 OUT=[---- ----][---- -XXX][XXXX XXXX] r[0] ((r[1] 3) 8) + r[2] r = spi.xfer2( [1, (8+chnnl)4, 0] ) return ((r[1] 3) 8) + r[2]
  • 63. def analogRead(port, bus=0, ce=0):     Read the given ADC port and preform the necessary shifting of bits     spi.open(bus, ce)      # CE port that the MCP3008 is connected to     if (port 7) or (port 0):         print 'analogRead -- Port Error, Must use a port between 0 and 7'         return -1     r = spi.xfer2([1, (8 + port) 4, 0])     value = ((r[1] 3) 8) + r[2]     spi.close()     return value
  • 64. import time import spidev import RPi.GPIO as GPIO   # This program reads an analogue value form a potentiometer attached to port 0 on the MCP3008 Chip   spi = spidev.SpiDev() pot_adc = 0 statusLED = 23          # GPIO port that our Status led is connected to   GPIO.setmode(GPIO.BCM) GPIO.setup(statusLED, GPIO.OUT)   print Press CTRL+C to exit   try:     while True:         GPIO.output(statusLED, True)   # Status Led On         print analogRead(pot_adc)    # Print read value         time.sleep(.125)               # Wait a little         GPIO.output(statusLED, False)  # Status Led Off         time.sleep(.175)               # Wait a bit longer   except KeyboardInterrupt:     GPIO.output(statusLED, False)   finally:     GPIO.cleanup() ADC1.py
  • 67. Let’s Add a Display
  • 68. I2C connects the same two signal lines to all slaves. I.e. addressing is required and all devices need a unique address SDA - Serial Data SCL - Serial Clock Ra!berryPi Inter-IC Bus - I2C
  • 69. pi@raspberrypi ~ $ cat /etc/modprobe.d/raspi-blacklist.conf # blacklist spi and i2c by default (many users don't need them) blacklist spi-bcm2708 blacklist i2c-bcm2708 Loading Kernel Modules: - Edit the raspi-blacklist.conf, so that the i2c module gets enabled. - Add the following lines to /etc/modules  i2c-dev i2c-bcm2708 Reboot, and confirm ls /dev/i2c* shows /dev/i2c-0 /dev/i2c-1 Installing Dependencies: sudo apt-get install python-smbus i2c-tools With i2c devices connected, run somthing like this, to discover devices addresses. sudo i2cdetect -y 0 I2C
  • 71. import time import spidev import RPi.GPIO as GPIO from lib.Char_Plate.Adafruit_CharLCDPlate import Adafruit_CharLCDPlate import smbus   GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) lcd = Adafruit_CharLCDPlate() spi = spidev.SpiDev() pot_adc = 0         # ADC l = list()          # List for Light Sensor Averaging statusLED = 23 print Press CTRL+Z to exit GPIO.setup(statusLED, GPIO.OUT) lcd.backlight(lcd.ON) lcd.clear() def movavg(list, length, value):     A function that smooths the results by averaging a list     list.append(value)     if length len(list):         del list[0]     sum = 0     for x in list[:]:         sum += x     return sum / len(list) ADC2.py
  • 72. try:     while True:         # Change the Back-light based on what button has been pressed         if lcd.buttonPressed(lcd.DOWN):             lcd.backlight(lcd.ON)         if lcd.buttonPressed(lcd.UP):             lcd.backlight(lcd.OFF)         lcd.home()                                                           GPIO.output(statusLED, True)                                # Status Led On         lcd.message('Potentiometer:n' + str(             movavg(l, 4, analogRead(pot_adc))) + '     ')           # Read analog value         sleep(.1)                                                   # Wait a little         GPIO.output(statusLED, False)                               # Status Led off         sleep(.155)                                                 # Wait a bit longer   except KeyboardInterrupt:     GPIO.output(statusLED, False)     spi.close()   finally:     lcd.clear()     lcd.backlight(lcd.OFF)     GPIO.cleanup() ADC2.py
  • 74. ADC3.py def colorChange(channel):     global color     if channel == green:         if color == lcd.ON:             color = lcd.GREEN         elif color == lcd.GREEN:             color = lcd.OFF         else:             color = lcd.ON     for i in range(3):         lcd.backlight(color)         sleep(.01)     sleep(bounce/1000)
  • 75. try:     GPIO.add_event_detect(green, GPIO.RISING, callback=colorChange, bouncetime=bounce)       while True:         GPIO.output(statusLED, True)                                # Status Led On         l = movavg(light_Average, 4, analogRead(light_adc))         # Read the light sensor         lcd.home()                                                          lcd.message('Pot: ' + str(analogRead(pot_adc)) + '         nLight: ' + str(l) + '       ')           GPIO.output(statusLED, False)                               # Status Led Off         sleep(rate)                                                 # Wait a little   except KeyboardInterrupt:     GPIO.output(statusLED, False)     spi.close()   finally:     lcd.clear()     lcd.backlight(lcd.OFF)     GPIO.cleanup() ADC3.py
  • 77. Demo
  • 78. Why? try:         # Main Program   except KeyboardInterrupt:         # On Interrupt   finally:         GPIO.cleanup()
  • 79. Somewhere, there is an Arduino laughing... Current I/O pins Digital I/O Pins Analog Input Pins Price 40 mA 14 (6 PWM) 6 $30
  • 80. Using
  • 83. JSON
  • 86.  Notation??? JSON?? { firstName: John, lastName: Smith, age: 25, address: { streetAddress: 21 2nd Street, city: New York, state: NY, postalCode: 10021 }, phoneNumber: [ { type: home, number: 212 555-1234 }, { type: fax, number: 646 555-4567 } ] }
  • 87. JSON
  • 89.  JASON { firstName: John, lastName: Smith, age: 25, address: { streetAddress: 21 2nd Street, city: New York, state: NY, postalCode: 10021 }, phoneNumber: [ { type: home, number: 212 555-1234 }, { type: fax, number: 646 555-4567 } ] }
  • 90.
  • 91. What
  • 93.  is
  • 94.  it
  • 95.  in
  • 97. #! /usr/bin/python #Written By Tom Paulus, @tompaulus, www.tompaulus.com   import requests import time   timeURL = 'http://json-time.appspot.com/time.json?tz=' zone = 'America/Los_Angeles'   while True:     timeJson = requests.get(timeURL + zone).json()     hour = timeJson['hour']     minute = timeJson['minute']     second = timeJson['second']     dateTime = timeJson['datetime']     print str(hour) + ':' + str(minute) + ':' + str(second)     print dateTime     time.sleep(1) time.py
  • 98.
  • 100.  the
  • 101.  Data
  • 103. while True:       if update:         lcd.clear()         lcd.message('Please WaitnFetching Data')         json = API.getLocation(locations.get(str(location) + 's'), locations.get(str(location) + 'c'), token)         update = False         display = 0       if display == 0:         lcd.clear()         high = API.high(json, units_Temp)         low = API.low(json, units_Temp)         windSpeed = API.windSpeed(json, units_Speed)         windDir = API.winDir(json)         string1 = API.Display1(high, low, windSpeed, units_Speed, windDir, language)         lcd.message(string1)       if display == 1:         lcd.clear()         rain = API.rain(json)         humidity = API.humidity(json)         string2 = API.Display2(rain, humidity, language)         lcd.message(string2)       if display == 2:         lcd.clear()         lcd.message('More DatanComing Soon!') Main.py
  • 104. class WebAPI:      def getLocation(self, state, city, token):         d = requests.get(             'http://api.wunderground.com/api/' + str(token) + '/forecast/q/' + str(state) + '/' + str(city) +'.json')         json = d.json()         return json       def high(self, json, units):         high = str(json['forecast']['simpleforecast']['forecastday'][0]['high'][units])         return high       def low(self, json, units):         low = str(json['forecast']['simpleforecast']['forecastday'][0]['low'][units])         return low       def windSpeed(self, json, units):         windSpeed = str(json['forecast']['simpleforecast']['forecastday'][0]['avewind'][units])         return windSpeed       def winDir(self, json):         windDir = str(json['forecast']['simpleforecast']['forecastday'][0]['avewind']['dir'])         return windDir WUndergroundAPI.py
  • 105. USER Data!! NSA I have some data for you...
  • 106. User Data... Main.py app_info_folder = '/etc/WeatherUnderground' LocationData = app_info_folder + '/locations.conf' try:     info = open(LocationData)     data = info.readlines()     length = int(str(data).count(',')) + 1     l1 = data[0].split(',')     for x in range(0, length):         l2 = l1[x].split(':')         locations[str(x) + 's'] = l2[0]         locations[str(x) + 'c'] = l2[1]     info.close()   except IOError:     lcd.message('WelcomenNew User!')     print 'Adding New Location...'     State = raw_input('Enter The name of the State your desired location is in, using the abbreviation -CAn')     City = raw_input('Now, Enter the name of the Cityn')     print 'nThank You!'     State = State.upper()     City = City.capitalize()     if not os.path.exists(app_info_folder):         os.makedirs(app_info_folder)     info = open(LocationData, 'w')     info.write(State + ':' + City)     locations = {'0' + 's': State, '0' + 'c': City}     info.close()
  • 107. User Data... AddLocation.py app_info_folder = '/etc/WeatherUnderground' LocationData = app_info_folder + '/locations.conf' info = open(data)         State = raw_input('Enter The name of the State your desired location is in, using the abbreviation -CAn')         City = raw_input('Now, Enter the name of the Cityn')         print 'nThank You!'         State = State.upper()         City = City.replace(' ','_')         if raw_input(Is this Information Correct? Type 'y'n) == 'y':             info = open(data, 'a')             info.write(',' + State + ':' + City)             info.close()
  • 108. Demo
  • 109. Summary Wow! We have learned a lot!! 1. Initial Setup of the Raspberry Pi 2. Made a little LED blink 3. Dealt with an AnalogValue and Displayed it 4.The Basics of JSON 5. Got our feet wet by finding the Time in different places 6. Used our new Knowledge to find the Weather 7. Learned how to save Custom User Data
  • 110.
  • 111.
  • 112. Slides: Code Used in this Talk: http://tompaulus.com/talks https://github.com/tpaulus/SCC-SD2013 Email: tom@tompaulus.com