Overview
In this guide, we will interface the XBee Module with a Raspberry Pi Pico and set up ZigBee communication using MicroPython Code to use it as a transmitter and receiver. Earlier we learned about Arduino ZigBee Communication.
ZigBee is a wireless communication protocol designed primarily for IoT (Internet of Things) applications, enabling smart devices to connect and communicate seamlessly in a mesh network. This mesh structure allows ZigBee devices to relay data through one another, extending the network’s range and improving reliability.
In this tutorial, we will:
- Introduce the XBee Module: Learn about the XBee module’s features, applications, and communication range.
- Set Up XCTU Software: Use XCTU to configure the XBee module as a transmitter or receiver.
- Connect XBee Modules to the Raspberry Pi Pico: Set up one Raspberry Pi Pico with an XBee module as a transmitter and another as a receiver.
- Write Sample MicroPython Code: Create code in MicroPython to send data wirelessly between the two Raspberry Pi Pico boards.
- Test the Wireless Communication: Verify successful data transmission between the transmitter and receiver over a certain distance.
By the end, you’ll have a fully functional setup for wireless ZigBee communication using the XBee Module and Raspberry Pi Pico.
Components Required
For interfacing the XBee Module with Raspberry Pi Pico, we need the following components.
| S.N. | Components Name | Quantity | Purchase Link |
|---|---|---|---|
| 1 | Raspberry Pi Pico | 2 | Amazon | AliExpress |
| 2 | XBee Module | 2 | Amazon | AliExpress |
| 3 | Xbee Adapter | 2 | Amazon | AliExpress |
| 4 | DHT11 Sensor | 1 | Amazon | AliExpress |
| 5 | Connecting Wires | 10 | Amazon | AliExpress |
| 6 | Breadboard | 2 | Amazon | AliExpress |
XBee Module
XBee modules are popular wireless communication modules developed by Digi International, designed to make wireless networking easy for IoT and embedded applications.
This is Zigbee XBee Module S2C 802.15.4 2mW with Wire Antenna XB24CZ7WIT-004. The XBee 2mW Wire Antenna S2C, the latest in Series 2, offers easy point-to-multipoint device connectivity, providing cost-effective wireless solutions for electronic devices. They are interoperable with other ZigBee feature set devices, including devices from different vendors.
Key Features of XBee Modules
- Integrated, Wire Antenna
- Interoperable with other ZigBee-compliant devices
- Programmable versions with onboard microprocessors enable custom ZigBee application development
- Supports binding and multicasting for easy integration into a home automation platform
- Through-hole form factor enables flexible design
- 15 general-purpose I/O lines
- Industry-leading sleep current of sub 1 µA
- Firmware upgrades via UART, SPI, or over-the-air
XBee Module Pinout
The XBee module has 20 pins, each serving specific functions that support various I/O, communication, and control features.
| Pin No. | Name | Direction | Description |
|---|---|---|---|
| 1 | VCC | – | Power Supply |
| 2 | DOUT | Output | UART Data Out |
| 3 | DIN/CONFIG | Input | UART Data In |
| 4 | DO8 | Output | Digital Output 8 |
| 5 | RESET | Input | Module Reset (reset pulse >= 200 ns) |
| 6 | PWM0/RSSI | Output | PWM Output 0 / Received Signal Strength Indicator |
| 7 | PWM1 | Output | PWM Output 1 |
| 8 | Reserved | – | Do not connect |
| 9 | DTR/SLEEP_RQ/DI8 | Input | Sleep Control or Digital Input 8 |
| 10 | GND | – | Ground |
| 11 | AD4/DIO4 | Input / Output | Analog Input 4 / Digital I/O 4 |
| 12 | CTS/DIO7 | Input / Output | Clear-To-Send Flow Control or Digital I/O 7 |
| 13 | ON/SLEEP | Output | Module Status Indicator, High = ON, Low = SLEEP |
| 14 | VREF | Input | Reference Voltage for ADC |
| 15 | ASSOCIATE/AD5/DIO5 | Input / Output | Association Indicator, Analog Input 5 or Digital I/O 5 |
| 16 | RTS/AD6/DIO6 | Input / Output | Request-To-Send Flow Control, Analog Input 6 or Digital I/O 6 |
| 17 | AD3/DIO3 | Input / Output | Analog Input 3 or Digital I/O 3 |
| 18 | AD2/DIO2 | Input / Output | Analog Input 2 or Digital I/O 2 |
| 19 | AD1/DIO1 | Input / Output | Analog Input 1 or Digital I/O 1 |
| 20 | AD0/DIO0 | Input / Output | Analog Input 0 or Digital I/O 0 |
XBee USB Adapter Board
One disadvantage of the Zigbee module is its lack of breadboard compatibility; its pin mapping doesn’t align with typical breadboards. Additionally, most Zigbee modules operate within a voltage range of 2.0V to 3.6V, with 3.3V as the standard. This makes them incompatible with 5V microcontrollers or any microcontrollers with higher voltage digital pins.
To overcome this, a Zigbee Adapter is needed. A popular choice is the XBee USB Adapter, a UART communication board designed specifically for XBee connectivity. It provides a UART interface, USB interface, and includes onboard buttons and LEDs, making it a user-friendly option for both development and debugging.
Key Features of the XBee USB Adapter
- Compatibility with Microcontrollers: The adapter operates with 3.3V logic, making it compatible with 3.3V microcontrollers.
- USB Interface: Equipped with a USB port, the adapter enables direct communication with a computer, allowing configuration and testing using AT Commands.
- Testing and Debugging: The adapter includes buttons and LEDs that facilitate easy testing of XBee modules.
Using XBee Module with XBee Adapter Board
To use the Zigbee module, start by carefully inserting it into the adapter board, ensuring the correct alignment and orientation.
The module should fit securely on top of the adapter, so double-check that the pins are properly aligned to avoid any connection issues.
Setting Up XBee Module using the X-CTU Software
Digi International provides a software tool known as X-CTU for configuring XBee in either operating mode or device function type. Using this tool, we can configure the device, test its performance, and upgrade its firmware.
Here we need first to download X-CTU software and go through a short overview of the X-CTU User Guide.
Follow these steps to configure two Zigbee modules—one as the coordinator and the other as the end device—using the X-CTU software.
Configure the Coordinator
- Connect the ZigBee Module: Plug the ZigBee module into your computer using a USB cable and note the COM port assigned to it.
- Open X-CTU Software: Launch the X-CTU software, then click on the Add Device option.
- Select COM Port: Choose the appropriate COM port for your connected ZigBee module and click Next. No additional settings need to be changed here, so click Finish to begin searching for the module.
- Add the Detected Device: When X-CTU detects your module, select it and click Add Selected Device. This will open the module’s configuration page.
- Update Firmware (if prompted): If X-CTU suggests a firmware update, proceed with the upgrade to ensure your module is using the latest version.
- Set Device as Coordinator:
- Write Settings: Click on Write to save these changes to the module. Your coordinator is now configured.
Configure the End Device
- Connect the Second ZigBee Module: Insert the second ZigBee module into your computer, following the same process as above.
- Select COM Port: Once connected, choose the appropriate COM port in X-CTU, click Next, and then Finish to start device detection.
- Add the Detected Device: Once the device is found, select it and add it to the software. If a firmware update is prompted, proceed to update.
- Set Device as End Device:
- Write Settings: Click Write to save these settings to the module. Your end device is now configured.
Once these steps are completed, your ZigBee modules are set up, with one as a coordinator and the other as an end device, and are ready for communication.
Interfacing XBee Module with Raspberry Pi Pico
Lets setup the hardware by interfacing XBee Module with Raspberry Pi Pico. First we will establish the hardware connection between Raspberry Pi Pico & XBee module so that we can establish ZigBee Communication.
We need to setup the two pieces of hardware here. One for the transmitter (end device) and the other one for the receiver (coordinator).
Transmitter Circuit (End Device)
On the transmitter circuit, connect the XBee Module & DHT11 Humidity Temperature Sensor to the Raspberry Pi Pico Board as shown in the image below.

