Getting started with Arduino 2 edition.pdf

(6589 KB) Pobierz
758386679.001.png
758386679.002.png
Getting
Started
with
Arduino
Massimo Banzi
Second Edition
758386679.003.png
Getting Started with Arduino
by Massimo Banzi
Copyright © 2011 Massimo Banzi. All rights reserved.
Printed in the U.S.A.
Published by Make:Books, an imprint of Maker Media,
a division of O’Reilly Media, Inc.
1005 Gravenstein Highway North, Sebastopol, CA 95472
O’Reilly books may be purchased for educational, business,
or sales promotional use. For more information, contact our
corporate/institutional sales department: 800-998-9938
or corporate@oreilly.com.
Print History:
October 2008: First Edition
September 2011: Second Edition
Executive Editor: Brian Jepson
Designer: Brian Scott
Indexer: Ellen Troutman Zaig
Illustrations: Elisa Canducci with Shawn Wallace
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc.
The Make: Projects series designations and related trade dress
are trademarks of O’Reilly Media, Inc. The trademarks of third
parties used in this work are the property of their respective
owners.
Important Message to Our Readers: Your safety is your own
responsibility, including proper use of equipment and safety gear,
and determining whether you have adequate skill and experi-
ence. Electricity and other resources used for these projects are
dangerous unless used properly and with adequate precautions,
including safety gear. Some illustrations do not depict safety
precautions or equipment, in order to show the project steps
more clearly. These projects are not intended for use by children.
Use of the instructions and suggestions in Getting Started with
Arduino is at your own risk. O’Reilly Media, Inc., and the author
disclaim all responsibility for any resulting damage, injury, or
expense. It is your responsibility to make sure that your activities
comply with applicable laws, including copyright.
ISBN: 978-1-449-309879
[LSI]
Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v
1 / Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1
Intended Audience. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
What Is Physical Computing? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 / The Arduino Way . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Prototyping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Tinkering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Patching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Circuit Bending . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Keyboard Hacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
We Love Junk! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Hacking Toys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Collaboration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3 / The Arduino Platform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
The Arduino Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
The Software (IDE) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Installing Arduino on Your Computer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Installing Drivers: Macintosh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Installing Drivers: Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Port Identiication: Macintosh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Port Identiication: Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .24
4 / Really Getting Started with Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Anatomy of an Interactive Device. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Sensors and Actuators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Blinking an LED. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Pass Me the Parmesan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Arduino Is Not for Quitters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Real Tinkerers Write Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
The Code, Step by Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
What We Will Be Building . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
What Is Electricity? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Using a Pushbutton to Control the LED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .40
How Does This Work? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
One Circuit, A Thousand Behaviours . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .43
5 / Advanced Input and Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Trying Out Other On/Off Sensors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Controlling Light with PWM. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Zgłoś jeśli naruszono regulamin