Introduction

Step 1: The shield

XBee shield for Arduino

The Arduino XBee shield allows your Arduino board to communicate wirelessly using Zigbee.
It was developed in collaboration with Arduino. This documentation describes the use of
the shield with the XBee module.

XBee in Raspberry Pi

Step 2: A simple example

Arduino Example

You should be able to get two Arduino boards with XBee shields talking to each other without any configuration, using just the standard Arduino serial commands.

To upload a sketch to an Arduino board with a XBee shield, you'll need to put both jumpers on the shield to the "USB" setting (i.e. place them on the two pins closest to the edge of the board) or remove them completely (but be sure not to lose them!). Then, you can upload a sketch normally from the Arduino environment. In this case, upload the Communication | Physical Pixel sketch to one of the boards. This sketch instructs the board to turn on the LED attached to pin 13 whenever it receives an 'H' over its serial connection, and turn the LED off when it gets an 'L'. You can test it by connecting to the board with the Arduino serial monitor (be sure it's set at 9600 baud), typing an H, and pressing enter (or clicking send). The LED should turn on. Send an L and the LED should turn off. If nothing happens, you may have an Arduino board that doesn't have a built-in LED on pin 13.

Once you've uploaded the Physical Pixel sketch and made sure that it's working, unplug the first Arduino board from the computer. Switch the jumpers to the XBee setting (i.e. place each on the center pin and the pin farthest from the edge of the board). Now, you need to upload a sketch to the other board. Make sure its jumpers are in the USB setting. Then upload the following sketch to the board:

When it's finished uploading, you can check that it's working with the Arduino serial monitor. You should see H's and L's arriving one a second. Turn off the serial monitor and unplug the board. Switch the jumpers to the XBee setting. Now connect both boards to the computer. After a few seconds, you should see the LED on the first board turn on and off, once a second. (This is the LED on the Arduino board itself, not the one on the XBee shield, which conveys information about the state of the XBee module.) If so, congratulations, your Arduino boards are communicating wirelessly. This may not seem that exciting when both boards are connected to the same computer, but if you connect them to different computers (or power them with an external power supply - being sure to switch the power jumper on the Arduino board), they should still be able to communicate.

Raspberry Pi Example

You should be able to get two Raspberry Pi boards with XBee shields talking to each other without any configuration, using just serial commands.

In one of the Raspberry Pi boards we will run a code that turn on the LED attached to pin 7 whenever it receives an 'H' over its serial connection, and turn the LED off when it gets an 'L'. The other Raspberry Pi board will run a program that sends 'H' and 'L' sleeping 1 second in between.

When both programs are running (one on each board) you should see the LED on the first board turn on and off, once a second.

NOTE: All the code examples in this tutorial developed for Raspberry Pi use the arduPi library. You can see the documentation and download the library here.

Step 3: Addressing

There are multiple parameters that need to be configured correctly for two modules to talk to each other (although with the default settings, all modules should be able to talk to each other). They need to be on the same network, as set by the ID parameter (see "Configuration" below for more details on the parameters). The modules need to be on the same channel, as set by the CH parameter. Finally, a module's destination address (DH and DL parameters) determine which modules on its network and channel will receive the data it transmits. This can happen in a few ways:

If a module's DH
is 0 and its DL
is less than 0xFFFF (i.e. 16 bits), data transmitted by that module will be received by any module whose 16-bit address
MY
parameter equals
DL
.

If
DH
is 0 and
DL
equals 0xFFFF, the module's transmissions will be received by all modules.

If
DH
is non-zero or
DL
is greater than 0xFFFF, the transmission will only be received by the module whose serial number equals the transmitting module's destination address (i.e. whose
SH
equals the transmitting module's
DH
and whose
SL
equals its
DL
).

Again, this address matching will only happen between modules on the same network and channel. If two modules are on different networks or channels, they can't communicate regardless of their addresses.

Step 4: Configuring the XBee module

You can configure the XBee module from code running on the Arduino board, on Raspberry Pi,
or from software on the computer. To configure it from the Arduino board, you'll need to
have the jumpers in the XBee position. To configure it from the computer, you'll need to
have the jumpers in the USB configuration and have removed the microncontroller from your
Arduino board.

