Tải bản đầy đủ (.pdf) (512 trang)

C programming for arduino

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (10.42 MB, 512 trang )

icviet.vn


C Programming for Arduino

Learn how to program and use Arduino boards
with a series of engaging examples, illustrating
each core concept

Julien Bayle

BIRMINGHAM - MUMBAI

icviet.vn


C Programming for Arduino
Copyright © 2013 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is
sold without warranty, either express or implied. Neither the author, nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.



First published: May 2013

Production Reference: 1070513

Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-84951-758-4
www.packtpub.com

Cover Image by Asher Wishkerman ()

icviet.vn


Credits
Author

Copy Editors

Julien Bayle

Laxmi Subramanian
Sajeev Raghavan

Reviewers

Insiya Morbiwala


Darwin Grosse

Brandt D'mello

Pradumn Joshi

Aditya Nair

Phillip Mayhew
Glenn D. Reuther
Steve Spence

Alfida Paiva
Project Coordinator
Leena Purkait

Acquisition Editor
Edward Gordon

Proofreaders

Erol Staveley

Claire Cresswell-Lane
Martin Diver

Lead Technical Editor
Susmita Panda


Indexer
Tejal R. Soni

Technical Editors
Worrell Lewis

Graphics

Varun Pius Rodrigues

Ronak Dhruv

Lubna Shaikh
Production Coordinator

Sharvari Baet

Pooja Chiplunkar
Cover Work
Pooja Chiplunkar

icviet.vn


About the Author
Julien Bayle completed his Master's degree in Biology and Computer Sciences

in 2000. After several years working with pure IT system design, he founded
Design the Media in early 2010 in order to provide his own courses, training, and
tools for art fields. As a digital artist, he has designed some huge new media art

installations, such as the permanent exhibition of La Maison des Cinématographies
de la Méditerranée (Château de la Buzine) in Marseille, France, in 2011. He has
also worked as a new media technology consultant for some private and public
entities. As a live AV performer, he plays his cold electronic music right from
New York to Marseille where he actually lives. The Arduino framework is one
of his first electronic hardware studies since early 2005, and he also designed the
famous protodeck controller with various open source frameworks. As an Art and
Technology teacher also certified by Ableton in 2010, he teaches a lot of courses
related to the digital audio workstation Ableton Live, the real-time graphical
programming framework Max 6, and Processing and Arduino.
As a minimalist digital artist, he works at the crossroads between sound, visual,
and data. He explores the relationship between sounds and visuals through his
immersive AV installations, his live performances, and his released music. His work,
often described as "complex, intriguing, and relevant", tries to break classical codes
to bring his audience a new vision of our world through his pure digital and realtime-generated stimuli.
He's deeply involved in the open source community and loves to share and
provide workshops and masterclasses online and on-site too. His personal website
is .

icviet.vn


Acknowledgement
I would like to thank my sweet wife Angela and our daughter Alice for having been
my unconditional supporters. Special thanks to our son Max, who was born between
the writing of Chapter 11 and Chapter 12!
I would also like to thank my two great friends Laurent Boghossian and Denis
Laffont because they were there for me all through the course of this huge project
with their advices, jokes, and unconditional support.
I would like to extend many thanks to two very nice persons and friends whom I

asked to review this book for me: Glenn D. Reuther and Darwin Grosse.
I thank the following great programmers who coded some libraries that have been
used in this book: Marcello Romani (the SimpleTimer library), Juan Hernandez (the
ShiftOutX library), Thomas Ouellet Fredericks (the Bounce library), Tim Barrass (the
Mozzi library), David A. Mellis from MIT (the PCM library), Michael Margolis and
Bill Perry (the glcd-arduino library), and Markku Rossi (Arduino Twitter Library
with OAuth Support).
I want to thank the creators of the following powerful frameworks used in this book
besides the Arduino framework itself: Max 6, Processing, and Fritzing.
Lastly, I'd like to hug Massimo Banzi and Arduino's project team for having initiated
this great project and inspired us so much.

icviet.vn


