SlideShare a Scribd company logo
Getting Started with
Raspberry Pi
Tom Paulus
www.tompaulus.com
@tompaulus
Recommended
 Books
Hardware
Model B
Model A
Model B
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
Getting Started with Raspberry Pi - DCC 2013.1
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:
in a Terminal--
sudo diskutil unmount /dev/disk1s1
sudo dd bs=1m if=(Insert Location of .img) of=(SD Card)
sync
sudo diskutil eject /dev/rdisk1
Getting Started with Raspberry Pi - DCC 2013.1
Demo
GPIO
Getting Started with Raspberry Pi - DCC 2013.1
sudo apt-get install python-dev python-pip
sudo easy_install -U distribute
sudo pip install RPi.GPIO
Preparing
 Python
Simple
 Blink
 App
#! /usr/bin/python
import time
import RPi.GPIO as GPIO
 
GPIO.setmode(GPIO.BCM)
#use the common numeration,
#also the one found on the Adafruit Cobbler
 
led = 25
delay = .5
GPIO.setup(led, GPIO.OUT)
#Set 'led' as and Output
 
while True:
    GPIO.output(led, True)  #led On
    time.sleep(delay)       #wait 'delay' seconds
    GPIO.output(led, False) #led off
    time.sleep(delay)      #wait another 'delay' seconds
Getting Started with Raspberry Pi - DCC 2013.1
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]
#! /usr/bin/python
#Written By Tom Paulus, @tompaulus, www.tompaulus.com
import time
import spidev
import RPi.GPIO as GPIO
 
spi = spidev.SpiDev()
light_adc = 7
statusLED = 25
 
GPIO.setmode(GPIO.BCM)
GPIO.setup(statusLED, GPIO.OUT)
 
print Press CTRL+Z to exit
 
def analogRead(port):
    Read the given ADC port and preform the necessary shifting of bits
    spi.open(0, 0)
    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
 
while True:
    GPIO.output(statusLED, True)
    print analogRead(light_adc)
    time.sleep(.125)
    GPIO.output(statusLED, False)
    time.sleep(.175)
Getting Started with Raspberry Pi - DCC 2013.1

More Related Content

What's hot (19)

Phil Bartie QGIS PLPython
Phil Bartie QGIS PLPython
Ross McDonald
 
N flavors of streaming
N flavors of streaming
Ruslan Shevchenko
 
Lecture6
Lecture6
misgina Mengesha
 
Lec06
Lec06
siddu kadiwal
 
Java on arm theory, applications, and workloads [dev5048]
Java on arm theory, applications, and workloads [dev5048]
Aleksei Voitylov
 
Programming at Compile Time
Programming at Compile Time
emBO_Conference
 
Kernel Recipes 2014 - x86 instruction encoding and the nasty hacks we do in t...
Kernel Recipes 2014 - x86 instruction encoding and the nasty hacks we do in t...
Anne Nicolas
 
Advance ROP Attacks
Advance ROP Attacks
n|u - The Open Security Community
 
Productive OpenCL Programming An Introduction to OpenCL Libraries with Array...
Productive OpenCL Programming An Introduction to OpenCL Libraries with Array...
AMD Developer Central
 
C++ AMP 실천 및 적용 전략
C++ AMP 실천 및 적용 전략
명신 김
 
Design and Implementation of GCC Register Allocation
Design and Implementation of GCC Register Allocation
Kito Cheng
 
TVM VTA (TSIM)
TVM VTA (TSIM)
Mr. Vengineer
 
Chp2 introduction to the 68000 microprocessor copy
Chp2 introduction to the 68000 microprocessor copy
mkazree
 
eBPF maps 101
eBPF maps 101
SUSE Labs Taipei
 
LED Blinking Using Raspberry Pi
LED Blinking Using Raspberry Pi
Arjun R Krishna
 
Go Go Gadget! - An Intro to Return Oriented Programming (ROP)
Go Go Gadget! - An Intro to Return Oriented Programming (ROP)
Miguel Arroyo
 
