no luck trying to make two xbees communicate in api mode with arduino xbee libra

I have been trying to make two xbees communicate for a long time. I have checked everything and at last i come here for some help from the experts or who have already stumbled upon the same problem as mine. I am using series 2 xbees.

I am using this library

Its a pretty basic circuit.

The coordinator has a buttion. And the router has led. When i press button on coordinator, i send two bytes as payload to the router. The router checks if packet was received if yes, it checks if the correct byte is received. If yes, it turns on the led. I am not able to turn on the led no matter what i do. I appreciate your help.

The code for coordinator(sender):

#include <XBee.h>


// create the XBee object
XBee xbee = XBee();

uint8_t payload[] = { 0, 0 };

// SH + SL Address of receiving XBee
XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x408698be);
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
ZBTxStatusResponse txStatus = ZBTxStatusResponse();

int pin5 = 0;

void setup() {

  Serial.begin(9600);
  xbee.setSerial(Serial);
}

void loop() {   

  payload[0] = 0x34;
  payload[1] = 0x76;



if (digitalRead(7) == HIGH){


  xbee.send(zbTx);

  delay(1000);

}

}

And the code for router(receiver) is:

#include <XBee.h>


XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
// create reusable response objects for responses we expect to handle 
ZBRxResponse rx = ZBRxResponse();
ModemStatusResponse msr = ModemStatusResponse();


void setup() {

  // start serial
  Serial.begin(9600);
  xbee.begin(Serial);

}

// continuously reads packets, looking for ZB Receive or Modem Status
void loop() {

    xbee.readPacket();

    if (xbee.getResponse().isAvailable()) {
      // got something

      if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
        // got a zb rx packet

        // now fill our zb rx class
        xbee.getResponse().getZBRxResponse(rx);

        //i check both bytes (or)
        if(rx.getData(0) == 0x34 || rx.getData(0) == 0x76 ){
         digitalWrite(8, HIGH); 
        }

      } 

}
}

Thank you!

Which XBee modules are you using, S1 or S2?

How are they hooked to the Arduinos?

Which Arduino boards are you using?

What does your Serial output is telling you is happening? Oh, wait. You don't have any. Why not?

@oric

I have already mentioned above that i am using series 2 xbee. Also you should easily infer how it is hooked since its a simple circuit with coordinator having button and router having led. By reading the pin numbers in the code you should be able to infer how the circuit is hooked and i am using arduino uno. Thanks!

series 2 xbee. Also you should easily infer how it is hooked since its a simple circuit

"easily infer" ... yeah.

Sorry, missed the 1st part, but hookup is the bane of XBee users about 99% of the time.
Crappy shield designs, hooking 5V to 3.3V pins, trying to connect XBee and USB
simultaneously to the UNO Rx,TX pins. Not so simple.

@oric

i am pretty sure there is no problem with the connection. I have very carefully hooked up the circuit and checked multiple times. I also take out xbee before programming uno and also the power is right i.e 3.3 v from arduino. Thank you!

i am pretty sure there is no problem with the connection.

Instead of bitching that the request is for information that is in the sketch (it was not), you should be saying "I'm certain the wiring is right because I'm using shield XXX". Then, you don't have to be "pretty sure". You can be certain.

Until you do describe EXACTLY how the XBee and the Arduino are connected, I won't be having any more to say on this subject.

I fixed the problem. The problem was if you look at the code, i haven't specified pinmode of the input and output pins.

pinMode(8, OUTPUT); is missing in router code and

pinMode(7, INPUT); is missing in coordinator code

pinMode(7, INPUT); is missing in coordinator code

That's OK because the pins default to input.

pinMode(8, OUTPUT); is missing in router code

That's a problem. Since the pin defaults to input, all you were doing was turning on and off the pullup resistor. Good catch.