Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Getting Started withRaspberry PiTom Pauluswww.tompaulus.com@tompaulus
Recommended
 Books
Hardware
Model B
Model A
Model B
Raspberry
 PiText“Take
 a
 bite!”CPUBroadcom ARM11SoCBroadcom ARM11SoCClockSpeedUp to 1GHzClockSpeed*Up to 1GHzClockSpeed*Memory 256 MB 512 MBUSB 1 ...
 BModel
 A
Arduino
 UNO
 
 :
 
 Arduino
 MEGA
 
 :
 
 
 Raspberry
 Pi
 
UNO MEGA DUE Pi Model A Pi Model BOperatingVoltageSRAMFLASH-MemoryClock SpeedUSB HostNetworkAudio /VideoCurrent I/OpinsDig...
Initial Setup
http://www.raspberrypi.org/downloads
Recommended
 SD
 Cards•Class
 4
 Minimum•2
 GB
 or
 More•Major
 Brands
 are
 Better!
Creating Your Image1. Download and Unzip the .img from www.raspberrypi.com2. Format the SD Card to clear all DataWindowsUs...
Demo
GPIO
sudo apt-get install python-dev python-pipsudo easy_install -U distributesudo pip install RPi.GPIOPreparing
 Python
Simple
 Blink
 App
#! /usr/bin/pythonimport timeimport RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM)#use the common numeration,#also the one found ...
Demo
Analogue
 Input
MCP3008 8-Channel 10-Bit ADC With SPI InterfaceRa!berryPiwi ADC
SPI requires four signals:clock (SCLK)master output/slave input (MOSI)master input/slave output (MISO)slave select (SS) or...
pi@raspberrypi ~ $ cat /etc/modprobe.d/raspi-blacklist.conf# blacklist spi and i2c by default (many users dont need them)b...
I2CSPI
IN =[0000 0001][1CNL ----][---- ----](8+channel) 4OUT=[---- ----][---- -XXX][XXXX XXXX] (10bit)((r[1]  3)  8) + r[2]
IN =[0000 0001][1CNL ----][---- ----](8+channel) 4OUT=[---- ----][---- -XXX][XXXX XXXX]r[0] ((r[1]  3)  8) + r[2]r = spi.x...
#! /usr/bin/python#Written By Tom Paulus, @tompaulus, www.tompaulus.comimport timeimport spidevimport RPi.GPIO as GPIO spi...
Demo
Analogue
 InputPart
 2
I2C connects the same two signal linesto all slaves. I.e. addressing is requiredand all devices need a unique addressSDA -...
Upcoming SlideShare
Loading in …5
×

Getting Started with Raspberry Pi - DCC 2013.1

1,461 views

Published on

