Go Down

Topic: Another roomba model (Read 2901 times) previous topic - next topic


Hello all,

I come to you today with a request of troubleshooting my first Arduino project. I saw some old Roomba projects where they used an arduino to make it controllable, and in the long run I would like to make mine controllable from my phone. I am following the specifications from http://www.irobot.lv/uploaded_files/File/iRobot_Roomba_500_Open_Interface_Spec.pdf and I got some code from another source. I tried following it to a 'T' but to no avail. All my roomba does is power on with the arduino then stops and doesn't do anything, and the scary part is, I don't even get a serial code from it.

Code: [Select]
#include <SoftwareSerial.h>

int rxPin = 2;
int txPin_nss = 3;
int ddPin = 4;

// define "sciSerial" as a NewSoftSerial serial port on those pins
SoftwareSerial sciSerial(rxPin,txPin_nss);
// define which pin will have an LED connected to it for simple status
int ledPin = 13;

// define a 10-byte array for holding sensor data
char sensorbytes[10];

// define what types to send for a "bump right" and "bump left" command
// which we will use later in the code
#define bumpright (sensorbytes[0] & 0x01)
#define bumpleft  (sensorbytes[0] & 0x02)

// start the rest of the setup routine by creating the "setup" function
void setup() {  // NOTE: all Arduino sketches must have a "setup" function

  pinMode(ledPin, OUTPUT);    // set the mode of the pin "ledPin"
  pinMode(ddPin,  OUTPUT);    // set the mode of the pin "ddPin"
  sciSerial.begin(115200);    // set the baud rate of the port "sciSerial"
                              // (defined above)
  digitalWrite(ledPin, HIGH); // turn on the LED to say we're alive
  // wake up the robot by flashing the "data detect" pin
  digitalWrite(ddPin, HIGH);
  digitalWrite(ddPin, LOW);
  digitalWrite(ddPin, HIGH);
  // set up the Roomba OI to receive commands (see OI manual)
  sciSerial.write(128);  // START (always first command)
  sciSerial.write(131);  // CONTROL (same as "Safe Mode")
  // turn off the LED to confirm that we're done setting up Roomba
  digitalWrite(ledPin, LOW);
  // do a little dance (routine defined below) to confirm that
  // the Roomba is ready to receive commands
} // this bracket indicates the end of the setup routine

// define what a "dance" is.  (used in setup routine above).
// this is simply a combination of the goForward, goBackward,
// and stopMoving functions (with some delays) which will be
// defined later.
void dance() {
  Serial.println("Preparing to dance");
  Serial.println("Done Dancing");
}  // this bracket indicates the end of the dance routine

// Now that we've setup the Roomba and did a dance to verify
// everything is working, we start the main loop of the program
void loop() {  // NOTE: all Arduino sketches must have a "loop" function
  digitalWrite(ledPin, HIGH); // turn on LED to say we're starting loop
  updateSensors();  // run the updateSensors function (defined below)
                    // to check for a bump
  Serial.println("Sensors are updated");                   
  digitalWrite(ledPin, LOW);  // turn on LED to say we've finished
                              // updating the sensors
  // after getting the sensor values, check the bump sensor values and
  // turn if we bumped 
  if(bumpleft) {  // bumpleft is defined near the top of this program as a
                  // particular byte (0x01) in the "sensorbytes" array we
                  // created to hold the sensor data returned by
                  // the updateSensors function.
    delay(1000);  // should be the approx. time for 90-degree turn
  // if we didn't hit the bumpleft sensor, did we hit the bumpright?
  else if(bumpright) {
    delay(1000);  // should be the approx. time for a 90-degree turn
  // once we're done checking the sensors, go back to moving forward,
  // even if you were already moving forward

// Now here is where we define all of those other things we've used

void goForward() {
  sciSerial.write(137); // Roomba's DRIVE command
  sciSerial.write((byte)0x00); // Velocity high byte, HEX 00
  sciSerial.write(0xc8); // Velocity low byte,  HEX C8 (00C8=200mm/sec)
  sciSerial.write(0x80); // Radius high byte,   HEX 80
  sciSerial.write((byte)0x00); // Radius low byte,    HEX 00 (8000=straight)
void goBackward() {
  sciSerial.write(137); // Roomba's DRIVE command
  sciSerial.write(0x38); // Velocity FF38 = -200 mm/sec (backwards)
  sciSerial.write((byte)0x00); // Radius 8000 = go straight
void spinLeft() {
  sciSerial.write(137); // Roomba's DRIVE command
  sciSerial.write(0xc8); // Velocity of spin 00C8 = 200 mm/sec
  sciSerial.write(0x01); // Radius 0001 = spin left
void spinRight() {
  sciSerial.write(137); // Roomba's DRIVE command
  sciSerial.write(0xc8); // Velocity of spin 00C8 = 200 mm/sec
  sciSerial.write(0xff); // Radius FFFF = spin right
void stopMoving() {
  sciSerial.write(137); // Roomba's DRIVE command
  sciSerial.write((byte)0x00); // Velocity 0000 = stopped
  sciSerial.write((byte)0x00); // Radius 0000 = nothing

void updateSensors() {
  sciSerial.write(142); // Roomba's SENSORS command
  sciSerial.write(1); // get sensor packet group 1, which is 10
                              // bytes long. This packet group starts with
                              // packet 7, of which the first two bits are
                              // for the bumpleft and bumpright sensors

  delay(64);  // wait for sensor data
  // before storing the new sensor data, wipe the old sensor data
  char i = 0;                  // start at position 0 in the array
  while (i < 10) {             // do a loop until i=10
    sensorbytes[i++] = 0;      // set the byte to 0 and then increment
                               // the loop counter
  } // this bracket is the end of the "wipe data" loop
  // go back to position 0 to prepare to receive the new data
  // this is the loop to actually read the incoming data and store it
  while(sciSerial.available()) {  // start the loop - check if there is
                                  // data coming in,
    int c = sciSerial.read();     // read it and store the current
                                  // byte as "c"
       // error routine to flash the LED 5 times if c= -1
       // (this shouldn't happen)
       if( c==-1 ) {
         for( int i=0; i<5; i ++ ) {    // loop to flash LED 5 times
           digitalWrite(ledPin, HIGH);
           digitalWrite(ledPin,  LOW);
      } // this brack is the end of the flashing loop
    } // this bracket is the end of the error routine
    // since we've read a byte, save it in the sensorbytes array at
    // position "i", and then increment "i"
    sensorbytes[i++] = c;
  } // this bracket is the end of the read incoming data loop
}  // this bracket is the end of the updatesensors function

This code is exactly what i have which is exactly what I copied from the other guy to see if I was making any mistakes. The only difference between mine and his is Arduino 1.x.x doesn't supper "Serial.println(v, BYTE);" so I had to use Serial.write(); . I am wondering if that's the problem... or if I'm just making a little mistake. I have the pins plugged in accordingly to the correct ports I believe, and i'm powering the roomba with a 9v battery. I also don't have the miniDin adapter for the roomba so I am just using jumper cables... All it does is turn on and the light will stay solid even though the code says when no signal to blink.. I am unsure what is happening, any help would be greatly appreciated!

Go Up