8-bit Emulator Programming with Go
8-bit Emulator Programming with Go
Ignacio Sánchez Ginés
 
Error Control in Multimedia Communications using Wireless Sensor Networks report
Error Control in Multimedia Communications using Wireless Sensor Networks report
Muragesh Kabbinakantimath
 
Runtime Symbol Resolution
Runtime Symbol Resolution
Ken Kawamoto
 
Phil Bartie QGIS PLPython
Phil Bartie QGIS PLPython
Ross McDonald
 
Java on arm theory, applications, and workloads [dev5048]
Java on arm theory, applications, and workloads [dev5048]
Aleksei Voitylov
 
Programming at Compile Time
Programming at Compile Time
emBO_Conference
 
Kernel Recipes 2014 - x86 instruction encoding and the nasty hacks we do in t...
Kernel Recipes 2014 - x86 instruction encoding and the nasty hacks we do in t...
Anne Nicolas
 
Productive OpenCL Programming An Introduction to OpenCL Libraries with Array...
Productive OpenCL Programming An Introduction to OpenCL Libraries with Array...
AMD Developer Central
 
C++ AMP 실천 및 적용 전략
C++ AMP 실천 및 적용 전략
명신 김
 
Design and Implementation of GCC Register Allocation
Design and Implementation of GCC Register Allocation
Kito Cheng
 
Chp2 introduction to the 68000 microprocessor copy
Chp2 introduction to the 68000 microprocessor copy
mkazree
 
LED Blinking Using Raspberry Pi
LED Blinking Using Raspberry Pi
Arjun R Krishna
 
Go Go Gadget! - An Intro to Return Oriented Programming (ROP)
Go Go Gadget! - An Intro to Return Oriented Programming (ROP)
Miguel Arroyo
 
Error Control in Multimedia Communications using Wireless Sensor Networks report
Error Control in Multimedia Communications using Wireless Sensor Networks report
Muragesh Kabbinakantimath
 
Runtime Symbol Resolution
Runtime Symbol Resolution
Ken Kawamoto
 

Similar to Getting Started with Raspberry Pi - DCC 2013.1 (20)

HDL17_MIPS CPU Design using Verilog.pptx
HDL17_MIPS CPU Design using Verilog.pptx
das85271
 
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
RootedCON
 
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
Functional Thursday
 
20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris
imec.archive
 
class04_x86assembly.ppt hy there u need be
class04_x86assembly.ppt hy there u need be
mnewg218
 
Em s7 plc
Em s7 plc
chethanraj
 
ISA.pptx
ISA.pptx
FarrukhMuneer2
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5
PRADEEP
 
8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED C
Aman Sharma
 
Chapter 2 Part2 C
Chapter 2 Part2 C
ececourse
 
node-rpi-ws281x
node-rpi-ws281x
Martin Schuhfuß
 
Using ARM Dev.Board in physical experimental instruments
Using ARM Dev.Board in physical experimental instruments
a_n0v
 
Code Red Security
Code Red Security
Amr Ali
 
The Joy Of Server Side Swift Development
The Joy Of Server Side Swift Development
Giordano Scalzo
 
The Joy of ServerSide Swift Development
The Joy of ServerSide Swift Development
Giordano Scalzo
 
General Purpose Computing using Graphics Hardware
General Purpose Computing using Graphics Hardware
Daniel Blezek
 
The n00bs guide to ovs dpdk
The n00bs guide to ovs dpdk
markdgray
 
Network Programming: Data Plane Development Kit (DPDK)
Network Programming: Data Plane Development Kit (DPDK)
Andriy Berestovskyy
 
23_Advanced_Processors controller system
23_Advanced_Processors controller system
stellan7
 
Debugging Ruby Systems
Debugging Ruby Systems
Engine Yard
 
HDL17_MIPS CPU Design using Verilog.pptx
HDL17_MIPS CPU Design using Verilog.pptx
das85271
 
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
RootedCON
 
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
Functional Thursday
 
20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris
imec.archive
 
