Sunday, April 29, 2018

Commanding a Roomba with Alexa and Raspberry Pi (Bonus): Controlling Roomba from Arduino via ROI Serial Interface

In the previous article we got Node-RED calling Arduino via Alexa.
Now, there are several ways to control the Roomba from Arduino.

One is the ROI (Roomba Open Interface) covered in this article.
The advantage is that the Arduino rides on the Roomba itself, so the connection stays live as the Roomba moves around.
The downside is that something sticks out of the Roomba — which risks snagging on furniture during a cleaning run.

The other approach is to leave Arduino in a fixed location and control the Roomba via IR.
Nothing needs to be attached to the Roomba.
The trade-off: you can only send commands while the Roomba is at its dock.

In practice, the Roomba returns to the dock automatically after cleaning, so you rarely need to send commands mid-run.
For simply starting a clean cycle, the IR approach is the better primary option.

That's why ROI control is presented here as a bonus.
  1. Gather parts.
  2. Set up Node-RED on the main Raspberry Pi and register it with Amazon Echo Dot
  3. Headless WiFi setup for Raspberry Pi Zero W
  4. Copy IR remote codes with Raspberry Pi
  5. Call IR functions from Node-RED to control the TV
  6. Control Arduino via HTTP API using FlashAir GPIO mode
  7. (Bonus) Control Roomba from Arduino via ROI serial interface [This article]
  8. Control Roomba from Arduino via IR
  9. Control Roomba from Node-RED via FlashAir/Arduino

What is ROI?

ROI is a serial interface for controlling the Roomba from external devices.
The full ROI specification is available on iRobot's site.

The connector location varies by model — on my Roomba 760, it's on the underside of the top handle.

On some other models, the connector is hidden under the top panel.

Connecting Arduino to the Roomba

The ROI uses a 7-pin mini-DIN connector.
You can find plugs at electronics retailers like Akihabara, but jumper wires inserted directly into the socket also work fine.

Pin assignments are in the ROI specification.


For this build, only pins 3 (RXD), 4 (TXD), and 6 (GND) need to be connected.
Arduino's hardware serial pins are 0 and 1, but using them blocks PC serial communication and makes debugging difficult.
To avoid that, I connected to other pins and used SoftwareSerial.

If you want to power the Arduino from the Roomba, tap pin 1 of the ROI connector, run it through a regulator, and feed it into Arduino's Vin pin.

Sending Commands from Arduino

I added Roomba serial communication to the Arduino code from last time (which handled the FlashAir connection).
In the example below, Arduino pins 12 and 13 are connected to the Roomba's TXD and RXD respectively.
The Roomba's default baud rate is 115200.
#include <SoftwareSerial.h>

#define PIN_SD_CLEAN 11

SoftwareSerial device(12, 13);

void setup() {
  Serial.begin(9600);
  pinMode(PIN_SD_CLEAN, INPUT);
}

// Ignore the initial HIGH state right after Arduino boots.
// Cleaning starts only after a LOW-to-HIGH transition.
volatile bool clean_flag = HIGH;
void loop() {
  if ( clean_flag == LOW && digitalRead(PIN_SD_CLEAN) == HIGH ){
    Serial.println("Run Roomba with clean mode");
    device.begin(115200);
    byte buffer[] = {
      byte(128), // Start
      byte(135)  // Clean
    };
    device.write(buffer, 2);
  }
  clean_flag = digitalRead(PIN_SD_CLEAN);
  delay(1000);
}
That's all there is to it.
Each ROI command is one byte, and you send bytes in sequence — the Roomba executes them in order.
The Roomba has several operating modes; sending low-level commands requires switching modes first.
Byte 128 is "Start" — after startup, the default mode is Passive.
In Passive mode, you can read sensors and start a clean cycle.
Since all we want is to start cleaning, we jump straight to the Clean command (135).

Modes and commands are all described in the ROI specification.
With it, you can turn the Roomba into a remote-controlled robot, play sounds, set indicator lights, and more.

Result

Here's the finished system in action:

Next time: triggering the Roomba via IR instead of ROI.

No comments:

Post a Comment