1. Python auf dem Raspberry Pi
Thomas Koch @tomy_koch
PythonCamp, Köln, Mai 2013
2. Agenda
Specs:
Was ist der Raspberry Pi ?
Anwendungen:
Was kann der Raspberry Pi ?
GPIO mit Python
Programmierung & Beispiele
Weitere Infos
Links, Literatur
05/2013Thomas Koch
3. Einführung: Der Raspberry Pi
Grundlagen
SOC Minicomputer: "System on a chip"
512 MB Hauptspeicher und 700 MHZ ARM CPU
Ethernet-Schnittstelle und zwei USB-Anschlüsse (Modell B)
"BYOP"-Prinzip: "bring your own peripherals“
Lieferung ohne Maus,Tastatur, Netzstecker etc.
Nackte Platine (ohne Gehäuse), ohne SD-Card/OS
Einschränkungen
keine Uhr
kein BIOS (d.h. Raspi kann NUR von SD-Card booten)
05/2013Thomas Koch
4. Hardware: Der Raspberry Pi
05/2013Thomas Koch
Das Board
GPIO (General Purpose Input/Output)
CSI (Camera Serial Interface)
DVI-Out
OS
Raspbian (Debian)
Arch Linux
RISC OS
5. Anwendungsmöglichkeiten
Network Device
Print- und Webserver, VPN-Server, DHCP-Server etc.
Cloud für eigenes Netzwerk
Raspberry Pi als Mediacenter
XBMC basierende Distributionen wie OpenELEC, Raspbmc
Oder auch als AirPlay Empfänger
Remote Control
Steuereinheit für eigene Roboter oder Luftfahrzeuge
Home Automation
Alarm Anlage
Kiosk-Systeme
eingebauterWeb-Browser "midori" bietetVollbildmodus
$ midori -e Fullscreen -a <URL>
http://lifehacker.com/5978871/ten-more-awesome-projects-for-your-raspberry-pi
10. Mini Tutorial II
05/2013Thomas Koch
Konfiguration:
$ raspi-config
‘enable ssh’
‘change_pass ‘ change system password (for the user 'pi')
http://learn.adafruit.com/adafruits-raspberry-pi-lesson-2-first-time-configuration/overview
nützliche Debian Pakete
für GPIO: "WiringPi"
https://projects.drogon.net/raspberry-pi/wiringpi/
$ sudo apt-get install git-core
$ git clone git://git.drogon.net/wiringPi
11. GPIO Basics
05/2013Thomas Koch
GPIO perWiringPI steuern
Ports per WiringPI ansteuern
command-line utility gpio
can be used to program and setup
the GPIO pins
pi@raspi ~ $ gpio readall
Python-Bindings
Bindings für GPIO-Projekt
WiringPi auf github:
https://github.com/WiringPi/WiringPi-Python
+----------+------+--------+------+-------+
| wiringPi | GPIO | Name | Mode | Value |
+----------+------+--------+------+-------+
| 0 | 17 | GPIO 0 | IN | Low |
| 1 | 18 | GPIO 1 | IN | Low |
| 2 | 27 | GPIO 2 | OUT | Low |
| 3 | 22 | GPIO 3 | IN | Low |
| 4 | 23 | GPIO 4 | IN | Low |
| 5 | 24 | GPIO 5 | IN | Low |
| 6 | 25 | GPIO 6 | IN | Low |
| 7 | 4 | GPIO 7 | IN | Low |
| 8 | 2 | SDA | ALT0 | High |
| 9 | 3 | SCL | ALT0 | High |
| 10 | 8 | CE0 | IN | Low |
| 11 | 7 | CE1 | IN | Low |
| 12 | 10 | MOSI | IN | Low |
| 13 | 9 | MISO | IN | Low |
| 14 | 11 | SCLK | IN | Low |
| 15 | 14 | TxD | ALT0 | High |
| 16 | 15 | RxD | ALT0 | High |
| 17 | 28 | GPIO 8 | IN | Low |
| 18 | 29 | GPIO 9 | IN | Low |
| 19 | 30 | GPIO10 | IN | Low |
| 20 | 31 | GPIO11 | IN | Low |
+----------+------+--------+------+-------+
$ gpio mode 0 out
$ gpio write 0 1
$ gpio write 0 0
12. Python auf dem Raspberry PI
05/2013Thomas Koch
Python included
Raspi kommt mit Python 2.7 und 3.2
und pygame http://www.pygame.org/
GPIO mit Python
simple GPIO PythonWrapper: RPi.GPIO
A module to control Raspberry Pi GPIO channels
includes a C extension
any script using RPi.GPIO must run with root privileges!
https://pypi.python.org/pypi/RPi.GPIO
14. Beispiel: WiringPi
05/2013Thomas Koch
Serielle Schnittstellte
GPIO bietet pins für 'transmit' signal (TxD) and 'receive' signal (RxD)
Achtung: Raspberry Pi verwendet 0 – 3.3V level (RS-232: +/-12V)
serialOpen: Requires device/baud and returns an ID
https://projects.drogon.net/raspberry-pi/wiringpi/
http://elinux.org/RPi_Serial_Connection
serial = wiringpi.serialOpen('/dev/ttyAMA0',9600)
wiringpi.serialPuts(serial,"hello")
wiringpi.serialClose(serial) // Pass in ID
15. Beispiel: RPi.GPIO
05/2013Thomas Koch
LED einschalten
http://elinux.org/RPi_Low-level_peripherals#Python
https://projects.drogon.net/raspberry-pi/gpio-examples/tux-crossing/gpio-examples-1-a-single-led/
import RPi.GPIO as GPIO
# header pin numbering BCM GPIO 00..nn
GPIO.setmode(GPIO.BCM)
# Set up the GPIO channels:
# one input and one output
GPIO.setup(17, GPIO.IN)
GPIO.setup(18, GPIO.OUT)
input_value = GPIO.input(17)
print „pin#17 is“, input_value
GPIO.output(18, GPIO.HIGH)