class04_x86assembly.ppt hy there u need be
class04_x86assembly.ppt hy there u need be
mnewg218
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5
PRADEEP
 
8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED C
Aman Sharma
 
Chapter 2 Part2 C
Chapter 2 Part2 C
ececourse
 
Using ARM Dev.Board in physical experimental instruments
Using ARM Dev.Board in physical experimental instruments
a_n0v
 
Code Red Security
Code Red Security
Amr Ali
 
The Joy Of Server Side Swift Development
The Joy Of Server Side Swift Development
Giordano Scalzo
 
The Joy of ServerSide Swift Development
The Joy of ServerSide Swift Development
Giordano Scalzo
 
General Purpose Computing using Graphics Hardware
General Purpose Computing using Graphics Hardware
Daniel Blezek
 
The n00bs guide to ovs dpdk
The n00bs guide to ovs dpdk
markdgray
 
Network Programming: Data Plane Development Kit (DPDK)
Network Programming: Data Plane Development Kit (DPDK)
Andriy Berestovskyy
 
23_Advanced_Processors controller system
23_Advanced_Processors controller system
stellan7
 
Debugging Ruby Systems
Debugging Ruby Systems
Engine Yard
 
Ad

Recently uploaded (20)

Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
High Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdf
Safe Software
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
Safe Software
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Safe Software
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
High Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdf
Safe Software
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
Safe Software
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Safe Software
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
Ad

