The Arduino Programming Language
People sometimes get irritated when it comes to the language the Arduino gets pro-
grammed in. That’s mainly because the typical sample sketches look as if they were
written in a language that was exclusively designed for programming the Arduino.
But that’s not the case—it is plain old C++ (which implies that it supports C, too).
Most Arduino boards use an AVR microcontroller designed by a company named
Atmel. (Atmel says that the name AVR doesn’t stand for anything.) These microcon-
trollers are very popular, and many hardware projects use them. One reason for their
popularity is the excellent tool chain that comes with them. Based on the GNU C++
compiler tools, it is optimized for generating code for AVR microcontrollers.
That means you feed C++ code to the compiler that is not translated into machine
code for your computer, but for an AVR microcontroller. This technique is called
cross-compiling and is the usual way to program embedded devices.
Using Serial Ports
Arduino makes many stand-alone applications—projects that do not involve
any additional computers—possible. In such cases you need to connect the
Arduino to a computer once to upload the software, and after that, it needs
only a power supply. More often, people use the Arduino to enhance the
capabilities of a computer using sensors or by giving access to additional
hardware. Usually, you control external hardware via a serial port, so it is a
good idea to learn how to communicate serially with the Arduino.
Although the standards for serial communication have changed over the past
years (for example, we use USB today, and our computers no longer have
RS232 connectors), the basic working principles remain the same. In the
simplest case, we can connect two devices using only three wires: a common
ground, a line for transmitting data (TX), and one for receiving data (RX).
Device #1
GND
TX
RX
Device #2
GND
TX
RX
Serial communication might sound old-school, but it’s still the preferred way
for hardware devices to communicate. The S in USB stands for “serial”—and
when was the last time you saw a parallel port? (Perhaps this is a good time
to clean up the garage and throw out that old PC you wanted to turn into a
media center someday….)
Chapter 2. Creating Bigger Projects with the Arduino • 28
report erratum • discuss
www.it-ebooks.info