To get the module into configuration mode, you need to send it three plus signs: +++ and there needs to be at least one second before and after during which you send no other character to the module. Note that this includes newlines or carriage return characters. Thus, if you're trying to configure the module from the computer, you need to make sure your terminal software is configured to send characters as you type them, without waiting for you to press enter. Otherwise, it will send the plus signs immediately followed by a newline (i.e. you won't get the needed one second delay after the +++). If you successfully enter configuration mode, the module will send back the two characters 'OK', followed by a carriage return.

Send Command

Expected Response

+++

OK<CR>

Once in configuration mode, you can send AT commands to the module. Command strings have the form ATxx (where xx is the name of a setting). To read the current value of the setting, send the command string followed by a carriage return. To write a new value to the setting, send the command string, immediately followed by the new setting (with no spaces or newlines in-between), followed by a carriage return. For example, to read the network ID of the module (which determines which other XBee modules it will communicate with), use the 'ATID command:

Send Command

Expected Response

ATID<enter>

3332<CR>

To change the network ID of the module:

Send Command

Expected Response

ATID3331<enter>

OK<CR>

Now, check that the setting has taken effect:

Send Command

Expected Response

ATID<enter>

3331<CR>

Unless you tell the module to write the changes to non-volatile (long-term) memory, they will only be in effect until the module loses power. To save the changes permanently (until you explicitly modify them again), use the
ATWR
command:

Send Command

Expected Response

ATWR<enter>

OK<CR>

To reset the module to the factory settings, use the
ATRE
command:

Send Command

Expected Response

ATRE<enter>

OK<CR>

Note that like the other commands, the reset will not be permanent unless you follow it with the
ATWR
command.

Here are some of the more useful parameters for configuring your XBee module.

Command

Description

Valid Values

Default Value

ID

The network ID of the XBee module.

0 - 0xFFFF

3332

CH

The channel of the XBee module.

0x0B - 0x1A

0X0C

SH and SL

The serial number of the XBee module (SH gives the high 32 bits, SL the low 32 bits).
Read-only.

0 – 0xFFFFFFFF
(for both SH and SL)

different for each module

MY

The 16-bit address of the module.

0 - 0xFFFF

0

DH and DL

The destination address for wireless communication (DH is the high 32 bits, DL the low 32).

0 – 0xFFFFFFFF
(for both DH and DL)

0 (for both DH and DL)

BD

The baud rate used for serial communication with the Arduino board or computer.

Note: although the valid and default values in the table above are written with a prefix of "0x" (to indicate that they are hexadecimal numbers), the module will not include the "0x" when reporting the value of a parameter, and you should omit it when setting values.

