1
$\begingroup$

Over the past month since I bought iRobot Create 2, I have failed to establish communication between the Arduino and iRobot Create 2. I will describe my hardware setup and my Arduino code, then ask several questions that would help future projects as well.

Hardware Setup: The iRobot Create 2 is connected with the Arduino based on the connection provided in pdf document at this link - https://edu.irobot.com/learning-library/controlling-create-2-with-arduino-and-android.

Software Setup: Following is a very basic code that I am using in my Arduino.


#include <SoftwareSerial.h> 

int rxPin = 10; //connected to pin 4 (TXD) of iRobot based on above document
int txPin = 11; //connected to pin 3 (RXD) of iRobot based on above document
int ddPin = 5;  //connected to pin 5 (BRC) of iRobot

//Set up a new Software Serial Port
SoftwareSerial softSerial = SoftwareSerial(rxPin, txPin);

void setup() {

// Defining PinModes
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  pinMode(ddPin, OUTPUT);
  softSerial.begin(19200); 
 

// Change the BAUD Rate/Waking up
  digitalWrite(ddPin, HIGH);
  delay(100);
  digitalWrite(ddPin, LOW);
  delay(500);
  digitalWrite(ddPin, HIGH);
  delay(2000);
  
// Start Command
  softSerial.write(128); //Starts the OI

// Mode Command - Passive, Safe, Full 
  softSerial.write(131); //Set mode to Safe
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.write(145);  //Serial.print(137, BYTE); 
  Serial.write(0x00);  
  Serial.write(0xc8);
  Serial.write(0x00);
  Serial.write(0x01);  
}

How I am deploying it ? I burn the above code into my Arduino using my laptop (Mac Pro). It compiles and burns fine without any issue. Then I disconnect the Arduino from my laptop and connect the Arduino using Jumper Wires to iRobot Mini DIN as following - Pin 10 of Arduino -> Pin 4 of iRobot; Pin 11 of Arduino -> Pin 3 of iRobot; Pin 5 of Arduino -> Pin 5 of iRobot;
GND of Arduino -> Pin 6 of iRobot; Vin of Arduino -> Pin 1 of iRobot

Observations

  1. When I connect the GND of Arduino to iRobot Pin 6, iRobot gets active - Green light
  2. Create 2 doesn't move at all OR No Reaction.

Questions

  1. I am unsure if the bot is communicating at 19200 Baud Rate ? In the above code, I believe that the code is wrong and maybe that's the problem.

  2. What could possibly be any other problems ?

  3. What is the correct way to set up the Baud Rate ? I do not clearly understand the documentation for Baud Rate for the Method 2 ? How do you execute Method 2 on Arduino ?

$\endgroup$
2
  • $\begingroup$ PLEASE HELP! I have been struggling for a month. $\endgroup$ Jul 26, 2020 at 4:50
  • $\begingroup$ Have you find an answer ? I'm struggling with this Uno / Create2 communication too... $\endgroup$
    – Olivier
    Oct 29, 2021 at 3:04

1 Answer 1

1
$\begingroup$

There are a few things wrong with this code that are stopping it from working.

  1. Setting the baud rate. From the Create 2 Open Interface Spec, page 4, the way to set the baud rate is to "wait 2 seconds after turning on Roomba and then pulse the baud rate change low three times." Your code only pulses the pin low once, so the robot wakes up but is not having its baud rate changed. You can fix this by changing your first wake up and baud rate change block as follows:
    // Wake up
      digitalWrite(ddPin, HIGH);
      delay(100);
      digitalWrite(ddPin, LOW);
      delay(500);
      digitalWrite(ddPin, HIGH);
      delay(2000);

    // Baud rate change
      for (int i = 0; i < 3; i++) {
        digitalWrite(ddPin, LOW);
        delay(200);
        digitalWrite(ddPin, HIGH);
        delay(200);
      }
  1. Serial port confusion. It seems like you're using software serial for some things (in setup()) but also hardware serial for others (in loop()). Stick to one or the other; for this, let's use the software serial port for the Create 2 as you've wired it, and the hardware serial port for debugging. Add Serial.begin(9600); to your setup() function, and then you can use the USB to serial UART through the "serial monitor" in the Arduino IDE for debugging.

  2. Confusion about how to use loop(). The loop() function runs over and over and over again. Had you been communicating over the correct serial port, you would just be slamming that drive command into the robot over and over and over again. Once is enough. You could either put it at the very end of your setup() function, or else put it in loop() and then go do something else, or wait, or delay forever. In my rewrite of your code, I've chosen to just busy-wait forever in a while(1).

  3. Missing cast of 0x00 literal in (soft)Serial.write(). Arduino has Serial.write overloaded, so if you just want to send a null character, you have to cast it as byte.

  4. Signal timings. You noted that you are "burning" the code onto your Arduino and then plugging the Arduino into the robot using jumper wires. Depending on the order you plug things in, various pulses or serial commands might happen before the robot is fully connected. You might consider adding a very long delay at the beginning of your code or (even better) adding a physical button to a GPIO on the Arduino that the code waits to be pressed before trying to talk to the robot.

  5. Power concerns. You note that you are plugging VBAT directly into the Arduino's VIN. Depending on the Arduino, this might be a problem. On the dock, VBAT can rise all the way to 21 V, but the Arduino Uno has a recommended operating maximum input voltage of 12 V, and absolute maximum of 20 V. You might consider adding another voltage regulator (or else being really careful not to plug the Arduino into your Create 2 while it's on the dock; it won't violate the absolute max of the Arduino when it's not charging).

Incorporating all these changes, here is the correct, working version of your code, tested on my Create 2 with an Arduino Uno:

#include <SoftwareSerial.h> 

int rxPin = 10; //connected to pin 4 (TXD) of iRobot Create 2
int txPin = 11; //connected to pin 3 (RXD) of iRobot Create 2
int ddPin = 5;  //connected to pin 5 (BRC) of iRobot Create 2

//Set up a new Software Serial Port
SoftwareSerial softSerial = SoftwareSerial(rxPin, txPin);

void setup() {

  Serial.begin(9600);

// Defining PinModes
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  pinMode(ddPin, OUTPUT);
  softSerial.begin(19200); 
 

  Serial.println("Wake up!");
  digitalWrite(ddPin, HIGH);
  delay(100);
  digitalWrite(ddPin, LOW);
  delay(500);
  digitalWrite(ddPin, HIGH);
  delay(2000);

  Serial.println("Set baud rate.");
  for (int i = 0; i < 3; i++) {
    digitalWrite(ddPin, LOW);
    delay(200);
    digitalWrite(ddPin, HIGH);
    delay(200);
  }

  Serial.println("Start OI in Safe Mode.");
  softSerial.write(128); //Starts the OI
  softSerial.write(131); //Set mode to Safe
}

void loop() {
  Serial.print("Arc left... ");
  softSerial.write(145);
  softSerial.write((byte)0x00);  
  softSerial.write(0xc8);
  softSerial.write((byte)0x00);
  softSerial.write(0x01);

  Serial.println("and do nothing else.");
  while(1);
}

I hope this helps. Sorry it's so late; I must have missed the question during the chaos of 2020.

Please note that I am an iRobot employee, but the postings on this site are my own and don't necessarily represent iRobot's positions, strategies, or opinions.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.