Arduino Sketches Tools and Techniques For Programming Wizardry 1st Edition Langbridge Download
Arduino Sketches Tools and Techniques For Programming Wizardry 1st Edition Langbridge Download
https://ebookname.com/product/arduino-sketches-tools-and-
techniques-for-programming-wizardry-1st-edition-langbridge/
https://ebookname.com/product/ruby-wizardry-an-introduction-to-
programming-for-kids-1st-edition-weinstein/
https://ebookname.com/product/programming-interactivity-a-guide-
for-processing-arduino-and-openframeworks-1st-edition-joshua-
noble/
https://ebookname.com/product/programming-arduino-with-
labview-1st-edition-marco-schwartz/
https://ebookname.com/product/zionism-and-land-tenure-in-mandate-
palestine-aida-essaid/
Local Area Networks 4th Edition Peter Hodson
https://ebookname.com/product/local-area-networks-4th-edition-
peter-hodson/
https://ebookname.com/product/renal-nursing-a-practical-
approach-1st-edition-bobbee-terrill/
https://ebookname.com/product/historical-dictionary-of-the-cold-
war-2nd-edition-edition-joseph-smith/
https://ebookname.com/product/indigenous-african-
institutions-2nd-edition-george-b-n-ayittey/
https://ebookname.com/product/practical-art-of-motion-picture-
sound-4th-edition-david-lewis-yewdall/
Fact Oriented Modeling with FCO IM Capturing Business
Semantics in Data Models with Fully Communication
Oriented Information Modeling 1st Edition Jan Pieter
Zwart
https://ebookname.com/product/fact-oriented-modeling-with-fco-im-
capturing-business-semantics-in-data-models-with-fully-
communication-oriented-information-modeling-1st-edition-jan-
pieter-zwart/
A-PDF Scan Optimizer Demo. Purchase from www.A-PDF.com to remove the watermark
Arduino™ Sketches
James A. Langbridge
Published by
John Wiley & Sons, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2015 by John Wiley & Sons, Inc., Indianapolis, Indiana
ISBN: 978-1-118-91960-6
ISBN: 978-1-118-91962-0 (ebk)
ISBN: 978-1-118-91969-9 (ebk)
10 9 8 7 6 5 4 3 2 1
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or
by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted
under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permis-
sion of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright
Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to
the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc.,
111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley
.com/go/permissions.
Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or war-
ranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all
warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be
created or extended by sales or promotional materials. The advice and strategies contained herein may not
be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in
rendering legal, accounting, or other professional services. If professional assistance is required, the services
of a competent professional person should be sought. Neither the publisher nor the author shall be liable for
damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation
and/or a potential source of further information does not mean that the author or the publisher endorses
the information the organization or website may provide or recommendations it may make. Further, readers
should be aware that Internet websites listed in this work may have changed or disappeared between when
this work was written and when it is read.
For general information on our other products and services please contact our Customer Care Department
within the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included
with standard print versions of this book may not be included in e-books or in print-on-demand. If this book
refers to media such as a CD or DVD that is not included in the version you purchased, you may download
this material at http://booksupport.wiley.com. For more information about Wiley products, visit
www.wiley.com.
Library of Congress Control Number: 2014948616
Trademarks: Wiley and the Wiley logo are trademarks or registered trademarks of John Wiley & Sons, Inc.
and/or its affiliates, in the United States and other countries, and may not be used without written permission.
Arduino is a trademark of Arduino, LLC. All other trademarks are the property of their respective owners.
John Wiley & Sons, Inc. is not associated with any product or vendor mentioned in this book.
To my wonderful daughter, Eléna: I have to admit, I’m addicted to your laugh and
smile, something you did every time I showed you the projects I was working on.
Again you found a way of telling me when I needed to stop and spend more time
playing with you (by unplugging and randomly rewiring my breadboard projects),
but coming back home at the end of a long and difficult day to see you smiling and
jumping into my arms gave me more energy than you can imagine.
James A. Langbridge does not like talking about himself in the third person,
but he will try anyway. James was born in Singapore and followed his parents
to several countries before settling down in Nantes, France, where he lives with
his partner and their daughter.
James is an embedded systems consultant and has worked for more than 15
years on industrial, military, mobile telephony, and aviation security systems.
He works primarily on low-level development, creating bootloaders or opti-
mizing routines in assembly, making the most of small processors. When not
on contract, James trains engineers on embedded systems, or he makes new
gizmos, much to the dismay of his partner.
James wrote his first computer program at age 6 and has never stopped tin-
kering since. He began using Apple IIs, ZX80s and ZX81s, and then moved to
BBC Micros and the Amiga before finally having no other option but to use PCs.
vii
Scott Fitzgerald is an artist and educator working with technology and its rela-
tionship to people, approaching digital tools from a human-centric perspective.
His work has been featured in numerous books and publications such as The
New York Times and IDN Magazine. He has edited several books on Arduino
and communication technologies, is the author of the book that accompanies
the Arduino Starter Kit, and is responsible for documentation of the Arduino
platform at http://arduino.cc. Scott is currently an assistant arts professor and
head of the interactive media program at New York University Abu Dhabi. He
enjoys tormenting his cat and partner with early morning work sessions.
ix
xi
Writing a book is a huge project. When I was at school, I used to shudder at the
thought of writing 1,000 words for an essay, and I was alone to do it. This book
is, of course, much longer, and I enjoyed every minute of it, thanks to the team
of professionals who helped me every step of the way. Take a quick look at the
people involved in this project, and you will soon see what I’m talking about.
I can’t thank everyone involved personally; there are just too many people,
but there are a few names that I will never forget. My thanks go out to Christina
Haviland, my project editor. When I knew that I would be working with her
again, I was thrilled. She actually managed to put up with me for the entire
duration and didn’t even shout at me when I was late, despite the fact that some
of the chapters were very, very late. I was also thrilled to know that I’d be work-
ing with San Dee Phillips, my copy editor. The job they did transforming raw
data coming out of my brain into something readable is outstanding. Then there
is Scott Fitzgerald, my technical editor, who made sure that I didn’t make any
mistakes. Believe me, nothing slipped by, and despite all the grumbling I did
when I received the corrections, thank you! This wouldn’t have been possible
without you.
I would also like to thank Atmel for their time and effort, for the engineers
I was in contact with to get more information, and to Tom Vu who kept on
encouraging me along the way and sending me new evaluation boards to play
with. My thanks also go out to Silicon Labs for its excellent UV sensor that is
presented in this book and for the time it spent helping me. Thanks to Materiel
.net who managed to get me a new computer, camera, and components in record
time when mine broke, allowing me to get the job done. Your coffee mug is still
on my desk!
xiii
Of course, this book would not have been possible without the amazing
people at Arduino. I don’t know if they know just how much they have changed
the world of makers. Your boards have brought back the joy I had in creating
gizmos and contraptions.
This has been a huge adventure, and I’ve met a lot of amazing people along
the way. Thank you to every one of you—for your time, your suggestions, and
your encouraging messages.
Introduction xxix
Part I Introduction to Arduino 1
Chapter 1 Introduction to Arduino 3
Chapter 2 Programming for the Arduino 25
Chapter 3 Electronics Basics 45
Part 2 Standard Libraries 63
Chapter 4 The Arduino Language 65
Chapter 5 Serial Communication 81
Chapter 6 EEPROM 101
Chapter 7 SPI 117
Chapter 8 Wire 133
Chapter 9 Ethernet 149
Chapter 10 WiFi 169
Chapter 11 LiquidCrystal 191
Chapter 12 SD 207
Chapter 13 TFT 225
Chapter 14 Servo 241
Chapter 15 Stepper 253
Chapter 16 Firmata 261
xv
Introduction xxix
Part I Introduction to Arduino 1
Chapter 1 Introduction to Arduino 3
Atmel AVR 5
The Arduino Project 7
The ATmega Series 8
The ATmega Series 8
The ATtiny Series 8
Other Series 9
The Different Arduinos 9
Arduino Uno 10
Arduino Leonardo 10
Arduino Ethernet 11
Arduino Mega 2560 11
Arduino Mini 13
Arduino Micro 13
Arduino Due 13
LilyPad Arduino 14
Arduino Pro 16
Arduino Robot 16
Arduino Esplora 18
Arduino Yún 18
Arduino Tre 19
Arduino Zero 19
Your Own Arduino? 20
Shields 20
What Is a Shield? 20
The Different Shields 21
xvii
Using Transistors 56
Breadboards 56
Inputs and Outputs 57
Connecting a Light-Emitting Diode 58
Calculation 58
Software 59
Hardware 60
What Now? 61
Summary 61
Part II Standard Libraries 63
Chapter 4 The Arduino Language 65
I/O Functions 65
Digital I/O 65
pinMode() 66
digitalRead() 66
digitalWrite() 67
Analog I/O 67
analogRead() 68
analogWrite() 68
Generating Audio Tones 69
tone() 69
noTone() 69
Reading Pulses 69
pulseIn() 70
Time Functions 70
delay() 70
delayMicroseconds() 71
millis() 71
micros() 71
Mathematical Functions 72
min() 72
max() 72
constrain() 73
abs() 73
map() 73
pow() 74
sqrt() 74
random() 74
Trigonometry 75
sin() 76
cos() 76
tan() 76
Constants 76
Interrupts 76
attachInterrupt() 77
detachInterrupt() 78
noInterrupts() 78
interrupts() 78
Summary 79
Chapter 5 Serial Communication 81
Introducing Serial Communication 82
UART Communications 84
Baud Rate 84
Data Bits 85
Parity 85
Stop Bits 86
Debugging and Output 86
Starting a Serial Connection 87
Writing Data 88
Sending Text 88
Sending Data 90
Reading Data 91
Starting Communications 91
Is Data Waiting? 91
Reading a Byte 92
Reading Multiple Bytes 92
Taking a Peek 93
Parsing Data 93
Cleaning Up 94
Example Program 95
SoftwareSerial 98
Summary 99
Chapter 6 EEPROM 101
Introducing EEPROM 101
The Different Memories on Arduino 103
The EEPROM Library 104
Reading and Writing Bytes 104
Reading and Writing Bits 105
Reading and Writing Strings 107
Reading and Writing Other Values 108
Example Program 110
Preparing EEPROM Storage 113
Adding Nonvolatile Memory 114
Summary 115
Chapter 7 SPI 117
Introducting SPI 118
SPI Bus 118
Comparison to RS-232 119
Configuration 119
Communications 120
T
HE establishment of Francesco Sforza as Duke of Milan had
virtually settled the affairs of Lombardy, for although the
Emperor and the French King refused to recognise his rights
to the Visconti succession, they deferred their respective claims upon
that duchy till a fitter season. The Angevine pretensions to the
crown of Naples were also in temporary abeyance, and the triple
tiara had passed from the turbulent Eugenius to Nicholas V., whose
early habits of scholarship continued undisturbed by ambitious
dreams. There thus seemed no element of contention left, and a
prolonged peace was the natural as well as the true policy of Italy.
But, in the words of Sanzi,
T
HOSE readers who have thus far followed our narrative of
Count Federigo's military career may perhaps regret that its
somewhat limited and monotonous interest should not have
been varied by glimpses of his domestic life. A prince whose
engagements were observed with rare fidelity, whose chivalrous
honour was happily combined with practical good sense and
unflinching justice, must have been almost necessarily a good
husband and kind master. But, in accordance with the habits of his
age and the calls of his condottiere profession, most of his time was
passed in the field, and unfortunately in those times few bards and
biographers considered any incense worth offering which did not
savour of
"The pomp and circumstance of glorious war."
His marriage with Gentile being hopelessly barren, he had followed
the example of his father by obtaining papal briefs of legitimation, in
1454, for his natural sons Buonconte and Antonio. With the latter we
shall make acquaintance by and by; the former, a youth of
remarkable promise, is supposed to have been his destined heir,[100]
but having been sent on a mission to Alfonso at Naples, in October,
1458, he died there of the plague; and another brother, Bernardino,
who had accompanied him on that journey, scarcely survived his
return. Berni, speaking from personal knowledge of these two
princes, applies to them Virgil's high-flown compliment to Marcellus:
—
"Ah, couldst thou break through Fate's severe decree,
A new Marcellus shall arise in thee!
Full canisters of fragrant lilies bring,
Mixed with the purple roses of the spring;
Let me with funeral flowers his body strew."[101]
"A maiden
With every grace and virtue rare endowed,
That heaven at intervals on earth vouchsafes,
In earnest of the bliss reserved on high."
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookname.com