- •Acknowledgments
- •Preface
- •Who Should Read This Book
- •What’s in This Book
- •Arduino Uno and the Arduino Platform
- •Code Examples and Conventions
- •Online Resources
- •The Parts You Need
- •Starter Packs
- •Complete Parts List
- •1. Welcome to the Arduino
- •What You Need
- •What Exactly Is an Arduino?
- •Exploring the Arduino Board
- •Installing the Arduino IDE
- •Meeting the Arduino IDE
- •Hello, World!
- •Compiling and Uploading Programs
- •What If It Doesn’t Work?
- •Exercises
- •2. Creating Bigger Projects with the Arduino
- •What You Need
- •Managing Projects and Sketches
- •Changing Preferences
- •Using Serial Ports
- •What If It Doesn’t Work?
- •Exercises
- •3. Building Binary Dice
- •What You Need
- •Working with Breadboards
- •Using an LED on a Breadboard
- •First Version of a Binary Die
- •Working with Buttons
- •Adding Your Own Button
- •Building a Dice Game
- •What If It Doesn’t Work?
- •Exercises
- •4. Building a Morse Code Generator Library
- •What You Need
- •Learning the Basics of Morse Code
- •Building a Morse Code Generator
- •Fleshing Out the Morse Code Generator’s Interface
- •Outputting Morse Code Symbols
- •Installing and Using the Telegraph Class
- •Publishing Your Own Library
- •What If It Doesn’t Work?
- •Exercises
- •5. Sensing the World Around Us
- •What You Need
- •Measuring Distances with an Ultrasonic Sensor
- •Increasing Precision Using Floating-Point Numbers
- •Increasing Precision Using a Temperature Sensor
- •Creating Your Own Dashboard
- •What If It Doesn’t Work?
- •Exercises
- •What You Need
- •Wiring Up the Accelerometer
- •Bringing Your Accelerometer to Life
- •Finding and Polishing Edge Values
- •Building Your Own Game Controller
- •More Projects
- •What If It Doesn’t Work?
- •Exercises
- •7. Writing a Game for the Motion-Sensing Game Controller
- •Writing a GameController Class
- •Creating the Game
- •What If It Doesn’t Work?
- •Exercises
- •8. Generating Video Signals with an Arduino
- •What You Need
- •How Analog Video Works
- •Building a Digital-to-Analog Converter (DAC)
- •Connecting the Arduino to Your TV Set
- •Using the TVout Library
- •Building a TV Thermometer
- •Working with Graphics in TVout
- •What If It Doesn’t Work?
- •Exercises
- •9. Tinkering with the Wii Nunchuk
- •What You Need
- •Wiring a Wii Nunchuk
- •Talking to a Nunchuk
- •Building a Nunchuk Class
- •Using Our Nunchuk Class
- •Creating Your Own Video Game Console
- •Creating Your Own Video Game
- •What If It Doesn’t Work?
- •Exercises
- •10. Networking with Arduino
- •What You Need
- •Using Your PC to Transfer Sensor Data to the Internet
- •Registering an Application with Twitter
- •Tweeting Messages with Processing
- •Communicating Over Networks Using an Ethernet Shield
- •Using DHCP and DNS
- •What If It Doesn’t Work?
- •Exercises
- •11. Creating a Burglar Alarm with Email Notification
- •What You Need
- •Emailing from the Command Line
- •Emailing Directly from an Arduino
- •Detecting Motion Using a Passive Infrared Sensor
- •Bringing It All Together
- •What If It Doesn’t Work?
- •Exercises
- •What You Need
- •Understanding Infrared Remote Controls
- •Grabbing Remote Control Codes
- •Cloning a Remote
- •Controlling Infrared Devices Remotely with Your Browser
- •Building an Infrared Proxy
- •What If It Doesn’t Work?
- •Exercises
- •13. Controlling Motors with Arduino
- •What You Need
- •Introducing Motors
- •First Steps with a Servo Motor
- •Building a Blaminatr
- •What If It Doesn’t Work?
- •Exercises
- •Current, Voltage, and Resistance
- •Electrical Circuits
- •Learning How to Use a Wire Cutter
- •Learning How to Solder
- •Learning How to Desolder
- •The Arduino Programming Language
- •Bit Operations
- •Learning More About Serial Communication
- •Serial Communication Using Various Languages
- •What Are Google Chrome Apps?
- •Creating a Minimal Chrome App
- •Starting the Chrome App
- •Exploring the Chrome Serial API
- •Writing a SerialDevice Class
- •Index
Learning How to Desolder • 247
As soon as the solder starts to flow, you’re safer, because the solder distributes heat automatically. Feed some more solder (not too much!) until you have a nice, shiny solder joint. The whole process shouldn’t take more than two to three seconds. When you’re finished, remove the iron tip quickly and give the joint a few seconds to cool down.
Repeat this for all six pin headers, and the result should look like this:
Test it by building the motion-sensing game controller, and play a video game to relax.
Congratulations! You have just finished your first soldering job!
Learning How to Desolder
Let’s face it: even if soldering isn’t that difficult, things can still go wrong. Sometimes you solder a part to the wrong place. In other cases you accidentally use too much solder and create unwanted connections. To correct such mistakes, you have to remove the excessive solder.
The following figure shows two of the most popular tools for desoldering. On the left you see a desoldering braid, and on the right you see a desoldering pump (also known as a solder sucker).
report erratum • discuss
Appendix 1. Electronics and Soldering Basics • 248
Both tools work the same in principle: you heat the solder you want to get rid of with the soldering iron, and then you use the tool to remove the molten solder. When you use the desoldering pump, you heat the solder until it melts, and then you press the pump’s button to suck the solder.
To desolder using braid, put the braid on top of the solder joint you’d like to remove. Then press the soldering iron’s tip to the braid and wait until the solder melts. The braid will suck the molten solder automatically.
Make sure that the distance between your fingers and the solder joint is reasonable, because the braid gets pretty hot. Also make sure you’re using a part of the braid that isn’t full of solder already.
This tutorial is only a starting point for your new shiny soldering career. You now know that soldering isn’t too difficult, and as a next step, you can try to build some beginner’s kits. All electronics stores offer them, and they usually come with soldering instructions, too. You can also find excellent tutorials and even videos on the Internet to build your skills.3
3.http://store.curiousinventor.com/guides/How_to_Solder
report erratum • discuss
APPENDIX 2
Advanced Arduino Programming
In reality, the Arduino programming language is nothing but C++, but it has some restrictions, and it uses a special tool suite. In this appendix, you’ll learn what your options are. Also, you’ll find a short section showing how bit operators work, because you need them often when working with sensors and other devices.
The Arduino Programming Language
The first sketches you’ll write for an Arduino might seem to be written in a special Arduino language, but they aren’t. To program the Arduino, you usually use plain old C/C++. Unfortunately, the Arduino doesn’t understand C or C++ code, so you have to compile the code on your PC or Mac into machine code suitable for the Arduino’s microcontroller. This process is called cross-compiling, and it’s the usual way of creating executable software for microcontrollers. You edit and compile the software on your PC, and then you transfer the machine code to the microcontroller.
In case of the Arduino, these microcontrollers are often part of the AVR family produced by a company named Atmel. To make software development for Atmel microcontrollers as easy as possible, Atmel has developed a whole tool chain based on the GNU compiler tools. All tools work like the originals, but they have been optimized for generating code for the Atmel microcontrollers.
For nearly all GNU development tools, such as gcc, ld, or as, there’s an AVR variant: avr-gcc, avr-ld, and so on. You can find them in the hardware/tools/avr/bin directory of the Arduino IDE.
The IDE is mainly a graphical wrapper that helps you avoid using the com- mand-line tools directly. Whenever you compile or upload a program using the IDE, it delegates all work to the AVR tools. As a serious software developer,
report erratum • discuss
Appendix 2. Advanced Arduino Programming • 250
you should turn on a more verbose output, so you can see all command-line tool invocations. Enable verbose output for both compilation and upload in the Preferences menu, as described in Changing Preferences, on page 26. Then load your blinking LED sketch and compile it. (We did this back at the start of our journey in Changing Preferences, on page 26).
The command invocations look weird at first because of the names of the many temporary files that are created. You should still be able to identify all compile and link steps necessary to build even a simple sketch like our blinking LED example. That’s the most important thing the Arduino team did: they hid all these nasty details well behind the IDE, so even people with no software development experience can program the Arduino. For programmers, it’s a good idea to work in verbose mode, because the best way to learn about all the AVR tools is to see them in action.
Upload the program to the Arduino now to see avrdude in action. This tool is responsible for loading code into the Arduino and can be used for programming many other devices, too. Interestingly, the AVR tools even make it possible to use the Arduino IDE for non-Arduino projects.
There’s another difference between Arduino programming and regular C++ code. When programming for the Arduino, you don’t define main yourself, because it is already defined in the libraries provided by the Arduino developers. As you might have guessed, it calls setup first and then runs the loop function in a loop. Since Arduino 1.0, it also calls serialEvent at the end of the loop function.
Further restrictions when programming C++ on AVR microcontrollers include the following:1
•You cannot use the Standard Template Library (STL) because it’s way too big for the small AVR microcontrollers.
•Exception handling isn’t supported. That’s why you see the -fno-exceptions switch often when the avr-gcc compiler is invoked.
•Dynamic memory management using new and delete isn’t supported.
In addition to all that, you should keep an eye on performance. C++ automatically creates a lot of functions (copy constructors, assignment operators, and so on) in the background that are rarely needed on the Arduino. Even with these restrictions, the Arduino supports a powerful subset of the C++ programming language. So there’s no excuse for sloppy coding!
1.http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_cplusplus
report erratum • discuss