Configuring Xbee without PC

Hi All

I am new this forum. I am developing a logger which transmits data wirelessly after logging is finished. I am using PIC 18F67k22 on both receiver and Transmitter. I am thinking of using xbee. But I dont want to configure using a pc. I want to do it in my code. can I configure xbee in my code itself?? My only concern here is ease of use.I want to know which one is easier xbee or nordic nrf24l01?? any help is appreciated. Thanks

Yes, an XBee can be configured by any a PIC or any processor with a serial interface.

With a PC one typically uses the X-CTU utility which makes configuring easy since it has all of the XBee parameters listed. X-CTU then just writes the command sequence to the XBee’s serial port to set the configuration.

Without X-CTU you just write your code to write these command sequences to the XBee. Study the XBee document to learn how to write these commands. Pay attention to AT verse API command sequences. For doing this from a processor I prefer have the XBee in API command mode and then use the API Frames to send commands.

I know nothing about the nrf24l01 so can not compare.

You can even remotely change the settings of an xbee module through an API command. The payload of the remote configuration packet is pretty much identical to an AT command. So you would not need an directly attached microcontroller to send the command. Unless it is the source of the data to be transmitted over the link.

Thanks guys. I will look into the xbee documentation.API mode sounds good.

There are simplifying libraries for the XBee - including Arduino and others.

Saves a lot of time.

Hi,

Since I have no xBee USB adapter (only the xBee connected to Arduino via an xBee shield) I am trying to configure the xBee programmatically using their code examples, sending AT commands. But I keep there is no response from the radio.

What am I missing?

In AT command mode you need to send the +++ then wait a specific time then send the commands within a specific time. This can be quit tricky but there has been much written about this on the web. If any of the timing constraints are missed the XBee quietly ignores the command. Did you do searches as there are a number of examples and discussions about doing this including in the SparkFun forum?

Metheny:
Hi,

Since I have no xBee USB adapter (only the xBee connected to Arduino via an xBee shield) I am trying to configure the xBee programmatically using their code examples, sending AT commands. But I keep there is no response from the radio.

What am I missing?

How can you tell what the Arduino is receiving from the Xbee? Is there a seperate( USB) serial link to the PC? Or some sort of display? The Arduino model might be important to know aswel.

I did send the “+++” command at the beginning with a 5 second delay after, apparently it does not help.

I have the Arduino UNO. The Arduino is connected via USB to the PC, and can send data through the serial connection (e.g. text, which can be displayed in a logging window in the Arduino programming environment). So in the AT commands example they log the result of each command sent to the xBee.

Metheny:
…So in the AT commands example they log the result of each command sent to the xBee.

What example/tutorial? My Magic Orb is in repair. Please provide a link or something.

This is the code, it’s a bit long.

I altered their original example a bit, which didn’t have the “+++” at the beginning:

So basically I send a “+++” at the beginning, wait a few seconds, and then send a few more commands, but none work.

// Define NewSoftSerial TX/RX pins
// Connect Arduino pin 9 to TX of usb-serial device
uint8_t ssRX = 9;
// Connect Arduino pin 10 to RX of usb-serial device
uint8_t ssTX = 10;
// Remember to connect all devices to a common Ground: XBee, Arduino and USB-Serial device
//NewSoftSerial nss(ssRX, ssTX);

XBee xbee = XBee();

uint8_t cfgCmd[] = {'+','+','+'};
// serial high
uint8_t shCmd[] = {'S','H'};
// serial low
uint8_t slCmd[] = {'S','L'};
// association status
uint8_t assocCmd[] = {'A','I'};

AtCommandRequest atRequest = AtCommandRequest(cfgCmd);

AtCommandResponse atResponse = AtCommandResponse();

void setup() { 
  xbee.begin(9600);
  // start soft serial
  Serial.begin(9600);
  
  // Startup delay to wait for XBee radio to initialize.
  // you may need to increase this value if you are not getting a response
  delay(5000);
}

void loop() 
{
    sendAtCommand();
    
    delay(5000);

  // get SH
    atRequest.setCommand(shCmd); 
  sendAtCommand();
  
  // set command to SL
  atRequest.setCommand(slCmd);  
  sendAtCommand();

  // set command to AI
  atRequest.setCommand(assocCmd);  
  sendAtCommand();
  
  // we're done.  Hit the Arduino reset button to start the sketch over
  while (1) {};
}

void sendAtCommand() {
  Serial.println("Sending command to the XBee");

  // send the command
  xbee.send(atRequest);

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

    // should be an AT command response
    if (xbee.getResponse().getApiId() == AT_COMMAND_RESPONSE) {
      xbee.getResponse().getAtCommandResponse(atResponse);

      if (atResponse.isOk()) {
        Serial.print("Command [");
         Serial.print(atResponse.getCommand()[0]);
        Serial.print(atResponse.getCommand()[1]);
        Serial.println("] was successful!");

        if (atResponse.getValueLength() > 0) {
          Serial.print("Command value length is ");
          Serial.println(atResponse.getValueLength(), DEC);

          Serial.print("Command value: ");
          
          for (int i = 0; i < atResponse.getValueLength(); i++) {
            Serial.print(atResponse.getValue()[i], HEX);
            Serial.print(" ");
          }

          Serial.println("");
        }
      } 
      else {
        Serial.print("Command return error code: ");
        Serial.println(atResponse.getStatus(), HEX);
      }
    } else {
      Serial.print("Expected AT response but got ");
      Serial.print(xbee.getResponse().getApiId(), HEX);
    }   
  } else {
    // at command failed
    if (xbee.getResponse().isError()) {
      Serial.print("Error reading packet.  Error code: ");  
      Serial.println(xbee.getResponse().getErrorCode());
    } 
    else {
      Serial.print("No response from radio");  
    }
  }
}

That code is insufficient to tell what each function in it does. Really, to be able to help I need to be able to know which API this is so I can look further what the code does.

You really should get yourself an XBee USB Explorer (or similar device from some vendor) This Xbee could be configured in a way that it does not respond to the +++ code. (by some previous goof-up) You need a direct way to access, check and possibly reset to factory conditions, the configuration of the device with XCTU. Or else you are working blind.

I’m using this API:

http://code.google.com/p/xbee-arduino/

Of course the easiest way is to buy an USB Explorer, but I would still like to give it a try.

Sending commands with the X-CTU or via this API should be the same (factory reset should also be possible, by sending the “RE” command with the code I attached).

From that link:

Note: This software requires API mode, by setting AP=2.

So, you can’t use this api to send +++ and use the AT commands that way. It requires the AT commands to be send encapsulated into an API packet. But the XBee is likely still in transparent mode, so this library is of no use now.

You’ll have to find a different API/library (that can use transparent mode by default), or make your own sketch to change it settings. So, send +++, wait for OK, then send AT commands, etc.

Ok, I’ll try an find such an API.

Can you please tell me how should I set the DLINE / UART switch? Which settings should be used in which cases?

Thanks!

Have you read the XBee module manual?