Using Cytron XBee Shield

Using Cytron XBee Shield

Introduction

Cytron XBee Shield (SHIELD-XBEE) is an Arduino-compatible shield that is compatible with Arduino UNOArduino DuemilanoveArduino Mega, Arduino Leonardo, and possibly other pin-compatible main boards. XBee Shield is compatible with XBee Modules and other XBee Compatible footprint modules such asBlueBeeXBee WIFI etc.

* Do take note if you are using Arduino Leonardo, the XBee module is not configurable from the computer as Arduino Leonardo does not have a USB to UART chip. Same goes for Arduino YUN.

So, why do we design a new Xbee shield since we already have other types of Xbee shields?
In fact, the new Cytron Xbee shield offers more features than the existing Xbee shield such as being able to select software or hardware UART, being stackable, and having an extra prototyping area. In addition, it is much cheaper than the previous Xbee shield.

 

Features:

  • Compatible with XBee (series 1 and series 2), XBee Pro (series 1 and series 2), XBee WifiBlueBee
  • On board 5V – 3.3V level translator IC.
  • Power, Transmit, Receive, Associate and RSSI LED indicators.
  • Jumper selectors for software or hardware UART selection and PC-XBee Communication.
  • Stackable side headers.
  • Prototyping area.
  • Arduino Wireless programming capable.

 

Limitation

However, there are some limitations with the Cytron Xbee shield compared to SKXBee.

Firstly, you cannot update your Xbee’s firmware with this Cytron Xbee shield. This is because to update the Xbee’s firmware, XBee requires VCC, GND, DIN, DOUT, RTS and DTR and the shield provides only connection of VCC, GND, DIN, and DOUT. You will still need SKXBEE in order to update the firmware of XBee. Not to be sad, we seldom need to update firmware of XBee, normally you just need the shield and Arduino :) We can always configure the XBee without the SKXBEE if you are using Cytron Xbee shield.

In addition, Cytron Xbee shield does not provide ISP/ICSP port. However, since we usually program the Arduino board through bootloader (which is much easier), so that is not a big deal.

 

TX RX pin selector

There are pin selections present in this Cytron Xbee shield. So, what is the use of these things?

xbeeshieldtxrx

Actually, this is the section to choose the serial pins (DIN and DOUT) of Xbee connection. You can pull out the jumper (the tiny black plastic) and plug it into whichever pins the XBee’s DIN and DOUT connect to.

The table below lists the modes of jumper selection.

table

What is  PC-XBee communication, hardware and software UART?

 

PC-XBee

This selection allows the XBee to communicate with a computer via Arduino onboard USB to UART chip. By selecting USB-USB on XBee shield’s TX and RX. This will connect the DIN of XBee to TX of USB to UART chip on Arduino UNO, or Mega (Arduino Leonardo does not have USB to UART chip). This also means the DOUT of XBee is connected to RX of USB to UART chip. Therefore, you can utilize this setting to configure the XBee from a computer using X-CTU (preferable) or other terminal program such as Hyperterminal, RealTerm, PuttY, or TeraTerm (BlueBee, RFBee).

Let’s see the example to communicate with BlueBee and XBee using a PC.

 

BlueBee with PC

What you need here is a BlueBee, Cytron Xbee shield, Arduino UNO, a smartphone with Integrated Bluetooth, and a PC.

zzblueebeephone

First, make sure the BlueBee is in Trans mode. You can do that by pushing the slide switch to “Trans”.


bluebee

After that, insert your BlueBee onto the Cytron Xbee shield. Stack the shield onto Arduino UNO (Make sure the pins are correct).


zzbluebeeangle

Select PC-XBee communication by moving the jumpers to USB-USB as shown.


zzusbusb

Connect the Arduino UNO to PC via USB cable. Open the HyperTerminal or any other Terminal program. Enter the name of the device and click OK.

bbstep1

Select the COM port you are connecting your Arduino UNO (BlueBee) to your computer and click OK.

bbstep2

Set the Bits per second to 9600 and click OK.

bbstep3

Click Properties.

bbstep4

Go to the Setting tab and click on the ASCII Setup.

bbstep5

Tick the “Send line ends with line feeds” and “Echo typed character locally”. Then click OK.

bbstep6

Now, turn on your phone’s Bluetooth and search and connect the BlueBee. Open your Bluetooth Terminal apps. If you are using a Window phone, you can download the app named “BT Terminal” by DevFor8.com from the window apps store. If you are using an Android phone, you can download the apps named “BlueTerm” or any compatible apps.

 

