Вы находитесь на странице: 1из 16

Wireless Sensor Networks-ZigBee

LAB MANUAL
Chapter 1. Configuring XBees
1. Attach Xbees to Module boards and plug into computer.

2. Open XCTU and click on discover devices.


3. Select all ports to search and accept default parameters.
4. Select all found Xbees and add them to your interface Items Needed:
5. Click on one of the Xbees and once it loads click on the firmware button (take note of the
product family):

6. Choose the appropriate product family, ZigBee Coordinator AT, and then click select current.
Click finish.
7. Allow Firmware to download, and wait for receive success page.

Note: Label Xbees so as to designate Coordinators from Routers from End Devices.

8. Repeat steps 5-7 with the other attached Xbee, but with the below firmware settings to set it
up as an End Device:

9. Click on the Xbee you configured as the Coordinator and choose a pan ID (The ID is 4 bytes
of hexadecimal and can range from 0000 to FFFF. Choose 0016 if you do not have a
preference) this is the only thing that you need to configure for the Coordinator. Click the pen
to write settings. (Box should turn blue.)
10. Scroll down in the Firmware Information area to the addressing section and take note of the
Serial Number High and Low (SH & SL):
11. Click on the Xbee you configured as the End Device and set pan ID to the same as that of the
coordinator.
12. Navigate to the addressing section and set the Destination Address High and Low to the
information corresponding to the coordinator. Click the Write button at the top of the page to
write all changes to the Xbee and make sure boxes turn blue.
13. Xbees are now configured to communicate with each other in the default AT mode.

Chapter 2. Sending Messages


1. In AT mode:
1. AT mode is synonymous with "Transparent" mode.
2. In AT mode, any data sent to the XBee module is immediately sent to the remote module
identified by the Destination Address in memory.
3. If the XBee that the data is sent to is the Coordinator it will broadcast on the PanID.
4. No packet formation is necessary, but rather simple send Serial data to the tx of one Xbee and it
will be received by the rx of the destination XBee
5. Because no packets are created the destination address and type (only-data) are both fixed.

Steps to AT mode communication:


1. As mentioned in previous section, filling DH and DL of radio terminal device enables them
to communicate in AT mode.
2. Select the device serial port in the serial data console (putty/terminal/x-ctu) to transmit data
the frame formation and destination addressing is done by device according to set data.
2. In API Mode:
Procedure
API (Application Programming Interface) mode is a frame-based method for sending and receiving
data to and from a radio terminal's serial UART. The API is an alternative to the default transparent
mode.

The API allows the programmer the ability to:

 Change parameters without entering command mode (XBee only)


 View RSSI and source address on a packet by packet basis (XBee 802.15.4 only)
 Receive packet delivery confirmation on every transmitted packet

This example will send the ASCII string "Hello" to a radio terminal with the destination address of
5001. Both examples will be using API mode without escaped characters (ATAP=1). Please verify
you have install the API version.

XBee - 16 bit 802.15.4 Unicast Example:

Configure the radio terminals with the following parameters:


Radio terminal 1 Radio terminal 2

AP = 1 DL = 5000

MY = 5000 MY = 5001

To compose the data packet, use the ''''Assemble Packet'''' option found within the Terminal
tab of the X-CTU test and configuration software.

Launch a second X-CTU screen. Verify you have selected the COM port Radio terminal 2 is
on, and click on the Terminal tab.

