Page 298 - Hacking Roomba
P. 298
Chapter 13 — Giving Roomba a New Brain and Senses 279
In short, Arduino is an open source environment for creating smart objects. The initial team
who created and promoted the Arduino concept consisted of Massimo Banzi, David Cuartielles,
Tom Igoe, David Mellis, and Nicholas Zambetti. This group of physical computing researchers
and enthusiasts wanted to make creating hardware as easy and friendly as creating software has
become.
The Arduino hardware addresses the cost issue of the Basic Stamp by using inexpensive parts
and having an open-source design. Anyone can build an Arduino board like in Figure 13-14
or build an entirely different-looking one that still abides by the Arduino standards. If you do
want to purchase a pre-built board, they only cost $29. This is for an entire board, not just a
chip. An Arduino-capable chip, like the one shown in Figure 13-15, is a standard Atmel AVR
ATmega8 and is about $3.60. A common practice is to buy one Arduino board and a handful
of ATmega8s and build many Arduino circuits.
The Arduino Environment
Figure 13-16 shows the Arduino programming environment. If you think it looks a lot like the
Processing environment introduced in Chapter 7, you’re right. Arduino is based on Processing
and adopts many of its idioms. Like Processing, Arduino runs on Mac OS X, Windows, and
Linux. And like Processing, programs written with Arduino all have a similar code structure,
consisting of two functions:
setup(): Code that’s run once, on startup
loop(): Code that’s run over and over, after setup()
Typically you put code to configure the Arduino board in the setup() function, much like
you’d put graphics initialization code in the setup() of a Processing sketch. However, although
Processing’s loop() function is repeatedly executed at a specific framerate, the Arduino loop()
is run as fast as possible. If you want to emulate a Processing-like periodic execution of
loop(), add a delay() to the end of your loop() function.
Beyond that similarity and the familiar programming environment, Arduino code is completely
different from Processing code. Processing code is just thinly wrapped Java code, whereas Arduino
code is thinly wrapped AVR-GCC C code. In a similar way that Processing attempts to make
Java a bit easier to deal with by creating many convenience functions, so Arduino does with C.
The idea of creating an embedded microcontroller version of Processing did not originate with
Arduino. That honor goes to Wiring (http://wiring.org.co/) by Hernando Barragán.
The Wiring I/O board has enormous amounts of I/O, almost like having two or three Arduino
boards in one. It’s priced to match, at around $80 from SparkFun. Arduino is based on Wiring
but aimed more at being a low-cost solution. Wiring is open-source, and Arduino inherits
much from its bigger brother.
The Arduino environment is not bound to the Arduino board, however; that is simply its
default. Arduino supports different target types and through text file configuration changes,
you can have Arduino program a Wiring board, a generic ATmega8 board, or any board with
any CPU supported by AVR-GCC. You could create your own circuit using any Atmel AVR
chip and use Arduino to program it.