XBee S1 on arduino uno r3 - inconsistent received data

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!

Are you using the same 9V battery to power the motors as well?
A PP3 9V battery can supply (not much) current.

I use 8 NimH batteries, that's 9.6V no load, with a Mega attached that drops to around 8.5V,
when my XBee is transmitting that drops the voltage down to 7.5 - 7.8V.
Around about then is where the 5V regulator is going to have problems.
Your USB port would be able to supply WAY more grunt than a PP3!

I have two XBee S1 radios configured as PID:332,DL:0,MY:1 and PID:332,DL:1,MY:0

0 is the broadcast address. It is not valid as a MY address.

Thanks for replying Guys! Looks as though each of you found a problem..

PaulS: After changing the MY to 2 on one XBee and DL to 2 on the other I saw activity in the motors and correct responses in the serial monitor with the 9v for a bit. But then it starting getting intermittent again which makes me believe cyberteque is right on queue with the power issue. I did go back to the XBee manual and while they're example shows 0x01,0x02 for MY source addresses they don't mention not using 0 - a bit misleading given 0 is the default. In any case, thanks for getting me in the right direction.

cyberteque: I was trying to power everything from 1 PP3 9v and I also tried with 4xNiMH 2650mA. After making the change above, the 9v had some response but the 4 NiMH's are clearly not enough (I was seeing original results in the serial monitor). I have my eye on one of the Polymer batteries at sparkfun (http://www.sparkfun.com/products/8483) which I'll probably end up buying but I'll go pick up an 8 battery holder today as I have enough NiMH to at least test with in the meantime.

Thank you both and I'll post the results as soon I test with 8 batteries.

Awesome! The MY address change and 8xNiMH did the trick - thank you very much!!