Connect the XBee Module Adapter VCC & GND Pin to 5V & GND Pin of the Pico. For the TX & Rx part of XBee Module Adapter, we will use the UART0 Pin of the Pico. For the DHT Sensor, connect its digital pin to GP15 of Raspberry Pi Pico.

You may use the breadboard and jumper wire to assemble and connect the hardware as per the circuit diagram.
Receiver Circuit (Coordinator)
On the receiver circuit, connect only the XBee Module to the Raspberry Pi Pico Board as shown in the image below.

Connect the XBee Module Adapter’s VCC and GND pins to the 5V and GND pins on the Raspberry Pi Pico. For data communication, connect the XBee Module Adapter’s TX and RX pins to the Raspberry Pi Pico’s UART0 pins (TX to RX and RX to TX).

That’s all from the hardware connection part. Now lets move to the coding part.
MicroPython Code for Raspberry Pi Pico ZigBee Communication
To establish the ZigBee Communication between Raspberry Pi Pico & XBee module, we need to write MicroPython Code for both transmitter & receiver.
Transmitter Code (End Device)
The sender code initializes a DHT11 sensor to measure temperature and humidity, formats the readings into a structured message (e.g., <T:29,H:71>), and sends this data over UART to an XBee module for wireless transmission. It also prints the sent values to the console for debugging purposes and repeats the process every 2 seconds.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import machine import utime import dht from machine import UART # Initialize the DHT11 sensor sensor = dht.DHT11(machine.Pin(15)) # Initialize UART for XBee communication uart = UART(0, baudrate=9600) def read_and_send(): try: sensor.measure() temp = sensor.temperature() hum = sensor.humidity() # Prepare the message string message = "<T:{},H:{}>".format(temp, hum) # Send the message over UART uart.write(message) # Debugging output to console print("Sent Temp: {} C, Hum: {} %".format(temp, hum)) except OSError as e: print("Failed to read from DHT sensor") utime.sleep(2) while True: read_and_send() |
Receiver Code (Coordinator)
The receiver code listens for incoming UART data from an XBee module, checks if the received message is correctly formatted (e.g., <T:29,H:71>), and extracts the temperature and humidity values. It then prints the raw message as well as the parsed temperature and humidity values to the console for verification. If the message format is incorrect or parsing fails, it prints an error message. The process repeats every second to avoid flooding the output.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
from machine import UART import utime # Initialize UART for XBee communication uart = UART(0, baudrate=9600) def receive_and_display(): if uart.any(): message = uart.readline().decode() if message.startswith('<') and message.endswith('>'): print("Raw Msg: ", message.strip()) # Extract temperature and humidity try: temp_start = message.find('T:') + 2 temp_end = message.find(',', temp_start) temp = float(message[temp_start:temp_end]) hum_start = message.find('H:') + 2 hum_end = message.find('>', hum_start) hum = float(message[hum_start:hum_end]) # Debugging output to console print("Received Temp: {} C, Hum: {} %".format(temp, hum)) except ValueError: print("Failed to parse temp and humidity.") while True: receive_and_display() utime.sleep(1) # Small delay to prevent flooding the output |
Testing Raspberry Pi Pico ZigBee Communication
Connect both Raspberry Pi Pico boards (one for the transmitter and one for the receiver) to your computer via USB.
Run each script separately on the respective Pico board by clicking the Run button in Thonny.
- Sender Output: On the first Pico (transmitter), you’ll see the output in Thonny’s Shell window, where it displays the formatted message with temperature and humidity values being sent (e.g.,
"Sent Temp: 29 C, Hum: 71 %"). - Receiver Output: On the second Pico (receiver), the Shell window will show the received message, including both the raw format (e.g.,
"Raw Msg: <T:29,H:71>") and the extracted temperature and humidity values (e.g.,"Received Temp: 29.0 C, Hum: 71.0 %").
Video Tutorial & Guide
This is how we can interface XBee Module with Raspberry Pi Pico using MicroPython Code and establish ZigBee communication between end device and coordinator.


