About the Reviewers
Darwin Grosse is the Director of Education and Services with Cycling '74, the

developer of the Max media programming system. He is also an Adjunct Professor
at the University of Denver, and teaches sonic art, programming, and hardware
interface in the Emerging Digital Practices department.

Pradumn Joshi is currently pursuing his Bachelor's degree in Electrical
Engineering from NIT Surat. He is an avid elocutionist and debate enthusiast, and
is also interested in economics, freelance writing, and Western music. His area
of technical expertise lies in open source hardware development and embedded
systems.

Phillip Mayhew is a Bachelor of Science in Computer Science from North
Carolina State University. He is the Founder and Managing Principal of Rextency

Technologies LLC based in Statesville, North Carolina. His primary expertise is in
software application performance testing and monitoring.

icviet.vn


Glenn D. Reuther's own personal journey and fascination began with music
technology during the 1970s with private lessons in "Electronic Music Theory and
Acoustic Physics". He then attended Five Towns College of Music in NY and has
been a home studio operator since 1981, playing multiple instruments and designing
a few devices for his studio configuration.
Since then, he has spent several years with Grumman Aerospace as a Ground and
Flight Test Instrumentation Technician, before moving through to the IT field.
Beginning with an education in Computer Operations and Programming, he went
on to work as network and system engineer having both Microsoft and Novell
certifications. After over 10 years at the University of Virginia as Sr. Systems
Engineer, he spends much of his spare time working with the current state of music
technology. His website is .
He is also the author of "One Complete Revelation", a photo journal of his ninemonth trek throughout Europe during the early 90s.
I would like to thank the author for his friendship, and I would
also like to thank my wonderful wife Alice and son Glenn for their
patience, understanding, and support during the editing process of
this book.

Steve Spence has been a veteran of the IT industry for more than 20 years,

specializing in network design and security. Currently he designs microcontrollerbased process controls and database-driven websites. He lives off grid and teaches
solar and wind power generation workshops. He's a former firefighter and rescue
squad member, and a current Ham Radio operator.
In the past, he's been a technical reviewer of various books on alternative fuels

(From the Fryer to the Fuel Tank, Joshua Tickell) and authored DIY alternative
energy guides.

icviet.vn


www.PacktPub.com
Support files, eBooks, discount offers
and more

You might want to visit www.PacktPub.com for support files and downloads related to
your book.
Did you know that Packt offers eBook versions of every book published, with PDF and
ePub files available? You can upgrade to the eBook version at www.PacktPub.com and
as a print book customer, you are entitled to a discount on the eBook copy. Get in touch
with us at for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up
for a range of free newsletters and receive exclusive discounts and offers on Packt books
and eBooks.
TM

 

Why Subscribe?




Fully searchable across every book published by Packt
Copy and paste, print and bookmark content

On demand and accessible via web browser

Free Access for Packt account holders

If you have an account with Packt at www.PacktPub.com, you can use this to access
PacktLib today and view nine entirely free books. Simply use your login credentials for
immediate access.

icviet.vn


Table of Contents













Installing drivers for Arduino Duemilanove, Nano, or Diecimilla
What is electricity?
Voltage
Current and power
What are resistors, capacitors, and so on?

Wiring things and Fritzing
What is Fritzing?

Power supply fundamentals
Hello LED!

What do we want to do exactly?
How can I do that using C code?
Let's upload the code, at last!

Summary

icviet.vn

1
7

7
8
11
13
15
15
16
16
19
19
20
20
21

21
22
23

25

27
28

29
29
34

34


Table of Contents

Chapter 2: First Contact with C

An introduction to programming
Different programming paradigms
Programming style
C and C++?
C is used everywhere
Arduino is programmed with C and C++
The Arduino native library and other libraries
Discovering the Arduino native library
Other libraries included and not directly provided
Some very useful included libraries

Some external libraries

Checking all basic development steps
Using the serial monitor
Baud rate
Serial communication with Arduino
Serial monitoring
Making Arduino talk to us
Adding serial communication to Blink250ms
Serial functions in more detail

