0
$\begingroup$

I am new to the iRobot Create 2 but I do know a thing or two about the Arduino (don't assume too much though). However, in this case, I am beyond stumped over what I am sure is something simple but is somehow not obvious to me. Three people have confirmed my wiring from the Create 2 to the Arduino to be correct and the code I have looks similar to many examples that I have seen on this forum. However, I cannot get my Create 2 to do ANYTHING. I am not at all sure what is wrong and I am starting to wonder if the robot is even receiving commands let alone doing anything with them. Is there anything wrong with this code and can anybody suggest a way to verify that the robot is receiving data (since it does not beep or provide return messages)? Thank you.

EDIT (06/24 01:10 EST); Updated code (with a few notes).

#########################
#include <SoftwareSerial.h>
#include <SPI.h>

int baudPin = 17;
int i;
int ledPin = 13;
int rxPin = 19;
int txPin = 18;

unsigned long baudTimer = 240000; // 4 minutes
unsigned long thisTimer = 0;
unsigned long prevTimer = 0;

SoftwareSerial Roomba(rxPin, txPin);

void setup() {
  pinMode(baudPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);

  // I have tired communicating with both baud rates (19200 and 115200).
  // When trying the 115200 baud, I set "i<=0;" in the loop below since
  // the pulse does not need to be sent.
  Roomba.begin(19200);
  Serial.begin(115200);
  delay(2000);

  // I hooked up an LED in series with the baudPin so that it would turn
  // off when low thus giving me some kind of visual confirmation that a
  // pulse is being sent. See additional note in loop() below.
  for (i = 1; i <= 3; i++) {
    digitalWrite(baudPin, HIGH);
    delay(100);
    digitalWrite(baudPin, LOW);
    delay(500);
    digitalWrite(baudPin, HIGH);
  }

  // I know this might not be the right way to send data to the robot,
  // but I was fiddling with this while trying to figure out a separate
  // problem regarding the TX/RX lines which I am putting off until I
  // get the baud issue straightened out.
. /*
    int sentBytes = Roomba.write("128");
    Serial.print(sentBytes);
    Serial.print("\n");
  */

  i = 0;
}

void loop() {
  thisTimer = millis();

  // The LED that I have hooked up in series with the baudPin blinks
  // when the pulse is low, thus indicating that a pulse is being sent.
  // However, it only seems to wake the robot when it is asleep. If the
  // robot is already awake when the pulse is sent, it has no affect and
  // the robot will fall asleep a minute later.
  if (thisTimer - prevTimer > baudTimer) {
    prevTimer = thisTimer;
    i = 10;
    Serial.print("Sending pulse...\n");
    digitalWrite(baudPin, LOW);
    delay(500);
    digitalWrite(baudPin, HIGH);
  }

  /*
    i++;
    Serial.print(prevTimer);
    Serial.print(" --> ");
    Serial.print(thisTimer);
    Serial.print(" --> ");
    Serial.print(i);
    Serial.print("\n");
    delay(1000);
  */
}
#########################
$\endgroup$
2
  • $\begingroup$ One note that I forgot to add before is that the serial monitor does print the value of thisTimer...but the baudPin does not appear to get a pulse as the robot eventually falls asleep. $\endgroup$ Jun 23, 2016 at 11:48
  • $\begingroup$ I've been having the exact same issue, we also determined that a pulse had been sent although the Roomba has yet to respond. When we went on the icreate projects website, there was an online program(with inaccessible code) which worked directly from serial to usb. Then, when coding virtually the exact translation into C# in Visual studios again through usb to serial, we were able to control it with no issue whatsoever. Its strange because previously with the same code and setup it was working and just stopped one day. Have you had any success with other methods? $\endgroup$
    – josephine
    Jul 31, 2017 at 17:13

1 Answer 1

1
$\begingroup$

It looks like you're trying to initialize two different baud rates:

Roomba.begin(19200);
Serial.begin(115200);

So, first off I don't think it would work to have your setup using two different rates (though I may be wrong). But, more importantly, from the manual

By default, Roomba communicates at 115200 baud. If you are using a microcontroller that does not support 115200 baud, there are two ways to force Roomba to switch to 19200:

Method 1:

While powering off Roomba, continue to hold down the Clean/Power button after the light has turned off. After about 10 seconds, Roomba plays a tune of descending pitches. Roomba will communicate at 19200 baud until the processor loses battery power or the baud rate is explicitly changed by way of the OI.

Method 2:

Use the Baud Rate Change pin (pin 5 on the Mini-DIN connector) to change Roomba’s baud rate. After turning on Roomba, wait 2 seconds and then pulse the Baud Rate Change low three times. Each pulse should last between 50 and 500 milliseconds. Roomba will communicate at 19200 baud until the processor loses battery power or the baud rate is explicitly changed by way of the OI.

Did you put it in the 19200 mode? Have you tried 115200?

$\endgroup$
11
  • $\begingroup$ Method 2 is what I have tried doing [that is the loop within setup()] AND have tired both baud rates (19200 with the loop and 115200 without the loop) with no apparent success...but that is part of my problem. How can I tell if the robot received the baud rate change commands that I send it? $\endgroup$ Jun 23, 2016 at 14:19
  • $\begingroup$ @TonyTzankoff - Method 1 would be seemingly the easiest way, both to do and confirm. Hold the power button util it plays a tune for you. It stays in 19200 until you pull the battery. Have you tried setting Serial.begin(19200)? $\endgroup$
    – Chuck
    Jun 23, 2016 at 14:24
  • $\begingroup$ Yes. Method 1 would be easier. However, I will be putting a platform (and subsequent body) on top of the robot and reaching the button will no be the easiest of tasks. Look up "Belvedere robot" on YouTube to see what I am talking about) $\endgroup$ Jun 23, 2016 at 14:41
  • $\begingroup$ @TonyTzankoff - For the moment, I would try setting Serial.begin(19200), Roomba.begin(19200), and using Method 1 to get the robot in 19200 mode. If that works, then you can try pulling the battery to reset it, then use 115200 for both Serial and Roomba and seeing if that works. Start small and work up. $\endgroup$
    – Chuck
    Jun 23, 2016 at 14:42
  • $\begingroup$ I have made something of a discovery over here. It seems that the baud pulse is being sent. However, in some cases, it does not keep the robot awake. For example, I now have the pulse set to be sent every four minutes. At the 4:00 mark, the pulse appears to be sent (as per the serial monitor feedback). At the 5:00 mark, the robot goes to sleep (due to supposed inactivity). Four minutes later, another pulse is sent and the robot wakes up again. $\endgroup$ Jun 23, 2016 at 15:37

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.