Go Down

Topic: xbee working but receiving strange chars? (Read 404 times) previous topic - next topic

spskeyes

I have two xbee radios configured as follows:

xbee1: ATRE,BD6,ID7374,MY0,DL1,D33,IC8, RR3,RO10,WR

xbee2: ATRE,BD6,ID7374,MY1,DL0,D33,IC8, RR3,RO10,WR

Both are connected to Arduinos programmed such that xbee1 sends a char to xbee2 every second. The programs are below. The problem is that xbee2 doesn't receive the char properly,  I see -68 and -72 from the Serial.println(c); when I look at the xbee2 board in the serial monitor. also the led never lights up.

If I connect  xbee2 directly to my computer and look at the ouput with minicom, I see it receives the chars 'l' and 'h' as it should. Any helpis much appreciated.

xbee1:

Code: [Select]
#include <SoftwareSerial.h>
SoftwareSerial XBee(2, 3); // Arduino RX, TX (XBee Dout, Din)
void setup()
{
  XBee.begin(57600);
}

void loop()
{
  XBee.write('l');
  delay(1000);
  XBee.write('h');
  delay(1000);
}



xbee2:

Code: [Select]

#include <SoftwareSerial.h>
SoftwareSerial XBee(2, 3); // Arduino RX, TX (XBee Dout, Din)
#define ledPin 13
void setup()
{
  pinMode(ledPin,OUTPUT);
  XBee.begin(57600);
  Serial.begin(57600);
}

void loop()
{
  if (XBee.available())
  {
    char c = XBee.read();
    Serial.print("got ");
    Serial.println(c);
    switch (c)
    {
    case 'h':     
      digitalWrite(ledPin,HIGH);
      delay(1000);
      break;
    case 'l':     
      digitalWrite(ledPin,LOW);
      break;
    }
  }
}




Power_Broker

Try 9600 Baud. For some reason XBees don't like going faster than that.

Also, it might work better if you change:


Code: [Select]


  if (XBee.available())
  {
    ...
  }
}



to:


Code: [Select]


  while (XBee.available())
  {
    ...
  }
}
"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

PaulS

The address 0 has special meaning. You should not be using it as MY or DL for either XBee.

Try using 5 and 6 as MY and DL.
The art of getting good answers lies in asking good questions.

spskeyes

Thanks. I followed all 3 suggestions and it works great now.

Cheers

Go Up