1
\$\begingroup\$

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.

It's a pretty basic circuit.

The coordinator has a button 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 it was, it checks if the correct byte is received. If so, it turns on the LED. But, no matter what I do, I am not able to turn on the LED. I appreciate your help.

The code for the 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); 
        }
      } 
   }
}
\$\endgroup\$
  • \$\begingroup\$ Just for clarification: I assume you are using XBee 2 series modules and as such have flashed them with the required firmware and set them to AP=2? \$\endgroup\$ – SimonBarker Jul 3 '13 at 10:48
  • \$\begingroup\$ yes i have done all that. \$\endgroup\$ – user734861 Jul 3 '13 at 17:30
  • \$\begingroup\$ 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 \$\endgroup\$ – user734861 Jul 5 '13 at 20:53
2
\$\begingroup\$

I fixed the problem. If you look at the code, you'll notice that I had not specified pinmode of the input and output pins.

The fix is to include the following lines in the router and coordinator code, respectively:

  • The line below is missing in router code:

    pinMode(8,  OUTPUT);
    
  • And the line below is missing in coordinator code:

    pinMode(7,  INPUT);
    
\$\endgroup\$
  • 1
    \$\begingroup\$ A pretty common mistake I've seen on the arduino questions on this board. AVR's default to high impedance (Input mode) on all the pins so the second declaration is not strictly necessary \$\endgroup\$ – crasic Aug 4 '13 at 22:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.