SparkFun Forums 

Where electronics enthusiasts find answers.

All things pertaining to wireless and RF links
By jysgymg
#188819
Greetings all,

I have a question to ask about the XBee codes pertaining to reading 2 XBees Series 2. 1 of which is the Coordinator API and the other the Router AT.

Both are plugged onto a wireless proto shield and the shield onto a MEGA for the Coordinator API, UNO for the Router AT.
The wireless proto shields have their tx and rx pins bent so that they will not be connected tx to tx and rx to rx on the Arduino MEGA and UNO. I use wires instead to manually connect the tx to rx and rx to tx.

Now, my plan is to send Hello World every 1 second from my Router and my Coordinator will receive it. The codes are below,

Router AT:

void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("Hello World");
delay(1000);
}

Coordinator API:
void setup() {
Serial.begin(9600);
Serial3.begin(9600);
}
void loop() {
if(Serial3.available() > 21) {
if(Serial3.read() == 0x7E){
for(int i=0; i<33; i++) {
Serial.print(Serial3.read(), HEX);
Serial.print(",");
}
Serial.println();
}
}

So the above codes work perfectly. I do read the API Hex frames from the Router so on my serial log it appears like this:
0 12 90.... checksum byte. (7E does not appear due to the if statement check).

So heres my question, when I change to the Arduino library which is:
https://github.com/andrewrapp/xbee-ardu ... Bee.h#L413

and all my codes include arduino library, I am unable to receive the "Hello World" anymore.

My router stays the same, only my Coordinator API changes its codes which are below:
//Some demo codes I extracted.
#include <EEPROM.h> //I am not sure about this library yet
#include <SoftwareSerial.h> //ditto on this library but from my understanding, something to do with the serial begin?
#include <XBee.h> //XBee library from the above link
#include <Streaming.h> //http://arduiniana.org/libraries/streaming/

XBee xbee = XBee(); //XBee object
ZBRxResponse rx = ZBRxResponse(); //XBee receive response
//XBeeResponse rx = XBeeResponse();

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

void loop(void)
{
xbee.readPacket(); //unsure what this function does
Serial << "Hello" << endl; //this is printed infinitely
if (xbee.getResponse().isAvailable()) {
Serial << "Hello1" << endl; //does not print this line
switch (xbee.getResponse().getApiId()) { //what kind of packet did we get?
Serial << "Hello2" << endl; // does not print this line
case ZB_RX_RESPONSE: //rx data packet
xbee.getResponse().getZBRxResponse(rx); //get the received data
switch (rx.getOption()) {
case ZB_PACKET_ACKNOWLEDGED:
Serial.print("Packet received"); // does not print this line
break;
}
}
}
}

As this above codes mentioned, I am only able to print Hello from the 2nd line in the void loop, but am unable to do anything else. BUT, if I were to change
if (xbee.getResponse().isAvailable()) {
to
if(Serial3.available() > 21) {
it continues to run down the chain and Hello1 will be printed.

So my questions are:
1. Is that xbee library only for series 1?
2. Must my router be in API mode as well?
3. I tried wiring the Din and Dout to tx and rx but is this also one of the case?
4. Is there anything wrong with the codes?

Any guidance would be appreciated. Thanks!