Page 287 - Hacking Roomba
P. 287
268 Part III — More Complex Interfacing
The Basic Stamp nomenclature uses Vss to mean Gnd and Vdd to mean Vcc or +5V. The
Vdd/Vss terms are more accurate but less well known.
Making BumpTurn with a Basic Stamp
Now that you have a new brain ready for Roomba, it’s time to create some Roomba code. The
BumpTurn functionality from Chapter 6 is a good starting point as it shows how to send com-
mands to Roomba as well as get sensor data out of it. Recall the BumpTurn algorithm had only
three actions:
Go forward
If bumped on the left, turn 90 degrees to the right
If bumped on the right, turn 90 degrees to the left
Implementing BumpTurn in PBASIC will be as easy as implementing the Java version from
Chapter 6. The main differences will be in the setup of the BS2 itself and setting the Roomba
serial speed to be slow enough for the BS2.
The first step in writing a Roomba (or any) PBASIC program is to define which pins are being
used and what direction the data is moving on those pins. These statements go at the begin-
ning of any PBASIC program. For the above circuit, the pin definitions would be (using the
ROI names):
DD PIN 12
RXD PIN 11
TXD PIN 10
INPUT TXD
Downshifting the Serial Speed for BS2
The Basic Stamp 2 cannot send serial data at the standard Roomba speed of 57.6 kbps.
Fortunately, the Roomba ROI designers allow you to downshift to 19.2 kbps by toggling the
Roomba DD line three times in a row. In PBASIC this looks like:
FOR i = 1 TO 3
LOW DD
PAUSE 250
HIGH DD
PAUSE 250
NEXT
Although Roomba can send data at 19.2 kbps, it can’t really receive data at that speed, so you
need to downshift the Roomba communication speed again to 2400 bps with the ROI BAUD
command.