Robot App Store Developer Program

robots-app-store-developer-program

Knowledge Base

How to Program Roomba to Play Music

  By Anna Sandler

Isn’t it fun to hear a vacuum cleanning robot singing?

Before we start, please make sure you are familiar with basic Roomba programming as explained in the "Introduction to Roomba Programming" chapter,
Please also make sure your Bluetooth device or the serial cable are connected and the baud rate is configured correctly as explained in the "Serial Port Baud Rate Configuration" chapter

One thing to know before we start - Roomba’s ‘singing’ is based on MIDI notes.

The command sequence for defining a song

[140] [Song Number] [Song Length] [Note Number 1] [Note Duration 1]....[Note Number N] [Note Duration N]

Explanation to the song definition commands:
  • 140 – Tells Roomba that we are going to define a song. (which is a collection of notes)
  • [Song Number]- Roomba 4XX, Create and Dirt dog models can hold up to 16 songs; therefore, this number can only be in the range of 0-15.
    The other Roomba models (5XX and 7XX) have capacity of only four pre-defined songs (song number can be 0-3).
    If a song has already been defined under this number, it will be replaced with the new song.
    Song definitions are saved until Roomba is turned OFF.
  • [Song Length]- Number of notes that are going to be sent. Maximum amount of notes in one song is 16; therefore, the range is between 0 and 15;
  • [Note Number 1]- Byte command that represents a note according to the table below; The range of the command byte is between 31 and 127.
    Values between 60 and 83 are the most recommended notes in terms of a ‘pleasant sounds’.
  • [Note Duration]- The duration of the note specified in increments of 1/64 of a second.

The command sequence for playing a pre-defined song

[141][Song Number]

Explanation to the song playing commands:
  • [141]- Tells Roomba to play a song;
  • [Song Number]- The song number to play.
    If no song has yet been defined under this number, the command will be canceled.
Note: Since songs are being erased when Roomba is turned off, at the beginning of your program you will have to re-define all songs using the [140] command as described above.

Note numbers for song command

Note number table for song command
Note number table for song command

Things you should know about Roomba play

  • The pre-defined song is actually saved to Roomba's memory for later use; (until it will be turned OFF);
  • Pre-defined song can be replaced, by giving a new song the same song number;
  • Roomba accepts song definitions while in "Passive", "Safe", or "Full" modes;
  • Roomba can play a pre-defined song only while in "Safe" or "Full" modes;
  • Request for a song number that has not yet been saved, will be ignored;

How to define a song with more than 16 notes

There is a way to define and play a song that its length is bigger than 16 notes. It's actually very easy:
  • Saving stage: You will need to break your longer song to smaller parts of 16 notes. So during the song definition stage- the first 16 notes are defined as song number 0. The next 16 notes are defined as a second song and so on… until you finish defining the 16th song (on older Roombas, or until you reach the 4th song on newer Roombas) or until the original song is ended.
  • Calculating song length: Since each note contains its duration; it's easy to calculate the duration for each defined song: Calculate the total duration from all the notes in the same song number. Since 1 second equals to 64 in the duration scale, all you need to do, is to divide the total sum with 64 to get the total duration in seconds for the specific song number;
  • Playing stage: After you've calculated the duration in seconds for each song number, you can simply define a loop with a timer. Send a play command for the first song, wait for the duration in second of the first song that you've calculated in previous step, and then send a play command for the next song and so on...
Note- If you use a Bluetooth device to communicate with Roomba, the execution time for each command that is sent to Roomba depends on the physical distance between Roomba and the device that sends those commands (computer / smart phone). Add few milliseconds to the timer if Roomba is moving during playing the song to prevent a situation that one of the songs will be interrupted before it is finished;

Song interruption while it is being played

Why Roomba plays a song from the middle for the next time it is played?

Roomba implements an internal pointer that references the note that is just being played. When a song is being interrupted before it is finished, this pointer saves the current note when it was interrupted. Next time this song will be played, it will be started from the note that is referenced in the counter and on.

What is the solution for song interruption while it is being played?

To avoid this situation wait until the song is finished before sending another Play command. If stopping the song in the middle is unavoidable, you can implement the following solution as a cleanup. This solution initializes Roomba’s song pointers. For safety, run this cleanup procedure when your program is started and finished.

The cleanup procedure is needed for two reasons:
  • In case the developer of the program that was communicating with Roomba before your program, didn’t read this article and didn’t make a cleanup when his program was ended;
  • In case the communication with Roomba was disconnected when you've tried to make the cleanup (Bluetooth was unreachable or the cable was unplugged);
Alternately, you can restart Roomba, the songs will disappear and so will their pointers;

How to implement songs cleanup?

  • Override all songs that have been saved on Roomba (16 song or four songs depend on Roomba model) with a one-note song. Note number is not important because it won't be heard. The duration of the note should be 0. This will not make a sound.
  • Send Play command for all the songs. This will make the pointers go back to the beginning of each song;

How to program your Roomba to play the Jingle Bells song?

Make sure Roomba is connected, fully charged and its serial port device (serial to USB cable or a Bluetooth device) is connected to your Roomba;

Send the following commands:
  • 128 131
  • 140 0 16
  • 76 16 76 16 76 32 76 16 76 16 76 32 76 16 79 16
  • 72 16 74 16 76 32 77 16 77 16 77 16 77 32 77 16
  • 140 1 7
  • 76 16 76 32 79 16 79 16 77 16 74 16 72 32
  • 141 0
  • 141 1
Explanation:
  • [128 131] (Start the command stream and change Roomba mode to "Safe" mode)
  • [140 0] (Start song definition and define the first song, song number 0)
  • [16] (16 notes will be sent for song number 0)
  • [76 16](play Mi sound for 1/4 seconds)
  • [76 16](play Mi sound for 1/4 seconds)
  • [76 32](play Mi sound for 1/2 seconds)
  • [76 16](play Mi sound for 1/4 seconds)
  • [76 16](play Mi sound for 1/4 seconds)
  • [76 32](play Mi sound for 1/2 seconds)
  • [76 16](play Mi sound for 1/4 seconds)
  • [79 16](play Sol sound for 1/4 seconds)
  • [72 16](play Do sound for 1/4 seconds)
  • [74 16](play Re sound for 1/4 seconds)
  • [76 32](play Mi sound for 1/2 seconds)
  • [77 16](play Fa sound for 1/4 seconds)
  • [77 16](play Fa sound for 1/4 seconds)
  • [77 16](play Fa sound for 1/4 seconds)
  • [77 32](play Fa sound for 1/2 seconds)
  • [77 16](play Fa sound for 1/4 seconds)
  • [140 1] (Start song definition and define the second song, song number 1)
  • [7] (7 notes will be sent for song number 1)
  • [76 16](play Mi sound for 1/4 seconds)
  • [76 32](play Mi sound for 1/2 seconds)
  • [79 16](play Sol sound for 1/4 seconds)
  • [79 16](play Sol sound for 1/4 seconds)
  • [77 16](play Fa sound for 1/4 seconds)
  • [74 16](play Re sound for 1/4 seconds)
  • [72 32](play Do sound for 1/2 seconds)
  • [141 0] (Play song number 0)
  • Wait 5 seconds, total duration of the first song
  • [141 1] (Play song number 1)

married and want to cheat infidelity in marriage my wife cheated on me with my father







Related Robot-Apps™

Comments