35
35
37
37
38
38
39
39
40
43

43
44

44
46
47
47
48

49
49
53

Serial.begin()53
Serial.print() and Serial.println()
53

Digging a bit…
53
Talking to the board from the computer
54
Summary54

Chapter 3: C Basics – Making You Stronger
Approaching variables and types of data
What is a variable?
What is a type?
The roll over/wrap concept

Declaring and defining variables

55
55
56
56

58

58


Declaring variables
Defining variables

58
59

String60
String definition is a construction
61
Using indexes and search inside String
61

charAt()61
indexOf() and lastIndexOf()
62
startsWith() and endsWith()
63

Concatenation, extraction, and replacement

63

Concatenation64
Extract and replace
65
[ ii ]


Table of Contents


Other string functions

68

Testing variables on the board

68

toCharArray()68
toLowerCase() and toUpperCase()
68
trim()68
length()68
Some explanations

71

The scope concept
72
static, volatile, and const qualifiers
73
static74
volatile75
const75
Operators, operator structures, and precedence
76
Arithmetic operators and types
76
Character types

Numerical types

76
77

Condensed notations and precedence
Increment and decrement operators
Type manipulations
Choosing the right type
Implicit and explicit type conversions

77
78
79
79
80

Comparing values and Boolean operators
Comparison expressions
Combining comparisons with Boolean operators

82
82
83

Adding conditions in the code
if and else conditional structure
switch…case…break conditional structure
Ternary operator
Making smart loops for repetitive tasks

for loop structure

86
86
89
91
91
91

Implicit type conversion
Explicit type conversion

Combining negation and comparisons

Playing with increment
Using imbricated for loops or two indexes

80
82

84

93
93

while loop structure
95
do…while loop structure
96
Breaking the loops

96
Infinite loops are not your friends
97
Summary98

[ iii ]


Table of Contents

Chapter 4: Improve Programming with Functions,
Math, and Timing
Introducing functions
Structure of a function

Creating function prototypes using the Arduino IDE
Header and name of functions
Body and statements of functions

Benefits of using functions

Easier coding and debugging
Better modularity helps reusability
Better readability

99

99
100


100
100
101

103

103
104
105

C standard mathematical functions and Arduino
Trigonometric C functions in the Arduino core

105
106

Exponential functions and some others
Approaching calculation optimization
The power of the bit shift operation

110
110
111

Some prerequisites
Trigonometry functions

What are bit operations?
Binary numeral system
AND, OR, XOR, and NOT operators

Bit shift operations
It is all about performance

106
109

111
111
112
113
114

The switch case labels optimization techniques

114

The smaller the scope, the better the board
The Tao of returns

115
116

Secrets of lookup tables

117

Optimizing the range of cases
Optimizing cases according to their frequency

The direct returns concept

Use void if you don't need return

Table initialization
Replacing pure calculation with array index operations

The Taylor series expansion trick
The Arduino core even provides pointers
Time measure
Does the Arduino board own a watch?
The millis() function
The micros() function

Delay concept and the program flow

What does the program do during the delay?
The polling concept – a special interrupt case
The interrupt handler concept
What is a thread?
A real-life polling library example

114
115

116
117
118
119

119
120

121
121

121
123

124

124
127
128
129
130

Summary134
[ iv ]


Table of Contents

Chapter 5: Sensing with Digital Inputs
Sensing the world
Sensors provide new capacities
Some types of sensors

135
135
136

136


Quantity is converted to data
Data has to be perceived
What does digital mean?
Digital and analog concepts
Inputs and outputs of Arduino
Introducing a new friend – Processing
Is Processing a language?
Let's install and launch it
A very familiar IDE

137
138
138
138
139
140
140
141
142

Checking an example
Processing and Arduino
Pushing the button
What is a button, a switch?

145
149
150
150


Alternative IDEs and versioning

Different types of switches

145

150

A basic circuit

150

The pull-up and pull-down concept

153

Making Arduino and Processing talk

155

Wires151
The circuit in the real world
151
The pseudocode
The code

