Faszinierende Elektronik-Projekte mit Scratch

031-9.book Seite I Dienstag, 17. März 2015 1:57 13
Rechts
Faszinierende Elektronik-Projekte mit
Scratch, Raspberry Pi und Arduino
Max.
Linie
Max.
Linie
031-9.book Seite II Dienstag, 17. März 2015 1:57 13
Links
Max.
Linie
Max.
Linie
031-9.book Seite III Dienstag, 17. März 2015 1:57 13
Rechts
Faszinierende Elektronik-Projekte
mit Scratch, Raspberry Pi
und Arduino
Erik Bartmann
Max.
Linie
Max.
Linie
Beijing · Cambridge · Farnham · Köln · Sebastopol · Tokyo
031-9.book Seite IV Dienstag, 17. März 2015 1:57 13
Links
Die Informationen in diesem Buch wurden mit größter Sorgfalt erarbeitet. Dennoch können
Fehler nicht vollständig ausgeschlossen werden. Verlag, Autoren und Übersetzer übernehmen
keine juristische Verantwortung oder irgendeine Haftung für eventuell verbliebene Fehler und
deren Folgen.
Alle Warennamen werden ohne Gewährleistung der freien Verwendbarkeit benutzt und sind
möglicherweise eingetragene Warenzeichen. Der Verlag richtet sich im wesentlichen nach den
Schreibweisen der Hersteller. Das Werk einschließlich aller seiner Teile ist urheberrechtlich
geschützt. Alle Rechte vorbehalten einschließlich der Vervielfältigung, Übersetzung,
Mikroverfilmung sowie Einspeicherung und Verarbeitung in elektronischen Systemen.
Kommentare und Fragen können Sie gerne an uns richten:
O’Reilly Verlag
Balthasarstr. 81
50670 Köln
E-Mail: [email protected]
Copyright:
© 2015 by O’Reilly Verlag GmbH & Co. KG
1. Auflage 2015
Bibliografische Information Der Deutschen Nationalbibliothek
Die Deutsche Nationalbibliothek verzeichnet diese Publikation in der
Deutschen Nationalbibliografie; detaillierte bibliografische Daten
sind im Internet über http://dnb.d-nb.de abrufbar.
Lektorat: Volker Bombien, Köln
Korrektorat: Dr. Dorothée Leidig, Freiburg
Umschlaggestaltung: Michael Oreal, Köln
Produktion: Karin Driesen, Köln
Satz: III-satz, www.drei-satz.de
Belichtung, Druck und buchbinderische Verarbeitung:
Mediaprint, Paderborn
ISBN 978-3-95875-031-9
Dieses Buch ist auf 100% chlorfrei gebleichtem Papier gedruckt.
Max.
Linie
Max.
Linie
031-9.book Seite V Dienstag, 17. März 2015 1:57 13
Rechts
Inhalt
Einleitung . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
IX
Es muss nicht unbedingt Code sein. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Was macht die Faszination von Scratch aus? . . . . . . . . . . . . . . . . . . .
Interessante Links zu Projekten. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Was nicht fehlen darf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Vielen Dank für die großzügige Unterstützung . . . . . . . . . . . . . . . . .
X
XIV
XIV
XV
XVI
Was ist Scratch? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Die Programmiersprache Scratch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Die Scratch-2-Oberfläche . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Ein erstes Beispiel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
S4A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Die Installation von S4A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Das Prinzip von S4A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
S4A und die Ports des Arduino. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
MBlock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Die Installation von MBlock. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Die Prinzip von MBlock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Die Ports des Baseboards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Riskiere einen Blick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
4
6
11
12
16
19
52
54
57
58
66
Für den Einstieg: Arduino und Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . .
Der Arduino. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Die zentrale Recheneinheit (CPU) . . . . . . . . . . . . . . . . . . . . . . . . . . .
Der Daten-Bus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Speicherbereiche . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Die Ein- bzw. Ausgabeports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Interrupt-Steuerung . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Der Arduino im Detail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Der Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Der Raspberry Pi im Detail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
67
69
69
69
70
71
71
72
74
1
2
Max.
Linie
Inhalt
1
67
| V
Max.
Linie
031-9.book Seite VI Dienstag, 17. März 2015 1:57 13
Links
3
4
5
Max.
Linie
VI |
Was wird benötigt? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Das Steckbrett (Breadboard) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Flexible Steckbrücken . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Ein digitales Multimeter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Eine Widerstandsbiegelehre . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Das Starter-Robot-Kit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Die elektronischen Bauteile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
75
75
79
79
80
81
82
Projekte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
83
Projekt 4-1: Das Blinken einer LED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Projekt 4-2: Mit Bauteilen experimentieren . . . . . . . . . . . . . . . . . . . . . . . .
Projekt 4-3: Eine Ampelschaltung . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Projekt 4-4: Der elektronische Würfel. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Projekt 4-5: Wir steuern einen Roboter . . . . . . . . . . . . . . . . . . . . . . . . . . .
Projekt 4-6: Simple-Pong. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Projekt 4-7: Analog-Monitoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Projekt 4-8: Der Robot-Tank. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Projekt 4-9: Sound-Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Projekt 4-10: Asteroids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
85
95
113
121
131
153
163
169
191
199
Was ist Elektronik? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
225
Die Elektronik . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Der Elektronenfluss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Der Strom . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Die Spannung . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Der allgemeine Widerstand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Das Ohmsche Gesetz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Der geschlossene Stromkreis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Bauteile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Der Unterschied zwischen passiven und aktiven Bauelementen . . . .
Der Festwiderstand. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Der veränderliche Widerstand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Der temperaturempfindliche Widerstand . . . . . . . . . . . . . . . . . . . . .
Der Kondensator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Die Diode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Der Transistor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Die Leuchtdiode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Weitere interessante Bauteile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Der Schalter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Der Taster. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Der Motor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Der Schrittmotor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
225
225
226
227
229
230
231
233
234
234
237
240
242
247
251
255
257
257
258
259
261
Inhalt
Max.
Linie
031-9.book Seite VII Dienstag, 17. März 2015 1:57 13
Rechts
Der Servo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Das Piezo-Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
264
266
Scratch und Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Die GPIO-Schnittstelle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Ansteuerung der GPIO-Schnittstelle . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Benötigte Bauteile: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Das Scratch-Skript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Riskiere einen Blick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
269
271
275
277
279
Das PicoBoard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Was kann das PicoBoard? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Benötigte Software. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Starten von Scratch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Was sagt der Raspberry Pi dazu?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Erste Schritte mit dem PicoBoard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Das Salzwasser-Experiment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Der Fluglage-Sensor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Benötigte Bauteile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Das Scratch-Skript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Riskiere einen Blick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
281
283
284
285
289
290
293
293
298
300
Wo bekomme ich was? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Bezugsquellen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Wo bekomme ich was? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
In eigener Sache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
301
301
301
302
302
302
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
303
6
7
8
269
281
301
Max.
Linie
Max.
Linie
Inhalt | VII