On your phone, type any character and send. Your BlueBee should receive the character and send it to your PC. The HyperTerminal should show the character you typed. Wireless communication from your phone to BlueBee and further to the computer.


hello

 

XBee with PC

To get wireless communication between XBees, you need two pieces of XBee. (You will still need two pieces of XBee because XBee communicates to XBee wirelessly).

zzxbeeskxbee

To allow communication between two XBees, you will need to set up their source address and destination address first. I will show you how to configure the XBee using the new version of XCTU software (Skip this part if you already knew it). The new version of XCTU is easier to setup and more user-friendly compared to the older version.

 

First, insert one of the XBee (I will call it XBee A) onto the Cytron XBee shield. Stack the shield onto Arduino UNO (make sure the pins are correct).


zzxbeeangle

Move the jumpers to USB-USB.


zzusbusb

Open the new version of XCTU software. Click “Discover devices” to add XBee to the list.

xbeestep1

Select the COM port you connect your Arduino (XBee) to your PC and click Next. As shown in my example, the COM for Arduino UNO is COM145.

xbeestep2

The setting should be as shown in the diagram below. Click finish and wait for the software to discover the XBee.

xbeestep3

Once the XBee is discovered, select it and click “Add selected devices”. Wait for it to read the settings of the XBee. It might take a while.

xbeestep4

Once it is done loading, set the destination(DL) and source(MY) address as shown below. This is for XBee A.

xbeestep5

Click the pencil symbol as shown in the diagram below to write the new values into XBee A.

xbeestep6

Repeat the same steps to configure the second XBee (I call it XBee B). However, please swap the destination and source addresses. 2222 for DL and 1111 for MY. (If you are using your own address while setting the address, just swap the value when you configure XBee B.)

After completing the settings for both XBees (XBee A and B), the XBees can communicate wirelessly.
Connect both of the XBee to your PC, you can either use a SKXBee for one of the XBee and another uses Cytron XBee Shield, or use two XBee shields. Then search and select them to add them to the list as shown previously.


Now, click the Terminal button.


terminal1

Click the cable alike symbol to open the serial connection of the device. (Open it on the second XBee also)


terminal2

Notice that there are two terminals, one for each XBee. Type in any messages in the first terminal. (Blue indicates data sent)


terminal3

Click on the second terminal and you will see that the second terminal received the messages. (Red indicates data received)


terminal4

What actually just happened is, after you typed the characters in the first terminal, the PC sends the data to XBee A via USB cable to Arduino UNO, and onboard USB to UART chip further to it on XBee shield. The XBee A receives the data and sends it to another XBee with the destination address (1111) out to the air wirelessly. XBee B with source address 1111 extracts the data from the air wirelessly and sends it back to PC (XCTU’s terminal). That is why you can see the red “Hello!” on the second terminal.

 

If you don’t believe it, you can try it on two different PC, a PC for each XBee. The same thing will happen!

P/S: I just want to remind again that you cannot communicate either XBee or Bluebee with PC (through HyperTerminal or XCTU) if your jumper is at either D1D0, D3D2, D9D8, or D11D10. You can try it out.

P/S: This can only happen on Arduino that has a USB to UART chip which is Arduino UNO, Mega. Arduino Leonardo cannot provide this.

 

Hardware Serial

By plugging in the jumpers onto D1 and D0, your BlueBee or XBee will be communicating with your Arduino’s hardware UART pins. By default, most of the Arduino main boards including Arduino UNO, have their serial pins at D0(RX) and D1(TX). So, What is the difference between communicating with PC and communicating with Arduino? When your BlueBee or XBee is communicating with Arduino, the Arduino can send and receive data wirelessly.

I will show you a simple example to turn on a LED wirelessly, using a phone (BlueBee) and PC (XBee).

First, connect a simple connection as shown in below.


arduinoled

Load the following simple program into your Arduino board.

[code lang=”cpp” wraplines=”true”]
int ledPin = 13;

void setup()
{
Serial.begin(9600); // begin the serial communication
pinMode(ledPin, OUTPUT); // set pin 13 as output
}
void loop()
if (Serial.available() > 0) // when you receive a data
{
char value = Serial.read(); // put the value received into a character variable
if (value == ‘1’) // if the value received is 1
{
digitalWrite(ledPin, HIGH); // turn on LED
Serial.println(“Received,LED ON”); // reply back to the transmitter
}
else
{
digitalWrite(ledPin, LOW); //turn off LED
Serial.println(“Received,LED OFF”); // reply back to the transmitter
}
}
}[/code]

