Page 295 - Hacking Roomba
P. 295
276 Part III — More Complex Interfacing
Adding a New Roomba Brain with Arduino
The Basic Stamp is an amazing tool and fun to play with, but it suffers from a few problems
for the serious hacker:
It’s expensive. Each BS2 costs $49. If you want to start adding microcontrollers to lots
of things, it gets expensive. And that’s assuming you don’t fry a BS2 or two while experi-
menting. What usually ends up happening is that you buy one BS2 and then re-use it,
destroying previous projects to make future projects. Unless you’re really good at docu-
menting (and who is?), this cannibalization destroys the history of your previous learning
experiences. You can’t cheaply make several iterations on an idea.
It’s limiting. PBASIC provides many useful functions, but if you cannot do what you
want using the PBASIC functions, you’re stuck. There’s no way to extend PBASIC to
add any functions you might need.
It’s closed. PBASIC works well, but maybe you could make it work better. Or perhaps
you’d like to get rid of the PBASIC functions you don’t need to make space for your
own code. Or maybe you’d just like to learn how PBASIC works. All of that is closed to
you because the PBASIC interpreter is not open source. It’s hard to fault Parallax for
this, because they’ve done great things for the hobbyist community, but it is frustrating
for the hacker who wants to learn.
It’s too slow. Your PBASIC programs run in a PBASIC interpreter on the BS2 PIC
microcontroller. They aren’t compiled down to machine code. This extra level of indirec-
tion makes PBASIC programs of any complexity run very slowly. This is likely the issue
you’ll run into first as you gain experience with the Basic Stamp.
Solutions exist here and there to these problems. Some companies offer BASIC compilers with
a language very much like PBASIC. These compilers compile your program to machine code
that can be burned on to cheap PIC microcontrollers. These compilers are usually several
hundred dollars and are not open source. And then you need to purchase a PIC programmer
to burn the chips. And even when you have it all hooked up, the cycle time between write-
compile-burn-use is long because it doesn’t work as seamlessly as the Basic Stamp does. The
Basic Stamp environment is so easy to use, why would anyone want to bother with the hassle
of compiling microcontroller code?
Interpreter vs. Compiler
With a microcontroller, interpreted code is almost always more problematic than compiled
code. In a microcontroller, you usually attempt to maximize the speed of execution and mini-
mize the memory footprint. An interpreted system necessarily results in slower code that takes
up more space. Figure 13-13 shows how your blinking LED source code file gets turned into
executable code for both an interpreted system like the Basic Stamp and a compiled system
like Arduino.