The communication protocol
The Processing code
The new Arduino firmware talk-ready


154
154
155
157
163

Playing with multiple buttons
165
The circuit
166
The Arduino code
168
The Processing code
170
Understanding the debounce concept
173
What? Who is bouncing?
173
How to debounce
174
Summary177

Chapter 6: Sensing the World – Feeling with Analog Inputs
Sensing analog inputs and continuous values
How many values can we distinguish?
Reading analog inputs

The real purpose of the potentiometer
Changing the blinking delay of an LED with a potentiometer

[v]

179
180
180
181

181
182


Table of Contents
How to turn the Arduino into a low voltage voltmeter?

Introducing Max 6, the graphical programming framework
A brief history of Max/MSP
Global concepts
What is a graphical programming framework?
Max, for the playground
MSP, for sound
Jitter, for visuals
Gen, for a new approach to code generation
Summarizing everything in one table

Installing Max 6
The very first patch

Playing sounds with the patch

Controlling software using hardware

Improving the sequencer and connecting Arduino
Let's connect Arduino to Max 6
The serial object in Max 6
Tracing and debugging easily in Max 6
Understanding Arduino messages in Max 6
What is really sent on the wire?
Extracting only the payload?
ASCII conversions and symbols
Playing with sensors
Measuring distances
Reading a datasheet?
Let's wire things
Coding the firmware
Reading the distance in Max 6

Measuring flexion

Resistance calculations

Sensing almost everything
Multiplexing with a CD4051 multiplexer/demultiplexer
Multiplexing concepts
Multiple multiplexing/demultiplexing techniques
Space-division multiplexing
Frequency-division multiplexing
Time-division multiplexing

The CD4051B analog multiplexer

184


186
187
189
189
190
193
194
196
198

198
199

201

203
203

203
204
206
206
209
211
212
214
214
215
217

218
220

222

224

226
226
227
227

228
228
229

230

What is an integrated circuit?
Wiring the CD4051B IC?
Supplying the IC
Analog I/O series and the common O/I
Selecting the digital pin

230
231
232
232
233


Summary237

[ vi ]


Table of Contents

Chapter 7: Talking over Serial

239

Synchronous or asynchronous
Duplex mode
Peering and bus
Data encoding

241
241
242
243

Serial communication
Serial and parallel communication
Types and characteristics of serial communications

Multiple serial interfaces
The powerful Morse code telegraphy ancestor
The famous RS-232
The elegant I2C
The synchronous SPI

The omnipresent USB

239
240
241

244
244

244
246
247
248

Summary251

Chapter 8: Designing Visual Output Feedback
Using LEDs
Different types of LEDs
Monochromatic LEDS
Polychromatic LEDs

Remembering the Hello LED example
Multiple monochromatic LEDs

Two buttons and two LEDs
Control and feedback coupling in interaction design
The coupling firmware
More LEDs?


Multiplexing LEDs
Connecting 75HC595 to Arduino and LEDs
Firmware for shift register handling
Global shift register programming pattern
Playing with chance and random seeds

Daisy chaining multiple 74HC595 shift registers
Linking multiple shift registers
Firmware handling two shift registers and 16 LEDs
Current short considerations

253
254
254

255
255

256
258

258
260
263
265

265
266
268


270
271

272

273
274
278

Using RGB LEDs
Some control concepts
Different types of RGB LEDs
Lighting an RGB LED

279
279
280
281

Building LED arrays
A new friend named transistor
The Darlington transistors array, ULN2003

284
285
286

Red, Green, and Blue light components and colors
Multiple imbricated for() loops


[ vii ]

282
283


Table of Contents

The LED matrix
Cycling and POV
The circuit
The 3 x 3 LED matrix code
Simulating analog outputs with PWM
The pulse-width modulation concept
Dimming an LED
A higher resolution PWM driver component

287
289
290
291
295
296
297

298

Quick introduction to LCD
299
HD44780-compatible LCD display circuit

301
Displaying some random messages
302
Summary304

