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
www.it-ebooks.info