Upload
phungdung
View
215
Download
2
Embed Size (px)
Citation preview
Arduino - Physical Computingfür Bastler, Designer und Geeks
Manuel Odendahl, ]ulian Finn, Alex Wenger
Q'REILLY®Beijing . Cambridge • Farnham • Köln . Sebastopol • Taipei . Tokyo
Inhalt
Einleitung . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . IX
Von Königen und Kondensatoren. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Die Geschichte des Arduino-Projekts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Der Arduino, das unbekannte Gerät. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Arduino-Projekte: eine kleine Vorstellung. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8Hardware. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17Die Arduino-Entwicklungsumgebung. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 22
2 Physical (omputing, elektrische Grundlagen und der Sprung ins kalte Wasser. . . . . . . .. 31Elektrische Grundlagen. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 35Schaltungen, Bauteile und Schaltbilder " 43Löten. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 64Fehlersuche in elektronischen Schaltungen. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
3 Workshop LED-Licht . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83Erste Schritte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 83Eine blinkende LED - das »Hello World« des Physical Computing. . . . . . . . . . . . .. 84
4 LEDs tür Fortgeschrittene. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 109LED-Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 109Animationen " 113Imerrupts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 115Tamagotchi 118Brainwave und Biofeedback. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 120
v
5 Sprich mit mir, Arduino! , 129Nach Hause telefonieren mit der seriellen Konsole. . . . . . . . . . . . . . . . . . . . . . . . .. 131Automatisierung mit Gobetwino , 137Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 142
6 Arduino im Netz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 153Hello World - ein Mini-Webserver '" . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 157Sag's der Welt mit Twitter. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 160Fang die Bytes - Datalogger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 165
7 Sensoren , 171Sensoren , 171Aktoren . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 189Elektronischer Würfel. , 193
8 Ein kleiner Arduino-Roboter , 199Flieg, Arduino, flieg! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 202Arduino und der Asuro-Robot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 205
9 Musik-Controller mit Arduino. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 211Musik steuern mit dem Arduino. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 211Das MIDI-Protokoll .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 217Die MidiDuino-Bibliothek . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 223Zweiter Sketch: Mikroskopischer Controller. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 225Dritter Sketch: Miniatur-Controller. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 226Vierter Sketch: Ein MIDI-Zauberstab. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 229Fünfter Sketch: MIDI-Input. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 232
10 Musik mit Arduino , 235Töne aus dem Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 235Erster Sketch: Töne mit langsamer PWM , 239Zweiter Sketch: Angenehme Klänge mit schneller PWM . . . . . . . . . . . . . . . . . . . . .. 240Dritter Sketch: Steuerung von Klängen. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 242Vierter Sketch: Berechnungen in einer Interrupt-Routine , 244Fünfter Sketch: Musikalische Noten. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 247
A Arduino-Boards und Shields , 253Arduino-Boards. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 253Arduino-Shields , 257
VI Inhalt
B Arduino-Bibliotheken................................................... 263EEPROM-Bibliothek: Werte langfristig speichern 264Ethernet-Bibliothek: mit dem Internet kommunizieren. . . . . . . . . . . . . . . . . . . . . .. 265Firmata-Bibliothek " 270LiquidCrystal-Bibliothek. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 270Servo-Bibliothek. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 272Debounce-Bibliothek 274Wire-Bibliothek. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 275capSense-Bibliothek 277
( Sprachreferenz. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 281Übersicht: Programmiersprachen. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 281Struktur, Werte und Funktionen. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 282Syntax 283Programmwerte (Variablen, Datentypen und Konstanten). . . . . . . . . . . . . . . . . . . .. 287Ausdrücke und Anweisungen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 299Ausdrücke . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 300Kontrollstrukturen 318Funktionen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 330Sketch-Struktur. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 340Funktionsreferenz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 343
D Händlerliste . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 361
Index 363
Inhalt VII