Chapter 9: Making Things Move and Creating Sounds
Making things vibrate
The piezoelectric sensor
Wiring a vibration motor
Firmware generating vibrations
Higher current driving and transistors
Controlling a servo
When do we need servos?
How to control servos with Arduino
Wiring one servo
Firmware controlling one servo using the Servo library
Multiple servos with an external power supply
Three servos and an external power supply
Driving three servos with firmware
Controlling stepper motors
Wiring a unipolar stepper to Arduino
Firmware controlling the stepper motor
Air movement and sounds
What actually is sound?
How to describe sound
Microphones and speakers
Digital and analog domains
How to digitalize sound
How to play digital bits as sounds


How Arduino helps produce sounds
Playing basic sound bits
Wiring the cheapest sound circuit
Playing random tones
Improving the sound engine with Mozzi
[ viii ]

305
306
306
307
308
309
311
311
311
312
313
314
315
316
318
318
320
323
323
324
325
326


326
328

329
329
330
331
332


Table of Contents

Setting up a circuit and Mozzi library
An example sine wave

333
335

Frequency modulation of a sine wave

338

Oscillators336
Wavetables336
Adding a pot
Upgrading the firmware for input handling

339
340


Controlling the sound using envelopes and MIDI
343
An overview of MIDI
343
MIDI and OSC libraries for Arduino
344
Generating envelopes
344
Implementing envelopes and MIDI
346
Wiring a MIDI connector to Arduino
352
Playing audio files with the PCM library
355
The PCM library
355
WAV2C – converting your own sample
356
Wiring the circuit
358
Other reader libraries
359
Summary360

Chapter 10: Some Advanced Techniques
Data storage with EEPROMs
Three native pools of memory on the
Arduino boards

Writing and reading with the EEPROM core library


361
361
361

362

External EEPROM wiring
Reading and writing to the EEPROM
Using GPS modules
Wiring the Parallax GPS receiver module
Parsing GPS location data
Arduino, battery, and autonomy
Classic cases of USB power supplying
Supplying external power

364
366
368
368
371
377
377
378

Power adapter for Arduino supply
How to calculate current consumption
Drawing on gLCDs
Wiring the device
Demoing the library

Some useful methods' families

380
381
382
383
384
385

Supplying with batteries

Global GLCD methods
Drawing methods
Text methods

[ ix ]

378

385
385
386


Table of Contents

Using VGA with the Gameduino Shield
387
Summary389


Chapter 11: Networking

An overview of networks
Overview of the OSI model
Protocols and communications
Data encapsulation and decapsulation
The roles of each layer
Physical layer
Data link layer
Network layer
Transport layer
Application/Host layers

Some aspects of IP addresses and ports
The IP address
The subnet
The communication port

Wiring Arduino to wired Ethernet
Making Processing and Arduino communicate over Ethernet
Basic wiring
Coding network connectivity implementation
in Arduino
Coding a Processing Applet communicating
on Ethernet

391
391
392
392

393
394

394
395
396
396
397

398

398
398
399

399
401

401
402
406

Some words about TCP
Bluetooth communications
Wiring the Bluetooth module
Coding the firmware and the Processing applet
Playing with Wi-Fi
What is Wi-Fi?

407

408
409
410
412
412

The Arduino Wi-Fi shield
Basic Wi-Fi connection without encryption
Arduino Wi-Fi connection using WEP or WPA2

414
415
418

Infrastructure mode
Ad hoc mode
Other modes

Using WEP with the Wi-Fi library
Using WPA2 with the Wi-Fi library

Arduino has a (light) web server
Tweeting by pushing a switch
An overview of APIs
Twitter's API
Using the Twitter library with OAuth support
Grabbing credentials from Twitter

[x]


413
413
414

418
418

419
422
422
422
423

423


Table of Contents
Coding a firmware connecting to Twitter

423

Summary428

Chapter 12: Playing with the Max 6 Framework

Communicating easily with Max 6 – the [serial] object
The [serial] object
Selecting the right serial port
The polling system
Parsing and selecting data coming

