pastebin - collaborative debugging tool
blankb.kpaste.net RSS


Arduino XBEE Lib Example
Posted by Anonymous on Thu 24th Mar 2016 03:02
raw | new post

  1. //Sender
  2. #include <XBee.h>
  3. XBee xbee = XBee();
  4.  
  5. void setup()
  6. {
  7.   Serial.begin(9600);
  8.   // Tell XBee to use Hardware Serial. It's also possible to use SoftwareSerial
  9.   xbee.setSerial(Serial);
  10. }
  11.  
  12. void loop()
  13. {
  14.   uint8_t payload[] = { 'H', 'e', 'y' };
  15.   XBeeAddress64 addr64 = XBeeAddress64(0x0000, 0xFFFF);
  16.   ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
  17.   xbee.send(zbTx);
  18.   delay(3000);
  19. }
  20.  
  21. //Receiver
  22. #include <XBee.h>
  23. XBee xbee = XBee();
  24. ZBRxResponse rx = ZBRxResponse();
  25.  
  26. void setup()
  27. {
  28.   Serial.begin(9600);
  29.   Serial.println("Boot...");
  30.  
  31.   Serial1.begin(9600);
  32.   xbee.begin(Serial1);
  33.  
  34. }
  35.  
  36. void loop()
  37. {
  38.   xbee.readPacket();
  39.   if (xbee.getResponse().isAvailable())
  40.   {
  41.     Serial.println("Got Something.");
  42.     xbee.getResponse().getZBRxResponse(rx);
  43.    
  44.     for (int i = 0; i < rx.getDataLength(); i++)
  45.     {
  46.            Serial.write(rx.getData(i));
  47.     }
  48.     Serial.println(" ");
  49.   }
  50. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}





All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at