The Raspberry Pi is a small credit-card sized linux computer. Developers and hobbyists around the world are creating miraculous applications and projects, and now you can join them. Last year we presented Raspberry Pi, What We Have Learned So Far, This year's presentation covers the first steps to using your Pi. From the basics, like burning your SD Card to creating a News Reader, you will learn GPIO Basics and simple Python tools. Communication between other components using SPI or I2C will also be covered. It is recommended, but not required that you have a Raspberry Pi, some knowledge of Python and simple electronics.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Getting Started with Raspberry Pi - DCC 2013.1

  1. 1. Getting Started withRaspberry PiTom Pauluswww.tompaulus.com@tompaulus
  2. 2. Recommended
  3. 3.  Books
  4. 4. Hardware
  5. 5. Model B
  6. 6. Model A
  7. 7. Model B
  8. 8. Raspberry
  9. 9.  PiText“Take
  10. 10.  a
  11. 11.  bite!”CPUBroadcom ARM11SoCBroadcom ARM11SoCClockSpeedUp to 1GHzClockSpeed*Up to 1GHzClockSpeed*Memory 256 MB 512 MBUSB 1 USB Port 2 USB PortsNetwork None Onboard EthernetModel
  12. 12.  BModel
  13. 13.  A
  14. 14. Arduino
  15. 15.  UNO
  16. 16.  
  17. 17.  :
  18. 18.  
  19. 19.  Arduino
  20. 20.  MEGA
  21. 21.  
  22. 22.  :
  23. 23.  
  24. 24.  
  25. 25.  Raspberry
  26. 26.  Pi
  27. 27.  
  28. 28. UNO MEGA DUE Pi Model A Pi Model BOperatingVoltageSRAMFLASH-MemoryClock SpeedUSB HostNetworkAudio /VideoCurrent I/OpinsDigital I/O PinsAnalog InputPinsPrice5V 5V 3.3V 3.3V 3.3V2 KB 8 KB 96 KB 265 MB 512 MB32 KB 256 KB 512 KB up to 64 MB up to 64 MB16 MHz 16 MHz 84 MHz 700 MHz* 700 MHz*n/a n/a 1 1 2n/a n/a n/a n/a10/100 wiredEthernet RJ45n/a n/a n/aHDMI, CompositeVideo,TRS-audio jackHDMI, CompositeVideo,TRS-audio jack40 mA 40 mA total 130 mA 2 to 16 mA 2 to 16 mA14 (6 PWM) 54 (15 PWM) 54 (12 PWM) 17 (1 PWM) 17 (1 PWM)6 16122DAC Analog Out0* 0*$30 $59 $50 $25 $35
  29. 29. Initial Setup
  30. 30. http://www.raspberrypi.org/downloads
  31. 31. Recommended
  32. 32.  SD
  33. 33.  Cards•Class
  34. 34.  4
  35. 35.  Minimum•2
  36. 36.  GB
  37. 37.  or
  38. 38.  More•Major
  39. 39.  Brands
  40. 40.  are
  41. 41.  Better!
  42. 42. Creating Your Image1. Download and Unzip the .img from www.raspberrypi.com2. Format the SD Card to clear all DataWindowsUsers:UseWin32DiskImagerMac Users:in a Terminal--sudo diskutil unmount /dev/disk1s1sudo dd bs=1m if=(Insert Location of .img) of=(SD Card)syncsudo diskutil eject /dev/rdisk1
  43. 43. Demo
  44. 44. GPIO
  45. 45. sudo apt-get install python-dev python-pipsudo easy_install -U distributesudo pip install RPi.GPIOPreparing
  46. 46.  Python
  47. 47. Simple
  48. 48.  Blink
  49. 49.  App
  50. 50. #! /usr/bin/pythonimport timeimport RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM)#use the common numeration,#also the one found on the Adafruit Cobbler led = 25delay = .5GPIO.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
  51. 51. Demo
  52. 52. Analogue
  53. 53.  Input
  54. 54. MCP3008 8-Channel 10-Bit ADC With SPI InterfaceRa!berryPiwi ADC
  55. 55. SPI requires four signals:clock (SCLK)master output/slave input (MOSI)master input/slave output (MISO)slave select (SS) or (CS) chip-selectRa!berryPiSe#al Pe#pheral Interface Bus - SPI
  56. 56. pi@raspberrypi ~ $ cat /etc/modprobe.d/raspi-blacklist.conf# blacklist spi and i2c by default (many users dont need them)blacklist spi-bcm2708blacklist i2c-bcm2708Loading 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 andls /dev/spi* shows two spi devices: /dev/spidev0.0 and /dev/spidev0.1Installing Dependencies:sudo apt-get install python-dev git-coreInstall Python bindings for Linux SPI access through spidev:cd ~git clone git://github.com/doceme/py-spidevcd py-spidev/sudo python setup.py install... which creates /usr/local/lib/python2.7/dist-packages/spidev.soSPI
  57. 57. I2CSPI
  58. 58. IN =[0000 0001][1CNL ----][---- ----](8+channel) 4OUT=[---- ----][---- -XXX][XXXX XXXX] (10bit)((r[1] 3) 8) + r[2]
  59. 59. IN =[0000 0001][1CNL ----][---- ----](8+channel) 4OUT=[---- ----][---- -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]
  60. 60. #! /usr/bin/python#Written By Tom Paulus, @tompaulus, www.tompaulus.comimport timeimport spidevimport RPi.GPIO as GPIO spi = spidev.SpiDev()light_adc = 7statusLED = 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)
  61. 61. Demo
  62. 62. Analogue
  63. 63.  InputPart
  64. 64.  2
  65. 65. I2C connects the same two signal linesto all slaves. I.e. addressing is requiredand all devices need a unique addressSDA - Serial DataSCL - Serial ClockRa!berryPiInter-IC Bus - I2C
  66. 66. pi@raspberrypi ~ $ cat /etc/modprobe.d/raspi-blacklist.conf# blacklist spi and i2c by default (many users dont need them)blacklist spi-bcm2708blacklist i2c-bcm2708Loading Kernel Modules:- Edit the raspi-blacklist.conf, so that the i2c module gets enabled.- Add the following lines to /etc/modules i2c-devi2c-bcm2708Reboot, and confirm ls /dev/i2c*shows/dev/i2c-0/dev/i2c-1Installing Dependencies:sudo apt-get install python-smbus i2c-toolsWith i2c devices connected, run somthing like this, to discover devices addresses.sudo i2cdetect -y 0I2C
  67. 67. I2CSPI
  68. 68. #! /usr/bin/python#Written By Tom Paulus, @tompaulus, www.tompaulus.comimport timeimport spidevimport RPi.GPIO as GPIOfrom Adafruit_LEDBackpack.Adafruit_7Segment import SevenSegmentimport smbus GPIO.setmode(GPIO.BCM)segment = SevenSegment(address=0x70)  # which port the display isspi = spidev.SpiDev()light_adc = 7l = list()statusLED = 25print Press CTRL+Z to exitGPIO.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
  69. 69. 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**
  70. 70. Demo
  71. 71. Using
  72. 72.  Outside
  73. 73.  Data
  74. 74. JSON
  75. 75. JavaScript
  76. 76.  Object
  77. 77.  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}]}
  78. 78. JSON
  79. 79.  meet
  80. 80.  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}]}
  81. 81. What
  82. 82.  time
  83. 83.  is
  84. 84.  it
  85. 85.  in
  86. 86.  city?
  87. 87. #! /usr/bin/python#Written By Tom Paulus, @tompaulus, www.tompaulus.com import lib.requests as requestsimport 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)
  88. 88. Displaying
  89. 89.  the
  90. 90.  Data
  91. 91. News Client
  92. 92. 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
  93. 93.          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)
  94. 94. The Quick Brown Fox Jumps Over The Lazy Dog[The Quick BrownnFox Jumps Over, The Lazy Dog]
  95. 95. 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 JSONwhile 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)
  96. 96. Demo
  97. 97. Wea!er Client
  98. 98. 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!)
  99. 99. 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
  100. 100. Demo
  101. 101. SummaryWow! We have learned a lot!!1. Initial Setup of the Raspberry Pi2. Made a little LED blink3. Dealt with an AnalogValue and Displayed it4.The Basics of JSON5. Got our feet wet by finding the Time in different places6. Used our new Knowledge to find the Weather7.What’s new in the News?
  102. 102. Slides:Code Used in this Talk:http://tompaulus.com/talkshttps://github.com/tpaulus/DCC-April13Email:tom@tompaulus.com
  103. 103. Slides:Code Used in this Talk:http://tompaulus.com/talkshttps://github.com/tpaulus/DCC-April13Email:tom@tompaulus.com

×