from Arduino
The readAll firmware
The ReadAll Max 6 patch
Requesting data from Arduino
Parsing the received data
Distributing received data and other tricks

429
429
430
431
432
432
433
434

435
435
437

Creating a sound-level meter with LEDs
444
The circuit
444
The Max 6 patch for calculating sound levels
446
The firmware for reading bytes
448
The pitch shift effect controlled by hand
449

The circuit with the sensor and the firmware
449
The patch for altering the sound and parsing Arduino messages
450
Summary452

Chapter 13: Improving your C Programming and
Creating Libraries
Programming libraries
The header file
The source file
Creating your own LED-array library
Wiring six LEDs to the board
Creating some nice light patterns
Designing a small LED-pattern library
Writing the LEDpatterns.h header
Writing the LEDpatterns.cpp source
Writing the keyword.txt file

Using the LEDpatterns library
Memory management
Mastering bit shifting
Multiplying/dividing by multiples of 2
Packing multiple data items into bytes
Turning on/off individual bits in a control and port register
Reprogramming the Arduino board
[ xi ]

453
453

455
457
458
458
459
461

461
462
463

464
466
467
467
467
468
469


Table of Contents

Summary471
Conclusion471
About Packt Publishing
473
About Packt Open Source
473
Writing for Packt
473


Index477

[ xii ]


Preface
Our futuristic world is full of smart and connected devices. Do-it-yourself
communities have always been fascinated by the fact that each one could design
and build its own smart system, dedicated or not, for specific tasks. From small
controllers switching on the lights when someone is detected to a smart sofa sending
e-mails when we sit on them, cheap electronics projects have become more and
more easy to create and, for contributing to this, we all have to thank the team, who
initiated the Arduino project around 2005 in Ivrea, Italy.
Arduino's platform is one of the most used open source hardware in the world. It
provides a powerful microcontroller on a small printed circuit board with a very
small form factor. Arduino users can download the Arduino Integrated Development
Environment (IDE) and code their own program using the C/C++ language and the
Arduino Core library that provides a lot of helpful functions and features.
With C Programming for Arduino, users will learn enough of C/C++ to be able to
design their own hardware based on Arduino. This is an all-in-one book containing
all the required theory illustrated with concrete examples. Readers will also learn
about some of the main interaction design and real-time multimedia frameworks
such as Processing and the Max 6 graphical programming framework.
C Programming for Arduino will teach you the famous "learning-by-making" way
of work that I try to follow in all of my courses from Max 6 to Processing and
Ableton Live.
Lastly, C Programming for Arduino will open new fields of knowledge by looking at
the input and output concept, communication and networking, sound synthesis, and
reactive systems design. Readers will learn the necessary skills to be able to continue

their journey by looking at the modern world differently, not only as a user but also
as a real maker.
For more details, you can visit my website for the book at
/>

Preface

What this book covers

Chapter 1, Let's Plug Things, is your first contact with Arduino and microcontroller
programming. We will learn how to install the Arduino Integrated Development
Environment on our computer and how to wire and test the development toolchain
to prepare the further study.
Chapter 2, First Contact with C, covers the relation between the software and the
hardware. We will introduce the C language, understand how we can compile it, and
then learn how to upload our programs on the Arduino Board. We will also learn all
the steps required to transform a pure idea into firmware for Arduino.
Chapter 3, C Basics—Making You Stronger, enters directly into the C language. By
learning basics, we learn how to read and write C programs, discovering the
datatype, basic structures, and programming blocks.
Chapter 4, Improving Programming with Functions, Math, and Timing, provides the first
few keys to improve our C code, especially by using functions. We learn how to
produce reusable and efficient programming structures.
Chapter 5, Sensing with Digital Inputs, introduces digital inputs to Arduino. We will
learn how to use them and understand their inputs and outputs. We will also see
how Arduino uses electricity and pulses to communicate with everything.
Chapter 6, Sensing the World—Feeling with Analog Inputs, describes the analog inputs
of Arduino through different concrete examples and compares them to digital pins.
Max 6 frameworks are introduced in this chapter as one of the ideal companions for
Arduino.