zzd1d0

Plug the jumpers into D1 D0 (Hardware serial).

Stack the Cytron Xbee shield (with XBee or BlueBee) to your Arduino board.

 

For BlueBee, create connection from your phone Bluetooth with the BlueBee. Open the BT terminal (windows phone) or BlueTerm (Android), and connect your phone to the BlueBee. After they are connected, simply type a in a character and send, you should be receiving the reply from the BlueBee saying “Received, LED OFF”. If you type “1” and send, the LED will turn on and you will get a message saying “Received, LED ON”.

 

 

For XBee, (assuming you had set the destination and source address configured shown earlier in this article) connect your the other XBee to your computer. Open XCTU software. Search and add the device to the list. (All the steps as shown previously). Go to the Terminal tab and turn on the Serial connection. Type in any character, you should be receiving the reply from the XBee saying “Received, LED OFF”. If you type “1”, the LED will turn on and you will get a message saying “Received, LED ON”.

 

Software Serial

So, what about software serial? What is the difference between hardware serial and software serial? As mentioned earlier, The Arduino has built-in support for serial communication on pin 0 and pin 1. However, the software serial allows serial communication on other digital pins of Arduino instead of pin 0 and pin 1. You might ask why don’t we just reserve pin 0 and pin 1 all the time for communication and then we do not need to learn about software serial communication.

 

Unfortunately, there is a time when we need to use software serial. For example, for Arduino Leonardo, the TX RX pins are at pin 1 and pin 0 respectively. However, interrupt 2 and interrupt 3 is at pin 0 and pin 1 too. In that case, if you need to use interrupt 2 and interrupt 3 together with UART communication, you can use other pins as the serial communication pins, thus software serial.

 

Besides, by using software serial, we can have multiple software serial implemented in a single chip. We can communicate with more than one UART device. However, there is a limitation on the software serial. If you are using multiple software serial, only one of them can receive or send data at a time. They have to take turns sending or receiving data. (However, one hardware serial and one software serial can be used at the same time)

So, let’s try to turn on a LED that is on pin 0 wirelessly. (You cannot do this using hardware serial).

zzd3d2

First,  move the jumpers onto D3 D2 (Software serial).

ledpin0

Stack your Cytron Xbee shield (with XBee or BlueBee) to your Arduino board. Connect a simple LED circuit as shown in diagram below.

(Note that now we are connecting the LED to pin 0.)

Now, modify your program to as shown below.

[sourcecode language=”cpp” wraplines=”true”]
#include 
SoftwareSerial mySerial(2,3); // RX, TX
int ledPin = 0;
void setup()
{
mySerial.begin(9600); // begin the software serial
pinMode(ledPin, OUTPUT); // setting pin 0 as output
}
void loop()
{
if (mySerial.available() > 0) // when a data was received
{
char value = mySerial.read(); // put the data received in to character variable
if (value == ‘1’) // if the character is “1”
{
digitalWrite(ledPin, HIGH); // turn on LED
mySerial.println(“Received,LED ON”); // reply to transmitter
}
else
{
digitalWrite(ledPin, LOW); // turn off LED
mySerial.println(“Received,LED OFF”); // reply to transmitter
}
}
}[/sourcecode]

You will get the same result as using Hardware serial, but now your LED is at pin 0, which you cannot do it using Hardware serial.

 

Using multiple serial

One more advantage of the Cytron Xbee shield, you can stack the shield on top of Arduino. First level connects D1D0, second level connects D3D2, third level connects D9D8, fourth level connects D11D10.

zzstack2

zzstack

So what does this means? This means that you can communicate with four different devices serially with the controller. However, as mentioned earlier just now, only one software serial can send or receive data at a time.

By this, we can use our Bluetooth devices to communicate with XBee radio devices indirectly. Why indirectly? Because what actually happens is, your can use your Bluetooth devices such as a mobile phone to communicate with BlueBee, and the BlueBee communicates with Arduino through the hardware serial TX RX pins. The microcontroller receives and transmits the same data to the software serial TX RX pins, which are connected to other XBee radio. This XBee can further communicate with the other XBee wirelessly which matches the source and destination address. Finally, the communication between two different devices is formed.

If you have any inquiries, please discuss them in our technical forum because we seldom check the comment section on the tutorial site.

 

BUY