Configuring the XBee with a Send and Receive Program

MUSIC GENRE of 2015

The IoT is so much more than just connecting disparate blocks of hardware together — comprehensive data connectivity is an integral part of innovation when it comes to automation. Qruize’s IoT team is forever tinkering with ideas and we’re all set to share some of the approaches on this blog.

One of the commonly used communication protocols between devices is the Zigbee protocol. XBee from digi supports this protocol very comfortably. IoT projects can use Zigbee/ XBee for both internal and external communications in a network.

For those who have worked with the Arduino and are ready to start off with the XBee, go through this exercise. Once you have got it working, experiment on changing values, checking conditions, well its up to you.

In this note, we will explain the following,

  1. Configuring a Zigbee network consisting of two XBee’s.
  2. A program to send and receive data over the XBee’s using Arduino .
  3. Sending temperature data over the XBee’s

In any network of XBee’s there has to be one coordinator. There can only be one coordinator. For our exercise, we will have two XBee’s, one configured as a coordinator and the other as an end device.

  1. Take one XBee and mark it as “C” – for coordinator.
  2. Download and install X-CTU from digi.com/xctu
  3. Mount the ‘C’ XBee on an XBee explorer board and connect the same to a laptop.
  4. Open the XCTU interface.

SS15. Click on discover devices, the button with the lens on it.

SS26. Click on next.

SS37. Click on finish. Keep the parameters as above.

SS4

8. Click on add selected devices

SS5

9. Click on the added device on the left screen. The details will be displayed.

SS6

10.Now we need to configure as coordinator.

11. Click on the update button, select product family – XB24-ZB, Function set- Zigbee coordinator AT, select the latest version and click finish. Wait for the firmware to be updated.

SS7

12. Under networking, Enter a pan ID, say 1234.

SS8

13. Under addressing , keep DH as 0, and DL as FFFF.(Destination address) as shown below. This is known as the broad cast mode.

SS914. Click on the “write radio settings button”. Coordinator is ready.

15. Remove the coordinator XBee and insert a fresh XBee labelled “end device”.

16. Do the same steps as above except for the following,

  • Under update>function set, select as “Zigbee end device AT”
  • Under networking, keep both DH and DL as “0”. (Zero). End device will only talk to the coordinator.
  • Ensure the pan ID is the same as in the coordinator, i.e. 1234 in this case.

Now you are done, ready with a “coordinator” and an “end device”.

Getting to work.

  1. Keep the “coordinator” XBee on the explorer board.
  2. Connect the “end device” XBee to the Arduino board. Ensure the RX, TX, 3v3 and GND are connected correctly.
  3. Connect a LM35 temp sensor to the Arduino. In this case we connect the middle pin to A2.
  4. Put an LED through resistor on pin 11.
  5. Open XCTU and discover the coordinator.
  6. Switch to console mode on the XCTU from the menu on top bar. The button next to the gear button.
  7. Click on the close the serial connection button.

SS10

SS11

8. Open the Arduino IDE and go ahead and upload the following sketch. (End device XBee). Remember to remove the Rx connection, between XBee and Arduino while uploading the sketch, or else you will end up with an error.

———————————

float temp_val=0; // variable to store temperature values.

void setup() {

Serial.begin(9600); // set serial baud at 9600

pinMode(11,OUTPUT); // set pin 11 as an output.

}

void loop() {

if(Serial.available()>0) // Check if any data is available on the serial port

{

int k=Serial.read(); //Store the data in a variable

k=k-48; // Convert from ascii value

if(k>3) // an arbitrary condition

{

digitalWrite(11,HIGH); // turn on LED

delay(1000); // wait for a second

digitalWrite(11,LOW); // turn off LED

}

Serial.print(” Number is : “); // Send out the value of K to the serial port

Serial.println(k);

int sensor_val= analogRead(2); // get the value from LM 35 and convert to temp.

temp_val = sensor_val*0.5;

Serial.print(“Temp is : “); // send out the temp value to the serial port.

Serial.println(temp_val);

}

}

Now on the console of the XCTU, type a number or character, and you should see the response as follows:

SS12

Well, the LED glows!

xbee_4

Now go ahead and experiment and have fun! Instead of console use another Arduino and transmit data at regular intervals. Use the Serial.print command.

– by P. Pramod Kumar, IoT Product Manager, Qruize

pramod@qruize.com

2 thoughts on “Configuring the XBee with a Send and Receive Program

  1. had to change the quote character ” in all places else this error will show up

    Arduino: 1.6.5 (Windows 8.1), Board: “Arduino Uno”

    sketch_aug07bxbeetemp:33: error: stray ‘\’ in program
    sketch_aug07bxbeetemp:33: error: stray ‘\’ in program
    sketch_aug07bxbeetemp:41: error: stray ‘\’ in program
    sketch_aug07bxbeetemp:41: error: stray ‘\’ in program
    sketch_aug07bxbeetemp.ino: In function ‘void loop()’:
    sketch_aug07bxbeetemp:33: error: ‘u201d’ was not declared in this scope
    sketch_aug07bxbeetemp:41: error: ‘u201cTemp’ was not declared in this scope
    stray ‘\’ in program

    This report would have more information with
    “Show verbose output during compilation”
    enabled in File > Preferences.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s