I am having a problem with my code. There, I said it. I am trying to do an Arduino controlled Xbee Robot... The problem I am having relates to the Arduino and its handling of information sent to it via SoftwareSerial. Here is my code:
#include <SoftwareSerial.h>
SoftwareSerial XBEE(2, 4);
#include <Robot.h>
Robot robot(5, 8, 6, 9);
void setup(){
//Serial.begin(9600);
XBEE.begin(9600);
}
void loop(){
//XBEE.println("Checking");
if(XBEE.available() > 0){
XBEE.println("Available");
if(char(XBEE.read()) == 'A'){
XBEE.println("Detected A");
int AVal = XBEE.parseInt();
if(AVal < 0){
robot.Reverse(1, abs(AVal));
}
else{
robot.Forward(1, abs(AVal));
}char B = XBEE.read();
//if(char(XBEE.read()) == 'B'){
XBEE.println("Detected b");
int BVal = XBEE.parseInt();
if(BVal < 0){
robot.Reverse(2, abs(BVal));
}
else{
robot.Forward(2, abs(BVal));
}
//}
}
}
}
I send 'A' + the value for that motor + 'B' + plus the value for the second motor, and then the arduino should apply that with the library. The code above is slightly modified for diagnostics. Here is the original:
#include <SoftwareSerial.h>
SoftwareSerial XBEE(2, 4);
#include <Robot.h>
Robot robot(3, 12, 11, 13);
void setup(){
//Serial.begin(9600);
XBEE.begin(9600);
}
void loop(){
//Serial.println("Checking");
if(XBEE.available() > 0){
//Serial.println("Available");
if(char(XBEE.read()) == 'A'){
// Serial.println("Detected A");
int AVal = XBEE.parseInt();
if(AVal < 0){
robot.Reverse(1, abs(AVal));
}
else{
robot.Forward(1, abs(AVal));
}
if(char(XBEE.read()) == 'B'){
// Serial.println("Detected b");
int BVal = XBEE.parseInt();
if(BVal < 0){
robot.Reverse(2, abs(BVal));
}
else{
robot.Forward(2, abs(BVal));
}
}
}
}
}
I have tested it on another robot(thecentralthinkingunit.blogspot.com explains it all) and the program works. The only change is that I am using:
A: the arduino motor shield
B: Xbee Series 2 rather than S1
All the arduino does is say, when running the first program, "Available
Detected A
Detected b
" but not turn on the motors...
The Robot library(another one of my recent works) is attached.
All help is appreciated.
Thanks,
L
keywords.txt (65 Bytes)
Robot.cpp (1.43 KB)
Robot.h (476 Bytes)