Mysensor-ing a Roomba vacuum cleaner.



  • Hi,

    Does someone have already mysensor-ed a Roomba bot ?
    I'd like to do so (in order to get back some info such as battery, status, etc... and be able to trigger a cleaning program remotely).
    This look like pretty straightfirward thanks to the Roomba serial interface and I intend to try that as soon as i will have finished the temperature control of my house...
    However if someone as already done that, i'll be interested in your feedbak.

    Thanks!

    Sorg


  • Admin

    @Timothée-GROS

    Sound fun. You'll probably be the first one!



  • I'd love to do it for you.
    Unfortunately, roomba too expensive in my country :(
    Anyway, good luck for your project.
    Hopefully, you can share it here



  • Never had a roomba, but i have obtained remote control of my automatic LG vacuum :+1:
    I just copied the IR remote commands and transmit them on command from a sensor node.
    There is no feedback, but i don't think i need feedback, when the battery is empty it drives back to the docking station. All i can say is that just pushing start remotely and getting home to a clean house is nice ;)



  • @funky81 said:

    Hopefully, you can share it here

    I will !



  • Hi,
    I had started to analyze the communication protocol and the project. I found this site very useful. The problem is the sizing. I'd like to keep everything hided so a very small circuit is requested.



  • @mortommy it's quite easy: Roomba has a serial (there is 7-pin mini DIN socket under rubber cover on top of the device). Communication protocol is well described: https://cdn-shop.adafruit.com/datasheets/create_2_Open_Interface_Spec.pdf
    Remember that higher versions of Roomba (7xx+) communicate with higher baud rate (115200bps).

    There are also couple of libraries (but be careful, one of them contains hardcoded baud-rate, no matter what you declare in constructor :(, I haven't already sent a pull-request).
    And the last thing worth mentioning is power supply from Roomba - usually it outputs about 16V, what is enough to power Arduino using internal power regulator, but after connecting to docking station, voltage raises (I needed to replace my one).



  • Done that as a proof of concept. Can Post the sketch later. Main challenge in my opinion is what you so with Hardware. Having a breadboard (or eben a box) on top of The roomba does not have a high waf....😃



  • Yes @emka it is not difficult, I have already wrote a sketch. The problem it is, as I said before, and as @vorowski said, an hardware problem, especially with the latest series 8 and 9. You cannot leave the electronics components outside and the space under the handle it is not enough. If you look for a solutions in the web you'll find even two commercial solutions to control roomba, but for the new series they propose some dirty fixes to fit the hardware.
    I'm thinking to control roomba via an IR send/receiver.



  • I also went down the road with Ir as my main application would be "start cleaning"...but I never got the room a to react with my IR diods....



  • this is the code I used....

    /*
     General comments
    This sketch controls a IRobot Roomba via Mysensors
    
    uses the Roomba library from
    http://www.airspayce.com/mikem/arduino/Roomba
    
    Implemented:
    Dock
    Medium clean
    OFF
    Spot clean
    
    
    
    Target functionality:
    Read sensors:
    1 SensorChargingState = 21 (ChargeStateNotCharging = 0, ChargeStateReconditioningCharging = 1, ChargeStateFullChanrging = 2, ChargeStateTrickleCharging = 3, ChargeStateWaiting = 4, ChargeStateFault = 5)
    2 SensorBatteryTemperature = 24
    3 SensorBatteryCharge = 25
    4 SensorBatteryCapacity = 26
    
    Events:
    1 Mode { ModeOff = 0, ModePassive = 1, ModeSafe = 2, ModeFull = 3 
    2. Power mode
    
    Trigger the following commands:
    1 Go to dock (stop) void dock() - Causes roomba to immediately seek the docking station. No equivalent for Create. 
    2 Clean
    3 Maintenance - void drive() - Starts the Roomba driving with a specified wheel velocity and radius of turn 
    4 Play a song :-) -  void playSong  ( uint8_t  songNumber ) 
    5 Spot cleaning - OPT code 134
    
    
    
    hook up radio - remember to switch serial output of MYSENSORS off!
    
    
    ******************************
    | Wire the NRF24L01+ module: |
    ******************************
    Arduino   NRF24L01+   Comment
    GND       GND         Black 
    5VReg     3.3V VCC    Red
    9         CE          Orange
    10        CSN/CS      Yellow 
    13        SCK         Green 
    11        MOSI        Blue 
    12        MISO        Violet 
    2         IRQ         Gray 
     
     */
    
    // 21.02.2016 created by WL
    // ... and NOT working!
    
    
    
    // 05.03.2016 created by WL
    // ... and  working!
    
    //include required libraries****************************************
    //********************************************************************
    
    #include "OneButton.h" // http://www.mathertel.de/Arduino/OneButtonLibrary.aspx
    #include <SPI.h>
    #include <MySensor.h>
    #include <Roomba.h>
    
    //Set Variable *****************************************************
    //******************************************************************
    // Setup a new OneButton on pin A1.  
    OneButton button1(A1, true);
    
    // Setup other variables
    Roomba roomba(&Serial, Roomba::Baud115200); // Defines the Roomba instance and the HardwareSerial it is connected to
    
    // Setup PINs
    const int ledPin1 = 5; //green
    const int ledPin2 = 6; //red
    
    //Pin2 & 3 External interrup / PWM: 3, 5, 6, 9, 10, and 11 / SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK) / LED: 13 / I2C: A4 (SDA) and A5 (SCL) - this applies for Pro Mini & Nano
    
    // Setup other variables
    //Child IDs 
    #define CHILD_ID 0   // Id of the command node
    #define CHILD_ID_1 1   // Id of the battery check node
    #define CHILD_ID_2 2   // Id of the 2nd node
    
    // Setup other variables
    int Roomba1 = 0; // 1 - dock / 2 - clean / 3 - spot / 4 - off
    
    
    //for sensorgetting
    char* ChargeTypes[6] = {
      "Not charging","Reconditioning Charging","Full Charging","Trickle Charging","Waiting","Charging Fault Condition"};
    char* OiTypes[4] = {
      "Off","Passive","Safe","Full"};
    
    int packetSizes[58] = {
      0,0,0,0,0,0, //1-6
      1,1,1,1,1,1,1,1,1,1,1,1, //7-18
      2,2, //19-20
      1, //21
      2,2, //22-23
      1, //24
      2,2,2,2,2,2,2, //25-31
      1, //32
      2, //33
      1,1,1,1,1, //34-38
      2,2,2,2,2,2, //39-44
      1, //45
      2,2,2,2,2,2, //46-51
      1,1, //52-53
      2,2,2,2, //54-57
      1 //58
    };
    
    boolean lowBattery = true; // Acts as a debounce
    long battery_Current_mAh = 0;
    long battery_Total_mAh = 0;
    long battery_percent = 0;
    boolean DeadBattery = false;
    boolean FullBattery = true;
    unsigned long chargingState = 0;
    long voltage = 0;
    long temp = 0;
    long OiMode = 0;
    long ChargeSource = 0;
    boolean firstRun = true; //We don't want it Tweeting when it is getting the current state
    boolean buttonsDown = false;
    long CorrectDockCycles = 0;
    unsigned long cliffStartTime = 0;
    int drivedurationforward = 1000; //value in ms from controller how long to go forward
    int drivedurationback =1000; //value in ms from controller how long to go back
    long sensorfrequency = 30000; // frequency the sensors are read
    long lastsensorread = 0; // when were the sensors read the last time
    
    uint8_t buf[52];
    
    // Initialize Mysensors
    MySensor gw;
    
    // Initialize messages
    MyMessage msg(CHILD_ID, V_VAR1); //Receive commands from controller
    MyMessage msg2(CHILD_ID, V_VAR2); //Receive drivedurationback from controller
    MyMessage msg3(CHILD_ID, V_VAR3); //Receive drivedurationforward from controller
    MyMessage msg4(CHILD_ID, V_VAR4); //Receive sensorfrequency from controller
    
    MyMessage msg1_1(CHILD_ID_1, V_VAR1); //Declare sensor message To send ChargeState
    MyMessage msg1_2(CHILD_ID_1, V_VAR2); //status of Voltage
    MyMessage msg1_3(CHILD_ID_1, V_VAR3); //status of Temperature
    MyMessage msg1_4(CHILD_ID_1, V_VAR4); //status of Charge [%]
    MyMessage msg1_5(CHILD_ID_1, V_VAR5); //status of ChargeSource
    
    MyMessage msg2_1(CHILD_ID_2, V_VAR1); // status of OiMode
    MyMessage msg2_2(CHILD_ID_2, V_VAR2); // status of Status
    //MyMessage msg2_3(CHILD_ID_2, V_VAR3); // status of Status
    //MyMessage msg2_4(CHILD_ID_2, V_VAR4); // status of Status
    MyMessage msg2_5(CHILD_ID_2, V_VAR5); // status of DEBUG
    
    
    // setup code here, to run once************************************
    //*******************************************************************
    void setup() {
    
      roomba.start(); // Starts the Open Interface and sets the mode to Passive. You must send this before sending any other commands. Initialises the serial port to the baud rate given in the constructor
      //Serial.println("Starting the RoombaControlsketch......");
      
         
         // link the button 1 functions.
      button1.attachClick(click1);
      button1.attachDoubleClick(doubleclick1);
    
      /////////////////////////////////////
      // The MySensors library is started// 
      /////////////////////////////////////
      gw.begin(incomingMessage);  // gw.begin(NULL, AUTO, true); // The third argument enables repeater mode - no sleeping for repeaters!
    
      //Send the sensor node sketch version information to the gateway
      gw.sendSketchInfo("ControlmyRoomba", "1.1");
      
      //Present sensors
      gw.present(CHILD_ID, S_CUSTOM); //Your sensor must first present itself to the controller
      gw.present(CHILD_ID_1, S_CUSTOM); //Your sensor must first present itself to the controller
      gw.present(CHILD_ID_2, S_CUSTOM);
      //gw.present(CHILD_ID_3, S_LIGHT);
    
      //Request Data from controller (Setup) - not always required
      gw.request(CHILD_ID, V_VAR2); //request drivedurationback
      gw.request(CHILD_ID, V_VAR3); //request drivedurationforward
      gw.request(CHILD_ID, V_VAR3); //request sensorfrequency
      
     // Setup required PINS
      pinMode(ledPin1, OUTPUT);  // initialize digital ledPin as an output.
      pinMode(ledPin2, OUTPUT);  // initialize digital ledPin as an output.  
      pinMode(13, OUTPUT); 
      // initialize digital pin 13 as an output.
    
      //blink bot hLEDs to indicate setup looped
      digitalWrite(ledPin1, HIGH);
      digitalWrite(ledPin2, HIGH);
      delay(50);
      digitalWrite(ledPin1, LOW);
      digitalWrite(ledPin2, LOW);
      delay(50);
      digitalWrite(ledPin1, HIGH);
      digitalWrite(ledPin2, HIGH);
      delay(50);
      digitalWrite(ledPin1, LOW);
      digitalWrite(ledPin2, LOW);
      delay(1000);
    } // setup
    
    
    // main code here, to run repeatedly:*******************************
    //******************************************************************** 
    void loop() 
    { 
      // keep watching the push buttons:
      button1.tick();
      gw.process();
      if (millis() > lastsensorread + sensorfrequency)
      {
          readsensors();
      }
    
    
      
    } // loop
    
    
    ////////////////////////////////////////////////////////////////////////
    
    //receive data from GW
    void incomingMessage (const MyMessage &message) 
    {
      if (message.sensor == CHILD_ID) 
      { 
        blinkLED(ledPin1);
        if (message.type == V_VAR1) 
        {
          Roomba1 = atoi(message.data); // Roombastatus
          
          if (Roomba1 == 1) 
          {
            roomba.dock(); 
            gw.send(msg2_5.set("received dock"));  // Send info value to gw
            blinkLED(13);
          }
          else if (Roomba1 == 2) {
            Serial.write(135); // medium clean  
            gw.send(msg2_5.set("received medium clean"));  // Send info value to gw
          }
          else if (Roomba1 == 3) {
            roomba.spot(); //if Roomba is in a cleaning mode this will pause the cycle
            gw.send(msg2_5.set("received spot"));  // Send info value to gw
          }
          else if (Roomba1 == 4) {
            Serial.write(133); // Power down
            gw.send(msg2_5.set("received power down"));  // Send info value to gw
          }
          else if (Roomba1 == 5) {
            driveback(); // drive backward
            gw.send(msg2_5.set("drive back"));  // Send info value to gw
          }
          else if (Roomba1 == 6) {
            driveforward(); // drive backward
            gw.send(msg2_5.set("drive forward"));  // Send info value to gw
          }
          else if (Roomba1 == 7) {
            Serial.write(133); // Power down
            gw.send(msg2_5.set("received power down"));  // Send info value to gw
          }
          else if (Roomba1 == 8) {
            Serial.write(133); // Power down
            gw.send(msg2_5.set("received power down"));  // Send info value to gw
          }
          else if (Roomba1 == 9) {
            Serial.write(133); // Power down
            gw.send(msg2_5.set("received power down"));  // Send info value to gw
          }
          else if (Roomba1 == 10) {
            Serial.write(133); // Power down
            gw.send(msg2_5.set("received power down"));  // Send info value to gw
          }
         }
       if (message.type == V_VAR2) 
        {
          drivedurationback = atoi(message.data); // 
          gw.send(msg2_5.set("received drivedurationback"));  // Send info value to gw
        }
       if (message.type == V_VAR3) 
        {
          drivedurationforward = atoi(message.data); // 
          gw.send(msg2_5.set("received ne drivedurationforward"));  // Send info value to gw
        } 
       if (message.type == V_VAR4) 
        {
          sensorfrequency = atoi(message.data); //
          sensorfrequency = 1000*sensorfrequency; 
          gw.send(msg2_5.set("received sensorfrequency"));  // Send info value to gw
        }  
      }
      
    }
    
    
    
    
    
    
    
    // ----- button 1 callback functions/////////////////////////////////////////
    
    // This function will be called when the button1 was pressed 1 time (and no 2. button press followed).
    void click1() {
      //Serial.println("Button 1 click.");
      blinkLED(13);
      roomba.safeMode();
      
       // 2 bytes per note
      uint8_t song[] = {62, 12, 66, 12, 69, 12, 74, 36};
      roomba.song(0, song, 8);
      delay(20);
      roomba.playSong(0);
    
      
      
    
      
      gw.send(msg2_5.set("play song"));  // Send info value to gw
      roomba.start();
      
    
     
    } // click1
    
    
    // This function will be called when the button1 was pressed 2 times in a short timeframe.
    void doubleclick1() {
      readsensors();
      
      
       
    } // doubleclick1
    
    
    
    
    
    
    
    // Function declarations
    //*********************************************************************
    
    //for sensorgetting
    int getPacketSize(int p) {
     return packetSizes[p-1]; 
    }
    int getPacketOffset(int p) {
      int i=0;
      for  (int s=1; s<p; s++) {
        i+=getPacketSize(s);
      }
      return i;
    }
    
    
    
    //read sensors
    void readsensors()
    {
         if (roomba.getSensors(6, buf, 52)) {
    
        int off = 0;
    
        // Battery Checks
        off = getPacketOffset(21);
        chargingState = buf[off+0];
        voltage = buf[off+2]+256*buf[off+1];
        temp = buf[off+5];
        battery_Current_mAh = buf[off+7]+256*buf[off+6];
        battery_Total_mAh = buf[off+9]+256*buf[off+8];
        
        if (battery_Total_mAh == 0) battery_Total_mAh=1;
        int nBatPcent = battery_Current_mAh*100/battery_Total_mAh;
        battery_percent = nBatPcent;
    
        //Oi Mode
        off = getPacketOffset(35);
        OiMode = buf[off+0];
    
        //ChargeSource
        off = getPacketOffset(34);
        ChargeSource = buf[off+0];
        
    
        gw.send(msg2_5.set("charging state"));  // Send info value to gw
        gw.send(msg2_5.set(chargingState));  // Send info value to gw
        gw.send(msg1_1.set(ChargeTypes[chargingState]));  // Send info value to gw
    
        
        gw.send(msg1_2.set(voltage));  // Send info value to gw
        
        
        gw.send(msg1_3.set(temp));  // Send info value to gw
    
        gw.send(msg2_5.set("battery_Current_mAh"));  // Send info value to gw
        gw.send(msg2_5.set(battery_Current_mAh));  // Send info value to gw
        gw.send(msg2_5.set("battery_Total_mAh"));  // Send info value to gw
        gw.send(msg2_5.set(battery_Total_mAh));  // Send info value to gw
        gw.send(msg1_4.set(battery_percent));  // Send info value to gw
        
        gw.send(msg2_1.set(OiTypes[OiMode]));  // Send info value to gw
        gw.send(msg2_2.set(ChargeSource));  // Send info value to gw
        lastsensorread = millis();
        blinkLED(ledPin2);
    
        
    
        
      }
      else{ gw.send(msg2_5.set("roomba is off"));}  // Send info value to gw
    }
    
    
    //Drive backward
    void driveback()
    {
      roomba.safeMode();
      delay(20);
      long drivestart = millis();
      roomba.drive(0xFF38, 0x8000); // Drive straight backwards
      while (millis() < drivestart+drivedurationback){
        gw.send(msg2_5.set("driving"));  // Send info value to gw
        }
      roomba.drive(0, 0); // Stop
      gw.send(msg2_5.set("stopped"));  // Send info value to gw
      roomba.start(); // back topassive mode
    }
    
    //Drive forward
    void driveforward()
    {
      roomba.safeMode();
      delay(20);
      long drivestart = millis();
      roomba.drive(0xc8, 0x8000); // Drive straight forward
      while (millis() < drivestart+drivedurationforward){
        gw.send(msg2_5.set("driving"));  // Send info value to gw
        }
      roomba.drive(0, 0); // Stop
      gw.send(msg2_5.set("stopped"));  // Send info value to gw
      roomba.start(); // back topassive mode
    }
    
    
    
    //blink a specified LED
    
    void blinkLED(int blinkPIN) //ledPinx needs to be specified
    {
      //Serial.print("blink LED ");
      //Serial.println(blinkPIN);
      //Serial.println(""); // move the cursor to the next line
      digitalWrite(blinkPIN, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(100);              // wait for a delay ms
      digitalWrite(blinkPIN, LOW);    // turn the LED off by making the voltage LOW 
      delay(30);
    }
    
    
    
    //roomba.playSong(0); //play song number 0 / OPT Code 141 + 1 data byte
      //roomba.playSong(0); //play song number 0 / OPT Code 141 + 1 data byte
      //roomba.leds(ROOMBA_MASK_LED_NONE, 0, 0); //does something withe LEDs / OPT Code 139 + 3 data bytes
      //roomba.leds(ROOMBA_MASK_LED_1, 100, 255); //this is "dirt detect"
      //delay(1000);
      //roomba.leds(ROOMBA_MASK_LED_1, 100, 0);
      //roomba.leds(ROOMBA_MASK_LED_3, 100, 255); //this is "dirt detect"
      //delay(1000);
      //roomba.leds(ROOMBA_MASK_LED_3, 100, 0);
      //roomba.leds(ROOMBA_MASK_LED_5, 100, 255); //this is dirt detect & dock
      //delay(1000);
      //roomba.leds(ROOMBA_MASK_LED_5, 100, 0);
      //roomba.leds(ROOMBA_MASK_LED_7, 100, 255); //this is spot & dock & dirt detect
      //delay(1000);
      //roomba.leds(ROOMBA_MASK_LED_7, 100, 0);
      //delay(1000);
    
    
    //roomba.playSong(0); //play song number 0 / OPT Code 141 + 1 data byte
      //roomba.playSong(0); //play song number 0 / OPT Code 141 + 1 data byte
      //roomba.leds(ROOMBA_MASK_LED_NONE, 0, 0); //does something withe LEDs / OPT Code 139 + 3 data bytes
      //roomba.leds(ROOMBA_MASK_LED_NONE, 100, 100); // this is the "clean LED"
      //delay(1000);
      //roomba.leds(ROOMBA_MASK_LED_NONE, 100, 0); // this is the "clean LED"
      
      //roomba.leds(ROOMBA_MASK_LED_PLAY, 255, 255); // this is the "clean LED"
      //delay(1000);
      //roomba.leds(ROOMBA_MASK_LED_PLAY, 255, 0);
      
      //roomba.leds(ROOMBA_MASK_LED_4, 100, 255); //this is "dirt detect" 
      //delay(1000);
      //roomba.leds(ROOMBA_MASK_LED_4, 100, 0);
    
      //roomba.leds(ROOMBA_MASK_LED_6, 100, 255);  // this is the "clean LED"
      //delay(1000);
      //roomba.leds(ROOMBA_MASK_LED_6, 100, 0);
      
      //roomba.leds(ROOMBA_MASK_LED_ADVANCE, 100, 255); //this is "!"
      //delay(1000);
      //roomba.leds(ROOMBA_MASK_LED_ADVANCE, 100, 0);
      //delay(1000);
      
    


  • I just tried with a simple sketch proposed in many forum to send a clean command by IR led, and with a normal IR-led, 300 ohm resistor and an arduino uno, from 2 meter I was able to send the commands power and clean.
    to my 870 roomba.



  • Hey all,
    I made a Roomba IR scheduler for my Roomba 500. I used Mysensors icm with Pimatic. On a defined time or condition in Pimatic I sent for about 10 seconds the IR command to the Roomba. Which will start the robot to clean and leave the dock. With a LDR on the dock LED I can measere the amount of time the robot is cleaning. The same Mysensors node does also measure the room temperature and humidity of the living room where my Roomba dock is.

    Emiel
    0_1479767567255_RoombaMysensors.jpg



  • For quite a while now there has been information on the net on how to build serial cables for the roomba and the documentation for controlling it from such a cable. I found this little bit on connecting the serial port to an arduino. http://www.netfluvia.org/layer8/?p=127 Seems like it should be pretty straight forward with this info to be able to MySensorize it. Looks like they do their communication with an xbee, but the basic concepts should be the same.



  • Take a look to this.


Log in to reply
 

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.