Select the ''''Hex'''' option in the ''''Assemble Packet'''' window and enter the following hex
formatted data in the X-CTU set for Radio terminal 1''''s COM port:

7E 00 0A 01 01 50 01 00 48 65 6C 6C 6F B8

7E Start delimiter
00 0A Length bytes
01 API identifier
01 API frame ID
50 01 Destination address low
00 Option byte
48 65 6C 6C 6F Data packet
B8 Checksum

If the packet was successful, you will see "Hello" in the receiving modules Terminal window.
You will also receive a response packet back to Radio terminal 1 stating the packet was successful.
This successful response packet will look something like this:

7E 00 03 89 01 00 75

7E Start delimiter
00 03 Length bytes
89 API identifier
01 API frame ID
00 Status byte
75 Checksum

To view the TX response packet, use the ''''Show Hex'''' option in the Terminal tab.

Various API Frame types:


API Operation theory
By default, XBee / XBee-PRO RF Modules act as a serial line replacement (Transparent Operation) -
all UART data received through the DI pin is queued up for RF transmission. When the module
receives an RF packet, the data is sent out the DO pin with no additional information.

Inherent to Transparent Operation are the following behaviors:

1. If module parameter registers are to be set or queried, a special operation is required for
transitioning the module into Command Mode.
2. In point-to-multipoint systems, the application must send extra information so that the
receiving module(s) can distinguish between data coming from different remotes.

As an alternative to the default Transparent Operation, Application Programming Interface (API)


operations are available. API operation requires that communication with the module be done
through a structured interface (data is communicated in frames in a defined order). The API specifies
how commands, command responses and module status messages are sent and received from the
module using a UART data frame.

API frame specifications:

Two API modes are supported and both can be enabled using the AP (API Enable) command.
Use the following AP parameter values to configure the module to operate in a particular mode:

 AP = 0 (default): Transparent Operation (UART Serial line replacement)


o API modes are disabled.
 AP = 1: API Operation
 AP = 2: API Operation (with escaped characters)

Any data received prior to the start delimiter is silently discarded. If the frame is not received
correctly or if the checksum fails, the data is silently discarded.
API Operation (AP parameter = 1)

When this API mode is enabled (AP = 1), the UART data frame structure is defined as follows:

Figure 9: UART data frame structure:

API Operation - with escape characters (AP parameter = 2)

When this API mode is enabled (AP = 2), the UART data frame structure is defined as follows:

Figure 10: UART Data Frame Structure - with escape control characters:

Escape characters. When sending or receiving a UART data frame, specific data values must be
escaped (flagged) so they do not interfere with the UART or UART data frame operation. To escape
an interfering data byte, insert 0x7D and follow it with the byte to be escaped XOR’d with 0x20.

Data bytes that need to be escaped:


• 0x7E – Frame Delimiter
• 0x7D – Escape
• 0x11 – XON
• 0x13 – XOFF

Example - Raw UART Data Frame (before escaping interfering bytes):


0x7E 0x00 0x02 0x23 0x11 0xCB

0x11 needs to be escaped which results in the following frame:


0x7E 0x00 0x02 0x23 0x7D 0x31 0xCB

Note: In the above example, the length of the raw data (excluding the checksum) is 0x0002 and the
checksum of the non-escaped data (excluding frame delimiter and length) is calculated as:
0xFF - (0x23 + 0x11) = (0xFF - 0x34) = 0xCB.

Checksum
To test data integrity, a checksum is calculated and verified on non-escaped data.
To calculate: Not including frame delimiters and length, add all bytes keeping only the lowest 8 bits
of the result and subtract from 0xFF.
To verify: Add all bytes (include checksum, but not the delimiter and length). If the checksum is
correct, the sum will equal 0xFF.
3. Broadcast Mode
Any RF module within range will accept a packet that contains a broadcast address. When
configured to operate in Broadcast Mode, receiving modules do not send ACKs (acknowledgments)
and transmitting modules do not automatically re-sent packets as is the case in Unicast Mode.

To send a broadcast packet to all modules regardless of 16-bit or 64-bit addressing, set the
destination addresses of all the modules as shown below.

Sample Network Configuration (All modules in the network):

• DL (Destination Low Address) = 0x0000FFFF

If RR is set to 0, only one packet is broadcast. If RR > 0, (RR + 2) packets are sent in each broadcast.
No acknowledgments are returned. See also the RR command description.

• DH (Destination High Address) = 0x00000000 (default value)

4. Remote Configuration:
Chapter 3. Reading I/O pins of XBee with API frame data
Connect a sensor node like a temperature sensor or door switch to an I/O pin of S1 module and
program the other module to follow the changes happening to that I/O pin.

The XBee Radio at the sensor node should be configured as a ROUTER or END device & the data
collecting XBee should be configured with COORDINATOR API Firmware. For parsing the data
received & decision making, an Arduino is connected at the Coordinator end.

Here we will see how to collect data from a Digital input like a Door switch & how to parse the API
frame data received from that sensor node.

Materials required:

a. XBEE S2 type Radio – 2 nos.


b. Toggle Button/Reed switch
c. Arduino UNO
d. XBEE USB Breakout boards

The Door switch is connected to pin 20 (DIO_0) of distant xbee which is configured with Router AT
firmware.

Configuration of XBEE Radios:

One of the Radios to be configured as Router. The Router radio is programmed with AT
Firmware & the Destination address DH, DL is given as the Source address (Serial Number SH,SL)
of Coordinator.

The PAN ID & Baud Rate should be same for both the Radios.

Pin 20 – DIO 0 of Router is to be connected to the Door switch. This pin is declared as DIGITAL
INPUT.

In XCTU configuration window, scroll down to I/O settings change the D0 AD0/DIO0 configuration
to 3 which represents Digital Input.

Click on the Write button to record the changes done.


Scroll down further to set the IR Sampling Rate.Set this to hex value 1388 which equals 5000 in
Decimal.i.e a digital sample is sent every 5000ms or 5 secs.

Program the other Radio as “XB24-ZB / ZigBee Coordinator API firmware”.

Ensure that the PANID (you can feed your own value) & Baud Rate are the same for both the
Radios.

The Destination address (DH&DL) is the source address (SH & SL) of router.

Scroll down further to set the API mode Enable (1).

Click on Write to record the changes.

Connecting Coordinator Radio to Arduino

Remove the Coordinator Radio (you can make an ink mark as C to identify) from the USB board &
plug it to the other break out board with LEDs. Connect this to Arduino UNO as described below.
Pin 1 of breakout board is connected to 5v of Arduino & pin 10 to GND. As the breakout board has
built in 3.3v regulator, it’s safe to provide 5v supply. Pin 2 (TX) of XBee breakout goes to pin 0
(Rx) of Arduino. Pin3 (RX) of XBee goes to pin 1 (Tx) of Arduino.

XBEE Breakout Arduino

PIN 1 ———> +5V

PIN 10 ———> GND

PIN 2 (TX) ———> PIN 0 (Rx)

PIN 3 (RX) ———> PIN 1 (Tx)

The Arduino board is connected to PC using USB cable.


The Router Radio is plugged on to the USB breakout. PIN 20 (ADIO 0) is connected to the toggle
switch with proper pull-up circuit.
Now open the Arduino IDE & select the port where Arduino is connected. Write and upload a simple
sketch to print on terminal the dat received from XBee.
Note: Now power up the Router by connecting the USB cable to the XBee USB breakout. Remember
to switch on the Coordinator first & then the Router.

As soon as the Router joins the Coordinator, it starts sending Digital samples collected from pin 20
every 5 secs.
Open the Serial monitor of Arduino to view the API Frames received.
Let us analyze the API Frame data received from the Router where the switch is connected (switched
on):

7E 0 12 92 0 13 A2 0 40 A9 C5 92 79 9 1 1 01 0 0 0 F3

The API Frame consists of total 22 bytes (counted from 0 to 21) starting with a Delimiter 7E.

The next 2 bytes represent the length of frame starting from Frame type & ending before Checksum.

In our sample here its 0 12 .The second byte 0x12 in HEX is equal to 18 in Decimal. You can see
total 18 bytes after this value 0x12 & before the checksum F3.

The next byte 92 is the API Frame type, Hex value 92 represents “RX I/O Data Received “

If you receive 0x0 in the first digital sample byte & 0x1 in the second one, that indicates high
voltage (level 1) is being received only on pin D0.

The last one is the checksum which is the 8 bit sum of bytes from offset 3 to this byte.

Note that if Analog lines are enabled you receive another single byte before this checksum
representing the Analog data.

————————–

You can watch the byte no. 20 which is the last but one in the Frame data. This changes to 1 when
the Door switch is closed & changes to 0 when the door switch is open.

Now upload a modified code to access the particular I/O status bytes.

If you monitor the serial port of Arduino you can get the data whether Door is closed or open.
Chapter 4. Experiments
1. Build a procedure to configure XBee in at mode using X-CTU.
XBee XBee End
Coordinator Device 1

Transfer message between end device and coordinator.

Procedure:

1) Configure one XBee in AT Coordinator mode; assign a pan ID in the range of 0000 to FFFF.
2) Configure other XBee in AT End Device mode; assign the same pan ID as coordinator.
3) Fill the DH & DL with SH & SL of the End Device and vice-versa
4) Power on and reset all radio terminals.
5) Connect Respective XBees to COM port-Serial Monitors.
6) Enter some data in the end device radio terminal to read on coordinator radio terminal.
7) Enter some data in the coordinator radio terminal to read on end device radio terminal.

2. Build the following topology procedure to configure XBee in AT mode using X-CTU

XBee
E.D. 1 (AT)

XBee Coord.
(AT)

XBee
E.D. 2 (AT)

Transfer message between End devices and Coordinator.

Procedure:

1) Configure one XBee in AT Coordinator mode; assign a pan ID in the range of 0000 to FFFF.
2) Configure two XBee in AT End Device mode; assign the same pan ID as Coordinator to
both, give DH & DL according to transmission direction needs.
3) Power on and reset all radio terminals.
4) Connect Respective XBees to COM port-Serial Monitors.
5) Enter some data in the end device radio terminal to read on coordinator radio terminal
6) Do the same on second end device radio terminal.
7) In similar two step fashion, change the DH & DL of coordinator to send data to end device 1
and end device 2 one-by-one.
8) Practice Broadcasting.
3. Repeat the experiment 2 and configure the coordinator in AT mode & end device using API
Mode.

XBee
E.D. 1 (API)

XBee Coord.
(AT)

XBee
E.D. 2 (API)

Procedure:

1) Configure one XBee in AT Coordinator mode; assign a pan ID in the range of 0000 to FFFF.
2) Configure two XBee in API End Device mode; assign the same pan ID as Coordinator to
both, give DH & DL according to transmission direction needs.
3) Power on and reset all radio terminals.
4) Connect Respective XBees to COM port-Serial Monitors.
5) To send data from Coordinator to End Device (AT-API):
a) Fill the DH & DL with SH & SL of the End Device
b) Enter some data in the end device radio terminal to read on coordinator radio terminal.
6) To send data from end device to Coordinator (API-AT):
a) Generate a ‘Transmit Request’ frame with coordinator ID as dest. address.
b) Add information to the RF data field.
c) Send this packet to and check Coordinator Radio terminal for the information.
7) Practice Broadcasting.

4. Repeat the experiment 2 and configure the Coordinator in API mode & End device using AT
Mode.
XBee E.D.
1 (AT)

XBee Coord.
(API)

XBee E.D.
2 (AT)

Procedure:

1) Configure one XBee in API Coordinator mode; assign a pan ID in the range of 0000 to
FFFF.
2) Configure two XBee in AT End Device mode; assign the same pan ID as Coordinator to
both, give DH & DL according to transmission direction needs.
3) Power on and reset all radio terminals.
4) Connect Respective XBees to COM port-Serial Monitors.
5) To send data from Coordinator to End Device (API-AT):
a) Generate a ‘Transmit Request’ frame with End Device ID as dest. address.
b) Add information to the RF data field.
c) Send this packet to and check end device radio terminal for the information.
6) To send data from end device to Coordinator (API-AT):
a) Fill the DH & DL with SH & SL of the End Device
b) Enter some data in the coordinator radio terminal to read on end device radio terminal.
7) Practice Broadcasting.

5. Repeat the experiment 2 and configure both the Coordinator & End device using API Mode.
XBee E.D.
1 (API)

XBee Coord.
(API)

XBee E.D.
2 (API)

In API mode to configure all devices on same network make the PAN ID and Scan Channel
of all the devices common.

Procedure:

1) Configure one XBee in AT Coordinator mode; assign a pan ID in the range of 0000 to FFFF.
2) Configure two XBee in AT End Device mode; assign the same pan ID as Coordinator to
both.
3) Power on and reset all radio terminals.
4) Connect Respective XBees to COM port-Serial Monitors.
5) Enter some data in the end device radio terminal to read on coordinator radio terminal
6) Do the same on second end device radio terminal.
7) In similar two step fashion, change the DH & DL of coordinator to send data to end device 1
and end device 2 one-by-one.

In this experiment we will learn to communicate between two mbed enabled boards Wirelessly
using XBEE Radio terminals. Hardware to keep in handy is:

1. 2 mbed board
2. 2 x XBEE Radio terminal
3. 2 x Breakout Board for XBEE

Connecting XBEEs to mbed board for Wireless Communication:


Following is the outline for two way communication:

1. Connect a Buzzer to the 2nd Mbed board (call it as B).The first Mbed board (call it as A) will
send a character “K” & it is transmitted through the first XBEE connected to Mbed board A.
7. The Mbed board B will look for a capital “K” & switches ON the buzzer for 5 seconds.
After that it sends back a character “O”. Mbed board A will wait for this character & on
receiving, it lights up an LED for 5 secs.How to read End device I/O pin status:

XBee Coord. XBee


(API) Router(AT)

Procedure:

1) Configure one XBee in API Coordinator mode; assign a pan ID in the range of 0000 to FFFF.
2) Configure other XBee in AT Router or AT end device mode; assign the same pan ID as
coordinator.
3) Fill the DH & DL with SH & SL of the end device.
4) Power on and reset all radio terminals.
5) Connect Respective XBees to COM port-Serial Monitors.
6) Make input device (toggle switch) pull-up circuit.
7) Write Mbed board code to infer I/O data from “0x92-IO Data Sample Rx Indicator”.

8. How to set end device I/O pins?

XBee Coord. XBee


(API) E.D.(AT)

Procedure:

1) Configure one XBee in API Coordinator mode; assign a pan ID in the range of 0000 to FFFF.
2) Configure other XBee in AT Router or AT end device mode; assign the same pan ID as
coordinator.
3) Fill the DH & DL with SH & SL of the end device.
4) Power on and reset all radio terminals.
5) Connect Respective XBees to COM port-serial monitors.
6) Write desired I/O statuses in Radio Configuration window of the sensor radio.
7) Read the changed I/O in coordinator radio terminal.

9. Read Analog values.

Repeat experiment 7 to access AD pin values.

Вам также может понравиться