Here are a couple more useful commands for configuring the XBee module (you'll need to prepend AT to these too).

Command

Description

RE

Restore factory default settings (note that like parameter changes, this is not permanent unless followed by the WR command).

WR

Write newly configured parameter values to non-volatile (long-term) storage. Otherwise, they will only last until the module loses power.

CN

Exit command mode now. (If you don't send any commands to the module for a few seconds, command mode will timeout and exit even without a CN command.)

You can see all the AT commands in the XBee manual.

API mode

As an alternative to Transparent Operation, API (Application Programming Interface) 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.

Read the manual if you are going to use the API mode.

Entering gateway mode in Raspberry Pi

To stablish UART connection with the module you can use several programs as cutecom in Raspbian graphical
environment or minicom in a terminal window in order to use it via SSH . For
using minicom follow these steps:

Open a Terminal window on Raspberry Pi, or connect to Raspberry Pi through SSH.
In order to enter via SSH change here the IP from your Raspberry Pi. The default user is pi.
ssh -X pi@192.168.1.X

Now you will have to type your password. The default password is āraspberryā.

Open comunication with the module UART with your correct baudrate. The default
baudrate is usually 115200 or 9600:
minicom -b 9600 -o -D /dev/ttyAMA0

Then you can enter in configuration mode (without
end of line characters so don't press Enter button) and wait a second:+++

The module will respond with and "OK"

Now type for example "ATID" press Enter button and the module will responde with
its ID.

To exit minicom press CTRL+A, then press X and Yes.

Step 5: Jumper settings (Only for Arduino)

The XBee shield has two jumpers (the small removable plastic sleeves that each fit onto two of the three pins labelled XBee/USB). These determine how the XBee's serial communication connects to the serial communication between the microcontroller (ATmega8 or ATmega168) and FTDI USB-to-serial chip on the Arduino board.

With the jumpers in the
XBee position
(i.e. on the two pins towards the interior of the board), the DOUT pin of the XBee module is connected to the RX pin of the microcontroller; and DIN is connected to TX. Note that the RX and TX pins of the microcontroller are still connected to the TX and RX pins (respectively) of the FTDI chip - data sent from the microcontroller will be transmitted to the computer via USB as well as being sent wirelessly by the XBee module. The microcontroller, however, will only be able to receive data from the XBee module, not over USB from the computer.

With the jumpers in the
USB position
(i.e. on the two pins nearest the edge of the board), the DOUT pin the XBee module is connected to the RX pin of the FTDI chip, and DIN on the XBee module is connected to the TX pin of the FTDI chip. This means that the XBee module can communicate directly with the computer - however, this only works if the microcontroller has been removed from the Arduino board. If the microcontroller is left in the Arduino board, it will be able to talk to the computer normally via USB, but neither the computer nor the microcontroller will be able to talk to the XBee module.

Step 6: Using Series 2 ZB XBee's

Series 2 XBee's (ZigBee protocol) are quite different to 802.15.4 ones.

ZigBee networks are called personal area networks or PANs. Each network is defined with a unique PAN identifier (PAN ID). XBee ZB supports both a 64-bit (extended) PAN ID and a 16-bit PAN ID.

The 16-bit PAN ID is used in all data transmissions. The 64-bit PAN ID is used during joining, and to resolve 16-bit PAN ID conflicts that may occur.

ZigBee defines three different device types: coordinator, router, and end devices.

Coordinator

Selects a channel and PAN ID (both 64-bit and 16-bit) to start the network

Can allow routers and end devices to join the network

Can assist in routing data

Cannot sleep--should be mains powered.

Router

Must join a ZigBee PAN before it can transmit, receive, or route data

After joining, can allow routers and end devices to join the network

After joining, can assist in routing data

Cannot sleep--should be mains powered.

End device

Must join a ZigBee PAN before it can transmit or receive data

Cannot allow devices to join the network

Must always transmit and receive RF data through its parent. Cannot route data.

Can enter low power modes to conserve power and can be battery-powered.

In ZigBee networks, the coordinator must select a PAN ID (64-bit and 16-bit) and channel to start a network. After that, it behaves essentially like a router. The coordinator and routers can allow other devices to join the network and can route data.

After an end device joins a router or coordinator, it must be able to transmit or receive RF data through that router or coordinator. The router or coordinator that allowed an end device to join becomes the "parent" of the end device. Since the end device can sleep, the parent must be able to buffer or retain incoming data packets destined for the end device until the end device is able to wake and receive the data.

Links and Documentation

If you are interested in Internet of Things (IoT) or M2M projects check our open
source sensor platform Waspmote
which counts with more than 100 sensors available to use 'off the shelf', a complete API with hundreds of ready to use codes and a low consumption mode of just 0.7µA to ensure years of battery life.

Customer Service

My Account

Subscribe to Our Newsletter

When you (āYOUā) use LIBELIUMĀ“s websites, fill in any form supplied by LIBELIUM or deliver your business card to our sales force, YOU consent to the use of your personal information by us in the manner specified in this Privacy Policy. This Policy may change periodically, so YOU should check back from time to time.

All references made in this Privacy Policy to specific Articles shall be deemed made to Regulation (EU) 2016/679 of the European Parliament and of the Council of 27 April 2016, on the protection of natural persons with regard to the processing of personal data and on the free movement of such data (āthe Regulationā).

Personal Data Collection

Following the Regulation and Spanish Regulations on Data Protection, LIBELIUM hereby informs its Customers and websites users (collectively, āUsersā) that any personal data supplied shall be recorded in an automated file named āCUSTOMERSā for which LIBELIUM is the Controller and also the Processor and located at LIBELIUMĀ“s registered address at c/ EscatrĆ³n 16. 50014 Zaragoza, Spain.

The Processors are the following: a) Amazon Web Services Inc., located at EU (Ireland), only for purposes of storing personal data; and b) Openbravo, LIBELIUMĀ“s ERP supplier, located at EU (Spain), for the purpose of managing our data bases. All personal data are sent encrypted to Amazon.

By filling any form in LIBELIUMĀ“s websites, Users consent: (i) to the processing of their personal data by LIBELIUM for the purposes mentioned below; (ii) to receive promotional offers of LIBELIUMĀ“s and its suppliers and partnersā Products and Services; and (iii) to the fact that LIBELIUM may make such data available to its partners or suppliers to the sole purpose of enabling service provision.

USERĀ“s rights (Articles 12 to 22):

Any request by Users in connection with their rights mentioned below, shall be answered by LIBELIUMĀ“s Data Protection Officer within a month.

3.1.Transparency and Information (Articles 12-14):

a. What type of personal data do we collect?: the forms in our websites only collect name, email address and country or origin. The forms in our marketplaces collect additional information, such as address, telephone and credit card number. Disclosure of these data is compulsory for making any purchase through our marketplaces. LIBELIUM does not collect any sensitive data (Articles 9&10) from Users through the forms in its websites. Please refer to LIBELIUMĀ“s Terms and Conditions of Sale and Use for MySignals Products (https://libelium.com/downloads/MySignals-Terms-and-Conditions.pdf), to learn about collection and processing of CustomerĀ“s data on health. LIBELIUM may record any or all telephone conversations with YOU and store them in the above-mentioned āCustomersā file. By phoning to LIBELIUMĀ“s customer service telephone numbers, YOU consent to the recording of these conversations.

b. Why do we collect your personal data? LIBELIUM warrants that the purposes of this personal data processing shall be lawful at all times, namely: (a) to provide You access to LIBELIUMĀ“s websites, marketplaces, products and services; (b) to respond to Your requests for information; (c) to send You information on LIBELIUMĀØs products and services; (d) to allow those of our partners who help us provide and improve our products and services, send You tailored information on related products or services, or provide you access to additional services; (e) for R&D purposes, allowing LIBELIUM develop new products and services or improve the existing ones; (f) to collect YOUR consent to the terms of use of forums and other sections in LIBELIUMĀ“s websites; and (g) if applicable, to consider Your application for employment with us.

c. What do we do with your personal data? Our processing shall be the following:

Collection, always with your consent, either by filling our forms, by delivering your business card to our salesforce, or by entering a contractual relationship with LIBELIUM by purchasing our products and/or services. LIBELIUM shall not process any personal data not directly obtained from YOU. Any User feeling that his/her personal data have been disclosed to us without his/her consent, may contact our DPO to ascertain the source from which his/her personal data originate, and to exercise any of the rights mentioned below. LIBELIUM reserves its right to exclude from any service for which prior registration is required, any User having provided false or inaccurate data, notwithstanding any other legal action to which LIBELIUM may be entitled.

Storage: our supplier is Amazon Web Services Inc., whose servers are located in Ireland. As already mentioned, our data bases are sent encrypted to Amazon.

Structuring of Users data by market, product, service, etc.

Recording: LIBELIUM may record phone conversations with Users, to have an evidence of their requests (of info, services, assistanceā¦).

Pseudonymisation meaning the processing of personal data in such a manner that the personal data can no longer be attributed to a specific data subject without the use of additional information,
provided that such additional information is kept separately. This is what we do with any data concerning health and obtained through MySignals products and services, which are obtained only to provide MySignals Customers access to their historical.

Profiling: LIBELIUM shall not make any profiling by using personal data.

Disclosure by transmission to some of LIBELIUMĀ“s service providers or partners (Recipients), who help us provide the services you enjoy by using our websites or purchasing our products and services.

Cross-border transfer: Cross-border transfer of data may exist, as LIBELIUMĀ“s service providers and partners may be either in the European Union or in third countries, always within a Privacy Shield Framework

Consultation and use by Libelium, for the purposes explained above.

Restriction, erasure or destruction, as per your request, or when the term of data processing, as explained below, comes to an end.

Personal data shall be processed by using the security measures requested by the Regulation to avoid any personal data breach (meaning a breach of security leading to the accidental or unlawful destruction, loss, alteration, unauthorised disclosure of, or access to, personal data transmitted, stored or otherwise processed). Users may nevertheless be aware of the fact that the existing security measures for computer systems on the Internet are not entirely trustworthy.

d. For how long do we store your personal data? personal data will be stored for the period strictly needed to serve the purposes described above and in connection with each kind of processing, for instance: (i) for the term of the contractual relationship entered with LIBELIUM and six years following its termination, according to Spanish Accountancy Regulations; (ii) as long as YOU do not exercise your right to erasure; (iii) for six years after your last statement of interest.

e. How can YOU exercise your rights? Please contact LIBELIUMĀ“s Data Protection Officer (DPO), by email (privacy@libelium.com) or at the following address: LIBELIUM COMUNICACIONES DISTRIBUIDAS, S.L. Attn. Data Protection Officer, C/ EscatrĆ³n 16. 50014 Zaragoza (Spain). Users may request from the DPO at any time access to and rectification or erasure of personal data or restriction of processing concerning their data, as well as data portability; Users may, at any time, withdraw consent without affecting the lawfulness of processing based on consent before its withdrawal; Users may at any time lodge a complaint with the Spanish Agency on Data Protection (www.agpd.es) or with any other Supervisory Authority;

3.2. Right of Access (Article 15)

Users shall have the right to obtain from our DPO confirmation as to whether or not personal data concerning him or her are being processed, and, where that is the case, access to their personal data. Our DPO shall provide a copy of the personal data undergoing processing. For any further copies requested by User, the DPO may charge a reasonable fee based on administrative costs. Where User makes the request by electronic means, the information shall be provided in a commonly used electronic form.

3.3. Right to Rectification and Erasure (āright to be forgottenā, Articles 16-17)

Users shall have the right to obtain from the DPO without undue delay the rectification of inaccurate personal data concerning him or her, and to have incomplete personal data completed, including by means of providing a supplementary statement.

Users shall also have the right to obtain from the DPOr the erasure of personal data concerning him or her without undue delay, in the circumstances set forth in Section 17 of the Regulation.

3.4. Right to restriction of processing (Articles 18-19)

Users shall have the right to obtain from the DPO restriction of processing in the circumstances set forth in section 18 of the Regulation.

3.5. Right to data portability (Article 20)

Subject to the restrictions in Section 20 of the Regulation, Users shall have the right to receive their personal data in a structured, commonly used and machine-readable format and have the right to transmit those data to another controller without hindrance from the controller to which the personal data have been provided, where:

(a) the processing is based on consent previously granted; and

(b) the processing is carried out by automated means.

In exercising his or her right to data portability Users shall have the right to have the personal data transmitted directly from one controller to another, where technically feasible.

3.6. Right to object and automated individual decision-making (Articles 21-22)

Users shall have the right to object at any time to processing of personal data for direct marketing purposes, for scientific or historical research purposes or statistical purposes pursuant to Article 89(1) of the Regulation.

Moreover and subject to the limitation in Section 22 of the Regulation, Users hall have the right not to be subject to a decision based solely on automated processing, including profiling, which produces legal effects concerning him or her or similarly significantly affects him or her.

Website navigation and Cookies

By navigating on LIBELIUMĀ“s websites you accept our using āCookiesā, unique identifiers that we transfer to your device to enable our systems to recognize your device and to:

Identify you when you sign-in to our sites, allowing us to provide you with product recommendations and display personalized content;

Conduct research and diagnostics to improve LIBELIUM's content, products and services;

Prevent fraudulent activity;

Improve security.

YOU may visit LIBELIUMĀ“s websites without disclosing your identity or any personal data, unless YOU voluntarily choose to disclose such information by filling the forms in our websites. LIBELIUMĀ“s servers may only collect domain names and IP addresses but not email addresses of their visitors. This kind of information is used to elaborate reports on visit statistics, the time spent in our websites, websites accessed, the general origin of visitors (through āFavoritesā, search engines, links from other websites, etc.) to the sole purposes of getting information on how our websites are used and improving their contents and services.

LIBELIUMĀ“s websites may provide links to other sites but LIBELIUM assumes no liability on the privacy policies adopted by the linked sites, directly or indirectly. Links to other sites are provided as a suggestion only and do not imply LIBELIUMĀ“s warranty or liability concerning their quality, accuracy or contents of the information provided therein.

LIBELIUM does not warrant the veracity or accuracy of the information disclosed by its suppliers, partners, developers or third parties whose products or services are offered through LIBELIUMĀ“s websites, their origin, ownership or the use or practical implementation made by Users.