Chapter 7, Talking over Serial, introduces the communication concept, especially
by teaching about Serial communication. We will learn how to use the Serial
communication console as a powerful debugging tool.
Chapter 8, Designing Visual Output Feedback, talks about the outputs of Arduino and
how we can use them to design visual feedback systems by using LEDs and their
systems. It introduces the powerful PWM concept and talks about LCD displays too.
Chapter 9, Making Things Move and Creating Sounds, shows how we can use the
Arduino's outputs for movement-related projects. We talk about motors and
movement and also about air vibration and sound design. We describe some basics
about digital sound, MIDI, and the OSC protocol, and have fun with a very nice
PCM library providing the feature of reading digitally encoded sound files from
Arduino itself.

[2]


Preface

Chapter 10, Some Advanced Techniques, delivers many advanced concepts, from
data storage on EEPROM units, and communication between multiple Arduino
boards, to the use of GPS modules. We will also learn how to use our Arduino
board with batteries, play with LCD displays, and use the VGA shield to plug the
microcontroller to a typical computer screen.
Chapter 11, Networking, introduces the network concepts we need to understand in
order to use our Arduino on Ethernet, wired or wireless networks. We will also use
a powerful library that provides us a way to tweet messages directly by pushing a
button on our Arduino, without using any computer.
Chapter 12, Playing with the Max 6 Framework, teaches some tips and techniques we
can use with the Max 6 graphical programming framework. We will completely
describe the use of the Serial object and how to parse and select data coming from

Arduino to the computer. We will design a small sound-level meter using both real
LEDs and Max 6 and finish by designing a Pitch shift sound effect controlled by our
own hand and a distance sensor.
Chapter 13, Improving Your C Programming and Creating Libraries, is the most advanced
chapter of the book. It describes some advanced C concepts that can be used to make
our code reusable, more efficient, and optimized, through some nice and interesting
real-world examples.
Appendix provides us with details of data types in C programming language,
operator precedence in C and C++, important Math functions, Taylor series for
calculation optimizations, an ASCII table, instructions for installing a library, and a
list of components' distributors.
Appendix can be downloaded from />files/downloads/7584OS_Appendix.pdf.

What you need for this book

If you want to take benefits of each example in this book, the following software
is required:
• The Arduino environment (free, />This is required for all operations related to Arduino programming.
• Fritzing (free, This is an open source
environment that helps us design circuits.
• Processing (free, This is an open
source framework for rapid prototyping using Java. Some examples use it as
a communication partner for our Arduino boards.
[3]


Preface

• The Max 6 framework (trial version of 30 days, />downloads). This framework is a huge environment that is used in this
book too.

Some other libraries are also used in this book. Every time they are needed, the
example description explains where to download them from and how to install
them on our computer.

Who this book is for

This book is for people who want to master do-it-yourself electronic hardware
making with Arduino boards. It teaches everything we need to know to program
firmware using C and how to connect the Arduino to the physical world, in
great depth. From interactive-design art school students to pure hobbyists, from
interactive installation designers to people wanting to learn electronics by entering
a huge and growing community of physical computing programmers, this book will
help everyone interested in learning new ways used to design smart objects, talking
objects, efficient devices, and autonomous or connected reactive gears.
This book opens new vistas of learning-by-making, which will change readers' lives.

Conventions

In this book, you will find a number of styles of text that distinguish between
different kinds of information. Here are some examples of these styles, and an
explanation of their meaning.
Code words in text are shown as follows: "We can include other contexts through the
use of the include directive."
A block of code is set as follows:
[default]
exten => s,1,Dial(Zap/1|30)
exten => s,2,Voicemail(u100)
exten => s,102,Voicemail(b100)
exten => i,1,Voicemail(s0)


When we wish to draw your attention to a particular part of a code block, the
relevant lines or items are set in bold:
[default]
exten => s,1,Dial(Zap/1|30)
exten => s,2,Voicemail(u100)
[4]


Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×