Page 179 - Hacking Roomba
P. 179
160 Part II — Fun Things to Do
Listing 8-4 shows a Processing sketch called RoombaRing. It takes any RTTTL formatted
ringtone and plays it on the Roomba. Change the rtttl variable to be whatever RTTTL
ringtone you like. And as always, change roombacommPort to reflect which serial port your
Roomba is on.
After using RTTTLParser to create a notelist from an RTTTL string, RoombaRing fol-
lows one of two paths. If the length of the song is less than 16 notes, it uses createSong()
and playSong() to let Roomba deal with the song’s timing.
If the song is greater than 16 notes, it goes through each note, plays it with playNote(), and
waits the appropriate amount of time for the note to play. Notice that there is a fudge factor
added to the pause. This was determined experimentally when it was noticed that a pause of
the exact right time wasn’t long enough and the notes were getting cut off. Your Roomba and
serial connection may have different characteristics and require a slightly different value of fudge.
When playing songs longer than 16 notes, timing between the computer and Roomba becomes
important so a wired connection and not Bluetooth should be used.
There is also the command-line Java program RTTTLPlay.java that functions very similarly to
Listing 8-4.
Search for “monophonic ringtone” on Google to find websites with databases of RTTTL-formatted
songs you can use with RTTTLPlay.java. One such site is www.handphones.info/
ringtones/category/. Transcribing normal piano sheet music into an RTTTL song requires
some experience in arranging for a monophonic instrument. If you can pick out melodies, try
www.freesheetmusicguide.com and download some sheet music to find the notes of
songs you can’t find in RTTTL format.
Listing 8-4: RoombaRing Ringtone Player Processing Sketch
import roombacomm.*;
String rtttl = “tron:d=4,o=5,b=100:8f6,8c6,8g,e,8p,8f6,8c6,”+
“8g,8f6,8c6,8g,e,8p,8f6,8c6,8g,e.,2d”;
String roombacommPort = “/dev/cu.KeySerial1”; // or COM3, etc.
RoombaCommSerial roombacomm = new RoombaCommSerial();
if( !roombacomm.connect(roombacommPort) ) {
println(“couldn’t connect. goodbye.”); System.exit(1);
}
println(“Roomba startup”);
roombacomm.startup();
roombacomm.control();