chipKIT® Development Platform

Inspired by Arduino™

XBee-Arduino API Lybraries

Created Mon, 03 Oct 2011 18:10:53 +0000 by Mattia743


Mon, 03 Oct 2011 18:10:53 +0000

You can found in google code (the system ask me to remove the link : Your post looks too spamy for a new user, please remove off-site URLs. ...???)


I'm trying XBee_arduino API with my new chipkit UNO....

When I try the RemoteAtCommand.pde sketch (I put XBee.h and NewSoftSerial.h in the right place) obtain :

RemoteAtCommand.cpp.o: In function __static_initialization_and_destruction_0': RemoteAtCommand.cpp:43: undefined reference to NewSoftSerial::~NewSoftSerial()' RemoteAtCommand.cpp:43: undefined reference to NewSoftSerial::NewSoftSerial(unsigned char, unsigned char, bool)' RemoteAtCommand.cpp:45: undefined reference to XBee::XBee()' RemoteAtCommand.cpp:57: undefined reference to XBeeAddress64::XBeeAddress64(unsigned int, unsigned int)' RemoteAtCommand.cpp:59: undefined reference to RemoteAtCommandRequest::RemoteAtCommandRequest(XBeeAddress64&, unsigned char*, unsigned char*, unsigned char)' RemoteAtCommand.cpp:62: undefined reference to RemoteAtCommandResponse::RemoteAtCommandResponse()' RemoteAtCommand.cpp.o: In function setup': RemoteAtCommand.cpp:65: undefined reference to XBee::begin(long)' RemoteAtCommand.cpp:67: undefined reference to NewSoftSerial::begin(long)' RemoteAtCommand.cpp.o: In function sendRemoteAtCommand()': RemoteAtCommand.cpp:104: undefined reference to XBee::send(XBeeRequest&)' RemoteAtCommand.cpp:107: undefined reference to XBee::readPacket(int)' RemoteAtCommand.cpp:111: undefined reference to XBee::getResponse()' RemoteAtCommand.cpp:111: undefined reference to XBeeResponse::getApiId()' RemoteAtCommand.cpp:139: undefined reference to XBee::getResponse()' RemoteAtCommand.cpp:139: undefined reference to XBeeResponse::getApiId()' RemoteAtCommand.cpp:143: undefined reference to XBee::getResponse()' RemoteAtCommand.cpp:143: undefined reference to XBeeResponse::isError()' RemoteAtCommand.cpp:145: undefined reference to XBee::getResponse()' RemoteAtCommand.cpp:145: undefined reference to XBeeResponse::getErrorCode()' RemoteAtCommand.cpp:112: undefined reference to XBee::getResponse()' RemoteAtCommand.cpp:112: undefined reference to XBeeResponse::getRemoteAtCommandResponse(XBeeResponse&)' RemoteAtCommand.cpp:114: undefined reference to RemoteAtCommandResponse::isOk()' RemoteAtCommand.cpp:116: undefined reference to RemoteAtCommandResponse::getCommand()' RemoteAtCommand.cpp:117: undefined reference to RemoteAtCommandResponse::getCommand()' RemoteAtCommand.cpp:120: undefined reference to RemoteAtCommandResponse::getValueLength()' RemoteAtCommand.cpp:135: undefined reference to RemoteAtCommandResponse::getStatus()' RemoteAtCommand.cpp:122: undefined reference to RemoteAtCommandResponse::getValueLength()' RemoteAtCommand.cpp:127: undefined reference to RemoteAtCommandResponse::getValue()' RemoteAtCommand.cpp:126: undefined reference to RemoteAtCommandResponse::getValueLength()' RemoteAtCommand.cpp.o: In function loop': RemoteAtCommand.cpp:87: undefined reference to AtCommandRequest::setCommand(unsigned char*)' RemoteAtCommand.cpp:88: undefined reference to AtCommandRequest::setCommandValue(unsigned char*)' RemoteAtCommand.cpp:89: undefined reference to AtCommandRequest::setCommandValueLength(unsigned char)' RemoteAtCommand.cpp:94: undefined reference to AtCommandRequest::clearCommandValue()' collect2: ld returned 1 exit status

