SlideShare una empresa de Scribd logo
1 de 66
Descargar para leer sin conexión
Getting Started with
Raspberry Pi
Tom Paulus
@tompaulus
www.tompaulus.com
Recommended
 Books
Hardware
Model B
Model A
Raspberry
 Pi
“Take
 a
 bite!”
Model
 A

Model
 B

Broadcom ARM11
SoC

Broadcom ARM11
SoC

ClockSpeed*

Up to 1GHz
ClockSpeed*

Memory

256 MB

512 MB

USB

1 USB Port

2 USB Ports

Network

None

Onboard Ethernet

CPU
Clock
Speed

Textto 1GHz
Up
Arduino
 UNO
 
 :
 
 Arduino
 MEGA
 
 :
 
 
 Raspberry
 Pi
 
UNO

MEGA

DUE

Pi Model A

Pi Model B

Operating
Voltage

5V

5V

3.3 V

3.3 V

3.3 V

SRAM

2 KB

8 KB

96 KB

265 MB

512 MB

FLASHMemory

32 KB

256 KB

512 KB

up to 64 MB

up to 64 MB

Clock Speed

16 MHz

16 MHz

84 MHz

700 MHz*

700 MHz*

USB Host

n/a

n/a

1

1

2

Network

n/a

n/a

n/a

n/a

10/100 wired
Ethernet RJ45
HDMI, Composite
Video, 	

TRS-audio jack

Audio / Video

n/a

n/a

n/a

HDMI, Composite
Video, 	

TRS-audio jack

Current I/O
pins

40 mA

40 mA

total 130 mA

2 to 16 mA

2 to 16 mA

54 (12 PWM)

17 (1 PWM)

17 (1 PWM)

Digital I/O Pins 14 (6 PWM) 54 (15 PWM)
Analog Input
Pins

6

16

12	

2DAC Analog Out

0*

0*

Price

$30

$59

$50

$25

$35
Initial Setup
Recommended
 SD
 Cards

•Class
 4
 Minimum
 
2
 GB
 or
 More
 
•
•Major
 Brands
 are
 Better!
http://www.raspberrypi.org/downloads
Install Your OS
1. Download and Unzip the .zip from www.raspberrypi.com	

2. Format the SD Card to clear all Data	

3. Drag  Drop the contents of the .zip onto the SD Card
Demo
GPIO
Preparing
 Python
sudo apt-get install python-dev python-pip
sudo easy_install -U distribute
sudo pip install RPi.GPIO
Simple
 Blink
 App
blink.py
!

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()
Hardware
Demo
Analogue
 Input
RaspberryPi 	

with ADC

MCP3008 8-Channel 10-Bit ADC With SPI Interface
RaspberryPi 	

Serial Peripheral Interface Bus - SPI

SPI requires four signals: 	

clock (SCLK)	

master output/slave input (MOSI)	

master input/slave output (MISO)	

