Page 296 - Hacking Roomba
P. 296
Chapter 13 — Giving Roomba a New Brain and Senses 277
Interpreted Code
Basic Stamp
blink.bs2 tokenize blink.tokens upload interpreter
libraries
blink tokens
Compiled Code
Arduino
compile
blink.pde preprocess blink.o upload boot loader
& link
blink code
libraries.cpp
FIGURE 13-13: Interpreted vs. compiled code flows for the blink program
Both systems take the source code file, process it, and upload it to the microcontroller, which
then executes it. In both cases, libraries of common routines (like how to toggle a pin to allow
blinking) are used by your code. In the Basic Stamp case, the libraries are fixed, frozen in the
firmware of the BS2. In the Arduino case, only those libraries that are needed are linked in
before being uploaded. If you don’t use the serial port, your executable code in the microcon-
troller won’t contain the serial libraries. By compiling only those libraries you need, a compiled
system will have more space available in the microcontroller for your code.
In the interpreted system, what is uploaded to the microcontroller are tokens: a compressed
version of your PBASIC program. If you have a loop in your code, the PBASIC interpreter
parses the loop’s token each time, figuring out what each token means and turning it into
machine code, each time. The compiled system does this translation once, at compile time.
The benefit is two-fold: no interpreter is needed on the microcontroller (more space again
for your code), and your code executes much faster.
About Arduino
Arduino (http://arduino.cc/) is several things. At first glance it is a microcontroller
board, as in Figure 13-14. It is also a standardized way of generating compiled programs for
the Atmel AVR series of microcontrollers, like the one in Figure 13-15. Viewed another way,
Arduino is an environment and style of programming any type of microcontrollers. In many
ways it is the spiritual successor to the Basic Stamp. It attempts to maintain the same ease-of-
use pioneered by the Basic Stamp while giving people the power to write compiled C code.