....this is too mucj for me.... please help.... ;(



Mon, 03 Oct 2011 19:03:29 +0000

Ok.... I reply to myself.....

It was simple : create a folder called "libraries" in the folder where you save all the sketch.. and put inside THE FOLDERS of the libraries.... the restart MPIDE environment... Use Sketch, add library...

now all the errors reported before magically disappeared... but insted appear only :

/Users/matt/Dropbox/ChipKit/libraries/NewSoftSerial/NewSoftSerial.cpp:37:27: fatal error: avr/interrupt.h: No such file or directory compilation terminated.

...this seems to be a more complicated problem.... simulation of AVR under pic?? due to arduino absence of interrupts (but chipkit has)???!



Fri, 07 Oct 2011 16:27:28 +0000


I'm using a chipkit UNO32 and xbee series 1 in Api mode 2 to control the DO line of a remote xbee, and saving to SD card file all the message i need (because the serial port is used for communication between chipkit and xbee and I don't know ho to use another serial even software...see another my post)....

The question is :

The communication goes well, i'm able to operate correctly on the digital output of the remote xbee, but the problem is that I cannot receive any kind of response... see the attached Sketch and the correspondent SD log file...


thanks Matt

Sketch :

#include <SD.h> #include <XBee.h>

//SD init const int chipSelect = 4;

//Xbee init XBee xbee = XBee(); uint8_t irCmd[] = {'D','2'}; uint8_t ONValue[] = { 0x00, 0x05 }; uint8_t OFValue[] = { 0x00, 0x04 }; // SH + SL of your remote radio XBeeAddress64 remoteAddress = XBeeAddress64(0x0013a200, 0x407a66BB); // Create a remote AT request with the IR command RemoteAtCommandRequest remoteAtRequest = RemoteAtCommandRequest(remoteAddress, irCmd, ONValue, sizeof(ONValue)); // Create a Remote AT response object RemoteAtCommandResponse remoteAtResponse = RemoteAtCommandResponse();