slave select (SS) or (CS) chip-select
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]
r = spi.xfer2( [1, (8+chnnl)4, 0] )!
return ((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]
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
ADC1.py
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()

Más contenido relacionado

La actualidad más candente

Digital system design lab manual
Digital system design lab manualDigital system design lab manual
Digital system design lab manualSanthosh Poralu
 
Rumba CNERT presentation
Rumba CNERT presentationRumba CNERT presentation
Rumba CNERT presentationARCFIRE ICT
 
20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Jorisimec.archive
 
LED Blinking Using Raspberry Pi
LED Blinking Using Raspberry PiLED Blinking Using Raspberry Pi
LED Blinking Using Raspberry PiArjun R Krishna
 
OpenBSD/sgi SMP implementation for Origin 350
OpenBSD/sgi SMP implementation for Origin 350OpenBSD/sgi SMP implementation for Origin 350
OpenBSD/sgi SMP implementation for Origin 350Takuya ASADA
 
Cassiopeia Ltd - standard Arduino workshop
Cassiopeia Ltd - standard Arduino workshopCassiopeia Ltd - standard Arduino workshop
Cassiopeia Ltd - standard Arduino workshoptomtobback
 
Online test program generator for RISC-V processors
Online test program generator for RISC-V processorsOnline test program generator for RISC-V processors
Online test program generator for RISC-V processorsRISC-V International
 
Ir remote kit_blink.pde
Ir remote kit_blink.pdeIr remote kit_blink.pde
Ir remote kit_blink.pdeCore Pale
 
VHDL Practical Exam Guide
VHDL Practical Exam GuideVHDL Practical Exam Guide
VHDL Practical Exam GuideEslam Mohammed
 
[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218CAVEDU Education
 
Dsd lab Practical File
Dsd lab Practical FileDsd lab Practical File
Dsd lab Practical FileSoumya Behera
 
Track c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eveTrack c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -evechiportal
 
from Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Worksfrom Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu WorksZhen Wei
 
Fosscon 2012 firewall workshop
Fosscon 2012 firewall workshopFosscon 2012 firewall workshop
Fosscon 2012 firewall workshopjvehent
 
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이GangSeok Lee
 
SMP Implementation for OpenBSD/sgi [Japanese Edition]
SMP Implementation for OpenBSD/sgi [Japanese Edition]SMP Implementation for OpenBSD/sgi [Japanese Edition]
SMP Implementation for OpenBSD/sgi [Japanese Edition]Takuya ASADA
 
IOT Talking to Webserver - how to
IOT Talking to Webserver - how to IOT Talking to Webserver - how to
IOT Talking to Webserver - how to Indraneel Ganguli
 

La actualidad más candente (20)

Digital system design lab manual
Digital system design lab manualDigital system design lab manual
Digital system design lab manual
 
Rumba CNERT presentation
Rumba CNERT presentationRumba CNERT presentation
Rumba CNERT presentation
 
20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris
 
LED Blinking Using Raspberry Pi
LED Blinking Using Raspberry PiLED Blinking Using Raspberry Pi
LED Blinking Using Raspberry Pi
 
OpenBSD/sgi SMP implementation for Origin 350
OpenBSD/sgi SMP implementation for Origin 350OpenBSD/sgi SMP implementation for Origin 350
OpenBSD/sgi SMP implementation for Origin 350
 
Cassiopeia Ltd - standard Arduino workshop
Cassiopeia Ltd - standard Arduino workshopCassiopeia Ltd - standard Arduino workshop
Cassiopeia Ltd - standard Arduino workshop
 
Online test program generator for RISC-V processors
Online test program generator for RISC-V processorsOnline test program generator for RISC-V processors
Online test program generator for RISC-V processors
 
Ir remote kit_blink.pde
Ir remote kit_blink.pdeIr remote kit_blink.pde
Ir remote kit_blink.pde
 
VHDL Practical Exam Guide
VHDL Practical Exam GuideVHDL Practical Exam Guide
VHDL Practical Exam Guide
 
[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218
 
Dsd lab Practical File
Dsd lab Practical FileDsd lab Practical File
Dsd lab Practical File
 
Track c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eveTrack c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eve
 
from Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Worksfrom Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Works
 
Fosscon 2012 firewall workshop
Fosscon 2012 firewall workshopFosscon 2012 firewall workshop
Fosscon 2012 firewall workshop
 
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
 
SMP Implementation for OpenBSD/sgi [Japanese Edition]
SMP Implementation for OpenBSD/sgi [Japanese Edition]SMP Implementation for OpenBSD/sgi [Japanese Edition]
SMP Implementation for OpenBSD/sgi [Japanese Edition]
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Soc
SocSoc
Soc
 
IOT Talking to Webserver - how to
IOT Talking to Webserver - how to IOT Talking to Webserver - how to
IOT Talking to Webserver - how to
 
Remote tanklevelmonitor
Remote tanklevelmonitorRemote tanklevelmonitor
Remote tanklevelmonitor
 

Destacado

Yield mapping Combinable Crops, Potential & Problems, An initial Phd Seminar ...
Yield mapping Combinable Crops, Potential & Problems, An initial Phd Seminar ...Yield mapping Combinable Crops, Potential & Problems, An initial Phd Seminar ...
Yield mapping Combinable Crops, Potential & Problems, An initial Phd Seminar ...Akbar Sanaei, PhD
 
Soil & Landscape Mapping Technologies
Soil & Landscape Mapping TechnologiesSoil & Landscape Mapping Technologies
Soil & Landscape Mapping TechnologiesAmanda Woods
 
Drip irrigation handbook 2005
Drip irrigation handbook 2005Drip irrigation handbook 2005
Drip irrigation handbook 2005Ayman Morshedy
 
Agricultural robot
Agricultural robotAgricultural robot
Agricultural robotAleena Khan
 

Destacado (6)

Yield mapping Combinable Crops, Potential & Problems, An initial Phd Seminar ...
Yield mapping Combinable Crops, Potential & Problems, An initial Phd Seminar ...Yield mapping Combinable Crops, Potential & Problems, An initial Phd Seminar ...
Yield mapping Combinable Crops, Potential & Problems, An initial Phd Seminar ...
 
Soil & Landscape Mapping Technologies
Soil & Landscape Mapping TechnologiesSoil & Landscape Mapping Technologies
Soil & Landscape Mapping Technologies
 
drip irrigation
drip  irrigationdrip  irrigation
drip irrigation
 
Drip irrigation handbook 2005
Drip irrigation handbook 2005Drip irrigation handbook 2005
Drip irrigation handbook 2005
 
Drip irrigation
Drip irrigationDrip irrigation
Drip irrigation
 
Agricultural robot
Agricultural robotAgricultural robot
Agricultural robot
 

Similar a Getting Started with Raspberry Pi - USC 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
 
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ć
 
Arduino workshop
Arduino workshopArduino workshop
Arduino workshopmayur1432
 
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
 
Embedded system course projects - Arduino Course
Embedded system course projects - Arduino CourseEmbedded system course projects - Arduino Course
Embedded system course projects - Arduino CourseElaf A.Saeed
 
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
 
Interfacing two wire adc0831 to raspberry pi2 / Pi3
Interfacing two wire adc0831 to raspberry pi2 / Pi3Interfacing two wire adc0831 to raspberry pi2 / Pi3
Interfacing two wire adc0831 to raspberry pi2 / Pi3Dnyanesh Patil
 
Raspberry Pi I/O控制與感測器讀取
Raspberry Pi I/O控制與感測器讀取Raspberry Pi I/O控制與感測器讀取
Raspberry Pi I/O控制與感測器讀取艾鍗科技
 
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
 
Android Things Linux Day 2017
Android Things Linux Day 2017 Android Things Linux Day 2017
Android Things Linux Day 2017 Stefano Sanna
 
NodeMCU ESP8266 workshop 1
NodeMCU ESP8266 workshop 1NodeMCU ESP8266 workshop 1
NodeMCU ESP8266 workshop 1Andy Gelme
 

Similar a Getting Started with Raspberry Pi - USC 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
 
Em s7 plc
Em s7 plcEm s7 plc
Em s7 plc
 
Linux+sensor+device-tree+shell=IoT !
Linux+sensor+device-tree+shell=IoT !Linux+sensor+device-tree+shell=IoT !
Linux+sensor+device-tree+shell=IoT !
 
Arduino workshop
Arduino workshopArduino workshop
Arduino workshop
 
Arduino: Arduino lcd
Arduino: Arduino lcdArduino: Arduino lcd
Arduino: Arduino lcd
 
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
 
Embedded system course projects - Arduino Course
Embedded system course projects - Arduino CourseEmbedded system course projects - Arduino Course
Embedded system course projects - Arduino Course
 
How to use an Arduino
How to use an ArduinoHow to use an Arduino
How to use an Arduino
 
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
 
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
 
The PDP-10 - and me
The PDP-10 - and meThe PDP-10 - and me
The PDP-10 - and me
 
Pandaboard
PandaboardPandaboard
Pandaboard
 
Raspberry pi led blink
Raspberry pi led blinkRaspberry pi led blink
Raspberry pi led blink
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Raspberry Pi I/O控制與感測器讀取
Raspberry Pi I/O控制與感測器讀取Raspberry Pi I/O控制與感測器讀取
Raspberry Pi I/O控制與感測器讀取
 
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
 
Android Things Linux Day 2017
Android Things Linux Day 2017 Android Things Linux Day 2017
Android Things Linux Day 2017
 
NodeMCU ESP8266 workshop 1
NodeMCU ESP8266 workshop 1NodeMCU ESP8266 workshop 1
NodeMCU ESP8266 workshop 1
 

Último

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
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
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
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
 
[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
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
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
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
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
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 

Último (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
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
 
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...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
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
 
[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
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
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
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

Getting Started with Raspberry Pi - USC 2013

  • 1. Getting Started with Raspberry Pi Tom Paulus @tompaulus www.tompaulus.com
  • 9.  a
  • 12.  B Broadcom ARM11 SoC Broadcom ARM11 SoC ClockSpeed* Up to 1GHz ClockSpeed* Memory 256 MB 512 MB USB 1 USB Port 2 USB Ports Network None Onboard Ethernet CPU Clock Speed Textto 1GHz Up
  • 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 5V 5V 3.3 V 3.3 V 3.3 V SRAM 2 KB 8 KB 96 KB 265 MB 512 MB FLASHMemory 32 KB 256 KB 512 KB up to 64 MB up to 64 MB Clock Speed 16 MHz 16 MHz 84 MHz 700 MHz* 700 MHz* USB Host n/a n/a 1 1 2 Network n/a n/a n/a n/a 10/100 wired Ethernet RJ45 HDMI, Composite Video, TRS-audio jack Audio / Video n/a n/a n/a HDMI, Composite Video, TRS-audio jack Current I/O pins 40 mA 40 mA total 130 mA 2 to 16 mA 2 to 16 mA 54 (12 PWM) 17 (1 PWM) 17 (1 PWM) Digital I/O Pins 14 (6 PWM) 54 (15 PWM) Analog Input Pins 6 16 12 2DAC Analog Out 0* 0* Price $30 $59 $50 $25 $35
  • 31.  SD
  • 33.  4
  • 35.   2
  • 36.  GB
  • 37.  or
  • 41.  are
  • 44. Install Your OS 1. Download and Unzip the .zip from www.raspberrypi.com 2. Format the SD Card to clear all Data 3. Drag Drop the contents of the .zip onto the SD Card
  • 45.
  • 46. Demo
  • 47. GPIO
  • 48.
  • 50.  Python sudo apt-get install python-dev python-pip sudo easy_install -U distribute sudo pip install RPi.GPIO
  • 53.  App
  • 54. blink.py ! 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()
  • 56. Demo
  • 59. RaspberryPi with ADC MCP3008 8-Channel 10-Bit ADC With SPI Interface
  • 60. RaspberryPi Serial Peripheral Interface Bus - SPI SPI requires four signals: clock (SCLK) master output/slave input (MOSI) master input/slave output (MISO) slave select (SS) or (CS) chip-select
  • 61. 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
  • 63. IN =[0000 0001][1CNL ----][---- ----]! (8+channel) 4 OUT=[---- ----][---- -XXX][XXXX XXXX] (10bit) ! ((r[1] 3) 8) + r[2]
  • 64. r = spi.xfer2( [1, (8+chnnl)4, 0] )! return ((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]
  • 65. 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
  • 66. ADC1.py 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()
  • 69. Let’s Add a Display
  • 70. RaspberryPi Inter-IC Bus - I2C 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
  • 71. 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
  • 73. ADC2.py ! 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)
  • 74. ADC2.py 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)                                #         lcd.message('Potentiometer:n' + str(             movavg(l, 4, analogRead(pot_adc))) + '     ')           #         sleep(.1)                                                   #         GPIO.output(statusLED, False)                               #         sleep(.155)                                                 #   except KeyboardInterrupt:     GPIO.output(statusLED, False)     spi.close()   finally:     lcd.clear()     lcd.backlight(lcd.OFF)     GPIO.cleanup() Status Led On Read analog value Wait a little Status Led off Wait a bit longer
  • 76. 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)
  • 77. ADC3.py 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()
  • 79. Demo
  • 80. Why? try:         # Main Program   except KeyboardInterrupt:         # On Interrupt   finally:         GPIO.cleanup()
  • 81. Somewhere, there is an Arduino laughing... Current I/O pins 40 mA Digital I/O Pins 14 (6 PWM) Analog Input Pins 6 Price $30
  • 82. Using
  • 85. JSON
  • 88.  Not 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! }! ]! }! ation ???
  • 89. JSON
  • 91.  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! }! ]! }
  • 92.
  • 93. What
  • 95.  is
  • 96.  it
  • 97.  in
  • 99. time.py #! /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)
  • 100.
  • 102.  the
  • 103.  Data
  • 105. Main.py 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!')
  • 106. WUndergroundAPI.py 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
  • 107. USER Data!! NSA I have some data for you...
  • 108. 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()
  • 109. 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()
  • 110. Demo
  • 111. Wow! We have learned a lot!! Summary 1. Initial Setup of the Raspberry Pi 2. Made a little LED blink 3. Dealt with an Analog Value 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
  • 112.
  • 113.
  • 114. Slides: http://tompaulus.com/talks Code Used in this Talk: https://github.com/tpaulus/SCC-USC2013 Email: tom@tompaulus.com