XBees Refuse to Talk

Hi all!

I'm new to XBee, and have been trying for about a week to get two modules to talk to one-another with NewSoftSerial. I have two Arduinos. One Duemilanove + XBee + Adafruit breakout board connected to my computer (coordinator). And a Mega + XBee + Adafruit breakout board for the end-point.

I started by following LadyAda's XBee tutorial, but it seems to be missing some pieces (or at least it didn't work for me when I tried it).

I've set the network id's to 1337. Both have unique MY's. Arduino's have Rx to pin 2, Tx to pin 3. Since this didn't work, I've since upgraded firmwares and set the destinations to the specific S/N of each unit (both high and low for both coordinator and end-point).

I thought I had them working when I swapped the pins (Tx to 2, Rx to 3), but the coordinator was getting data that it was sending. Oddly enough, the coordinator would get the data when the end-point should have sent it.

Code is as follows...

Coordinator:

#include <NewSoftSerial.h>

// --> mLight Server <--

boolean conn=false;

NewSoftSerial xbee(2,3);

void setup(){
  xbee.begin(9600);
  Serial.begin(9600);
  Serial.println("> mLight Online <");
}

char* getData(){
  char* tmp;
  while (xbee.available()){
    *tmp++ = (char)xbee.read();
  }
  
  return tmp;
}

void loop(){
  if (!conn){
    xbee.print("HELLO");
    delay(500);
    
    Serial.println(getData());
  }
  
  delay(500);
}

End-point:

#include <NewSoftSerial.h>

// --> mLight Client <--

NewSoftSerial xbee(2,3);

void setup(){
  xbee.begin(9600);
}

void loop(){
  xbee.print("HIYO");
  delay(1000);
}

They got really basic after the XBees refused to properly communicate...

If I swap the pins back to how it should look (I think), I get no data being sent back-n-forth.

Sorry if I'm confusing, I've tried basically everything to get NewSoftSerial to talk with my XBees. My power lights go on, but the only way to get the RSS lights to trigger is to hook them up with what I assume is backwards (but I don't know anymore).

Thanks in advance for any help. Adafruit forums were essentially useless for me. On one final note, Adafruit sent me two different (but basically the same units). One just displays Digi's tag and "S1" on the face, while the other display's MaxStream's tag with no "S1".

Take the xBees out of the loop first. wire from pin 2 of one Arduino to pin 3 of the other and visa versa. Also connect the grounds. Run your sketch and make sure you see data. Then wire to the xBees and don't configure anything (reset to factory defaults). That should work. The reason for setting up addresses is so that you only get the traffic you are interested in. If you don't configure, they get everything. But if they are the only xBees at your bandwidth in range, then there is nothing else to filter out. Once they worke like that, then proceed to adding the addresses.

What I am asking is that you first make sure your basic serial communication is working, then make sure the xBees work at base level and them add in their tighter protocol.

char* getData(){
  char* tmp;
  while (xbee.available()){
    *tmp++ = (char)xbee.read();
  }
  
  return tmp;
}

Since you haven't actually allocated any space, tmp is a NULL pointer. Incrementing a NULL pointer, and storing data at the new non-existent location generally causes an exception to be thrown. But, since the Arduino doesn't ave exception handling, it pretends that the increment and assignment worked, even tough they haven't.

Might that explain why you think they don't talk?

What kind of XBees are they?

Great catch (pun intended), Paul!
Those were a nightmare back in my firmware days. I did mostly Intel and similar chips, which like the PROM up high in the address space and RAM down low (ISR pointers were stored in specific locations down in the first page, for example, so you needed writable memory down there). So NULL pointers were totally legitimate except they kind of trashed the system area...

If that doesn't fix it, then step 2 is to test just serial...