Hey Guys,
I've racked my brain and scoured the Internets trying to find a solution to my, what seems to be, different problem. First, the formalities:
I have two XBee S1 radios configured as PID:332,DL:0,MY:1 and PID:332,DL:1,MY:0
1 XBee connected to computer via XBee Explorer
1 XBee connected to arduino via XBee Explorer Regulated (DOUT to arduino RX, DIN to arduino TX)
My baud rates are consistent throughout the path, including the sketch. I've tested various rates (9600, 19200, 57600) to no avail and I'm currently set at 19200.
The sketch is driving two motors using an Ardumoto based on values received in a case statement: A (motor A fwd), a (motor A bkwd), B (motor B fwd), b (motor B bkwd), and S (stop all).
switch(input) {
case 'A':
// motor A forwards
analogWrite(PwmPinMotorA, 200);
digitalWrite(DirectionPinMotorA, HIGH);
break;
case 'a':
// motor A reverse
analogWrite(PwmPinMotorA, 200);
digitalWrite(DirectionPinMotorA, LOW);
break;
case 'B':
// motor B forwards
analogWrite(PwmPinMotorB, 200);
digitalWrite(DirectionPinMotorB, LOW);
break;
case 'b':
// motor B reverse
analogWrite(PwmPinMotorB, 200);
digitalWrite(DirectionPinMotorB, HIGH);
break;
case 'S':
analogWrite(PwmPinMotorA, 0);
analogWrite(PwmPinMotorB, 0);
digitalWrite(DirectionPinMotorA, LOW);
digitalWrite(DirectionPinMotorB, LOW);
break;
default:
analogWrite(PwmPinMotorA, 0);
analogWrite(PwmPinMotorB, 0);
digitalWrite(DirectionPinMotorA, LOW);
digitalWrite(DirectionPinMotorB, LOW);
break;
}
With the XBee connected to the computer and the arduino XBee run by a 9v battery, I open the arduino serial monitor to manually pass the commands to see the results using:
while (!Serial.available()); // wait for input
input = Serial.read(); // read it in
Serial.print("what i got: ");
Serial.println(input, DEC);
When I type A, a, B, or b, the response is something like this in my println:
what ý
what ýwhat é
However, if I type 'S' (which is the stop all motors command) or any other value not used like 'Q' or 'x', I received expected values in my println which indicates the XBees are communicating with each other just fine:
what i got: 83
what i got: 81
what i got: 120
It appears the Ardumoto may have a play in these ill results and I've tried dabbling with different delay values in various spots of the sketch thinking the XBees needed more time to tx/rx commands. I'm at a loss and hoping the community can help me.
BTW, the sketch works beautifully if I eliminate the XBees altogether and use a direct USB connection.
Thanks in advance for your help and let me know if I need to provide any additional info!