void setup() { pinMode(10, OUTPUT); String dataString = "-----------START-------------"; //prova la carta if (!SD.begin(chipSelect)) { //Serial.println("Card failed, or not present"); // don't do anything more: return; } //carta ok, apri il file e poi inizializza Xbee File datafile ="test.txt", FILE_WRITE); xbee.begin(57600); if (datafile) { datafile.println(dataString); datafile.println("Carta OK, File Ok, Xbee Ok"); } datafile.close(); //aspetta che l'Xbee si associ delay(5000);


void loop(){

//send on sendRemoteAtCommand(); delay(3000); //send off remoteAtRequest.setCommand(irCmd); remoteAtRequest.setCommandValue(OFValue); remoteAtRequest.setCommandValueLength(sizeof(OFValue)); sendRemoteAtCommand(); delay(2000);


void sendRemoteAtCommand() {

File datafile ="test.txt", FILE_WRITE); datafile.println("Sending command to the XBee"); // send the command xbee.send(remoteAtRequest);

// wait up to 1 seconds for the status response if (xbee.readPacket(1000)) { // got a response!

// should be an AT command response if (xbee.getResponse().getApiId() == REMOTE_AT_COMMAND_RESPONSE) { xbee.getResponse().getRemoteAtCommandResponse(remoteAtResponse);

 if (remoteAtResponse.isOk()) {
    datafile.print("Command [");
    datafile.println("] was successful!");

   if (remoteAtResponse.getValueLength() &gt; 0) {
    datafile.print("Command value length is ");
    datafile.println(remoteAtResponse.getValueLength(), DEC);

    datafile.print("Command value: ");

     for (int i = 0; i &lt; remoteAtResponse.getValueLength(); i++)

{ datafile.print(remoteAtResponse.getValue()[i], HEX); datafile.print(" "); }

 } else {
   datafile.print("Command returned error code: ");
   datafile.println(remoteAtResponse.getStatus(), HEX);

} else { datafile.print("Expected Remote AT response but got "); datafile.print(xbee.getResponse().getApiId(), HEX); } } else { // remote at command failed if (xbee.getResponse().isError()) { datafile.print("Error reading packet. Error code: "); datafile.println(xbee.getResponse().getErrorCode()); } else { datafile.print("No response from radio"); } } datafile.close(); }

And SD log file :

-----------START------------- Carta OK, File Ok, Xbee Ok Sending command to the XBee No response from radioSending command to the XBee No response from radio


Sun, 09 Oct 2011 19:23:44 +0000

Nobody at Digilent can help me??


Mon, 10 Oct 2011 11:37:00 +0000

I'm using the xbee-arduino lib on a uno32 w/o any problems. I would suggest making a very simple test to begin with. If the examples provided with xbee-arduino do not work for you then it will be easier to pinpoint the issue.


Mon, 10 Oct 2011 12:53:21 +0000

Can You post your code & results? Just to know we're on The same issue




Mon, 10 Oct 2011 15:56:09 +0000

It's basically what was taken from the examples (I excluded unrelated code)...

#include &lt;XBee.h&gt;
XBee xbee = XBee();
void setup() {
  // If you want to use Serial1...
void loop() {
  byte payload[1];
  payload[0] = 13; // test data
int xbeeRead() {
  if (xbee.getResponse().isAvailable()) {
    if (xbee.getResponse().getApiId() == RX_16_RESPONSE) {
      Rx16Response rx16 = Rx16Response();
      // getData(0) == zero indicates the data at the supplied index does not exist
      int firstData = rx16.getData(0);
      return 1;
    } else if (xbee.getResponse().getApiId() == TX_STATUS_RESPONSE) {
      TxStatusResponse txStatus = TxStatusResponse();
      // get the delivery status, the fifth byte
      if (txStatus.getStatus() == SUCCESS) {
        return 2;
      } else {
        // the remote XBee did not receive our packet. is it powered on?
        return 0;
  return -1;
int xbeeSend(byte payload[]) {
  // with Series 1 you can use either 16-bit or 64-bit addressing
  // 16-bit addressing: Enter address of remote XBee, typically the coordinator 
  Tx16Request tx = Tx16Request(0x1234, payload, sizeof(payload));
  int xbeeRtn;
  while ((xbeeRtn = xbeeRead()) &lt; 0);
  return xbeeRtn;


Tue, 11 Oct 2011 20:02:21 +0000

Sorry but still won't work.... i get -1 so no response received.... the 2 xbees with java api work perfectly...

How you connect xbee to chipkit uno?


Tue, 11 Oct 2011 22:44:17 +0000

I use [url][/url] to connect a [url][/url] on the pc side. Then another [url][/url] to a breadboard which connects to a uno32.

Are you sure that you configured your xbees for API mode (outlined here: [url][/url])? Do you have series 1 or 2?


Wed, 12 Oct 2011 08:27:48 +0000

Thanks for reply to mine....

I have Series 1 and they works very fine when I use it with Java-API libraries via processing script.... So the same configuration, for end-device with the coordinator linked to Chipkit UNO32 won't work but don't totally... In particular, I'm able to send remote AT command from Chipkit+Xbee Coordinator to xbee end-device (I activate a DO line and I see the led attached going on and off as I remotely tell him, so it works...) The problems are that :

  1. I cannot receive any kind of response, but I see the RSSI led on the remote and coordinator blink correctly after sending command, so I'm pretty sure that the problem is software....
  2. after some commands the xbee coordinator hangs...




Wed, 12 Oct 2011 11:12:38 +0000

Can you provide both of your radio configurations from X-CTU?


Wed, 12 Oct 2011 18:23:07 +0000

Ok, here it is .....

With the same identical configuration they works very well with Xbee Java API library, so I'm pretty sure that there's nothing wrong in configuration...



Thu, 13 Oct 2011 01:22:34 +0000

Try setting CE to 0 on both radios and see what you get.

Also, what hardware are you using?


Fri, 14 Oct 2011 11:38:20 +0000

Ok, I don't know why it has to be useful, but I tried and no changes.... Also with both radio CE=0 still cam't receive response .... Chipkit developer?


Fri, 14 Oct 2011 12:28:40 +0000

Has hardware I use to connect Xbee to Chipkit...

The two rear pins (DIN=RX) and (DOUT=tx) are connected respectively to pin (40 tx of serial1) and (39 rx of serial1)...

By testing i'm extremely sure that for sending command from chipkit to xbee it's all ok (in fact the command is received from remote xbee that activate a Digital output line).... but I can't receive response ... (even i get "No response from remote radio" ref to the examples in the library)..... :(

I also try with sending at command directly to main radio (no remote) and still the same....