Getting Started with Raspberry Pi - DCC 2013.1

  • 1. Getting Started with Raspberry Pi Tom Paulus www.tompaulus.com @tompaulus
  • 10.  a
  • 11.  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
  • 13.  A
  • 16.  UNO
  • 17.  
  • 18.  :
  • 19.  
  • 22.  
  • 23.  :
  • 24.  
  • 25.  
  • 27.  Pi
  • 28.  
  • 29. 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
  • 33.  SD
  • 35.  4
  • 37.  GB
  • 38.  or
  • 41.  are
  • 43. 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: in a Terminal-- sudo diskutil unmount /dev/disk1s1 sudo dd bs=1m if=(Insert Location of .img) of=(SD Card) sync sudo diskutil eject /dev/rdisk1
  • 45. Demo
  • 46. GPIO
  • 48. sudo apt-get install python-dev python-pip sudo easy_install -U distribute sudo pip install RPi.GPIO Preparing
  • 52.  App
  • 53. #! /usr/bin/python import time import RPi.GPIO as GPIO   GPIO.setmode(GPIO.BCM) #use the common numeration, #also the one found on the Adafruit Cobbler   led = 25 delay = .5 GPIO.setup(led, GPIO.OUT) #Set 'led' as and Output   while True:     GPIO.output(led, True)  #led On     time.sleep(delay)       #wait 'delay' seconds     GPIO.output(led, False) #led off     time.sleep(delay)      #wait another 'delay' seconds
  • 55. Demo
  • 58. MCP3008 8-Channel 10-Bit ADC With SPI Interface Ra!berryPi wi ADC
  • 59. 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
  • 60. 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
  • 62. IN =[0000 0001][1CNL ----][---- ----] (8+channel) 4 OUT=[---- ----][---- -XXX][XXXX XXXX] (10bit) ((r[1] 3) 8) + r[2]
  • 63. 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]
  • 64. #! /usr/bin/python #Written By Tom Paulus, @tompaulus, www.tompaulus.com import time import spidev import RPi.GPIO as GPIO   spi = spidev.SpiDev() light_adc = 7 statusLED = 25   GPIO.setmode(GPIO.BCM) GPIO.setup(statusLED, GPIO.OUT)   print Press CTRL+Z to exit   def analogRead(port):     Read the given ADC port and preform the necessary shifting of bits     spi.open(0, 0)     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   while True:     GPIO.output(statusLED, True)     print analogRead(light_adc)     time.sleep(.125)     GPIO.output(statusLED, False)     time.sleep(.175)
  • 66. Demo
  • 69.  2
  • 70. 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
  • 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. #! /usr/bin/python #Written By Tom Paulus, @tompaulus, www.tompaulus.com import time import spidev import RPi.GPIO as GPIO from Adafruit_LEDBackpack.Adafruit_7Segment import SevenSegment import smbus   GPIO.setmode(GPIO.BCM) segment = SevenSegment(address=0x70)  # which port the display is spi = spidev.SpiDev() light_adc = 7 l = list() statusLED = 25 print Press CTRL+Z to exit GPIO.setup(statusLED, GPIO.OUT)   def analogRead(port):     Read the given ADC port and preform the necessary shifting of bits     spi.open(0, 0)     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
  • 74. def movavg(list, length, value):     A function that smooths the results by averaging a list     #Courtesy Wolf Paulus     list.append(value)     if length len(list):         del list[0]     sum = 0     for x in list[:]:         sum += x     return sum / len(list)     while True:     GPIO.output(statusLED, True)     segment.writeInt(movavg(l, 4, analogRead(light_adc)))     time.sleep(.125)     GPIO.output(statusLED, False)     time.sleep(.175) **This program uses a modified library**
  • 76. Demo
  • 77. Using
  • 80. JSON
  • 83.  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 } ] }
  • 84. JSON
  • 86.  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 } ] }
  • 88. What
  • 90.  is
  • 91.  it
  • 92.  in
  • 94. #! /usr/bin/python #Written By Tom Paulus, @tompaulus, www.tompaulus.com   import lib.requests as requests import time   timeURL = 'http://json-time.appspot.com/time.json?tz=' zone = 'America/Phoenix'   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)
  • 97.  the
  • 100. class Scroller():      def splitString(self, s, lineLength):         # s = 'The Quick Brown Fox Jumps Over The Lazy Dog' #Test String           string = ''         length = 0         k = 0       #Counter Variable         wordLength = list()         strings = list()         lines = list()           words = s.strip().split()           for k in range(0, len(words)): #Make a list of the word lengths             length = len(words[k])             wordLength.append(length)           k = 0       #Reset Counter           while k len(words):             if len(string) + len(words[k]) + 1 lineLength:                 if len(string) == 0:                     string += words[k]                 else:                     string = string + ' ' + words[k]                 k += 1               else:                 strings.append(string)                 string = ''               if k == len(words):                 strings.append(string)                 string = ''         k = 0       #Reset Counter
  • 101.           while k len(strings): #Format for Our Display             if k == len(strings) - 1:                 line = strings[k]                 lines.append(line)                 break             else:                 line = strings[k] + 'n' + strings[k + 1]                 lines.append(line)                 k += 2         return lines     if __name__ == '__main__':     s = raw_input('Enter the string to be separatedn').replace('n', '')     tools = Scroller()     print tools.splitString(s, 16)
  • 102. The Quick Brown Fox Jumps Over The Lazy Dog ['The Quick BrownnFox Jumps Over', 'The Lazy Dog']
  • 103. class NewsAPI:     def get(self,count,key):                Get the homepage form HackerNews        :return: JSON object                 url = 'http://api.usatoday.com/open/articles/topnews/news?count='+str(count)+'days=0page=0encoding=jsonapi_key='+key         d = requests.get(url)         JSON = d.json()         return JSON while True:     z = 0     if update:         nJson = API.get(15, API_KEY)         length = len(nJson['stories'])         for x in range(0, length):             articles.append(nJson['stories'][x]['title'])         update = False       display = tools.splitString(articles[currentTitle], 16)     for y in range(0, len(display)):         z += 1         Timer(y * 2, rotate, args=[display[y]]).start()     time.sleep(z * 2 + 2)     currentTitle = (currentTitle + 1) % len(articles)
  • 104. Demo
  • 106. 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!')
  • 107. 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
  • 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.What’s new in the News?
  • 111. Slides: Code Used in this Talk: http://tompaulus.com/talks https://github.com/tpaulus/DCC-April13 Email: [email protected]
  • 112. Slides: Code Used in this Talk: http://tompaulus.com/talks https://github.com/tpaulus/DCC-April13 Email: [email protected]