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);
*/
}
#########################