Friday, March 1, 2024

XBee Interfacing With Raspberry Pi Model 2

Arnav Bansal. He is pursuing B.E. in electronics and communication from UIET PUSSGRC, Hoshiarpur

- Advertisement -

Now the serial port of Raspberry Pi is disengaged from the boot sequence and can be used to communicate with XBee module. The default baud rate of the ttyAMA0 is 115200, but a baud rate of 9600 is required for XBee. You can change the baud rate in minicom software as given below:

 [stextbox id=”grey”]

pi@raspberrrypi ~ $ sudo minicom –b 9600

- Advertisement -

–o –D /dev/ttyAMA0

[/stextbox]// This will set the baud rate of the port ttyAMA0 to 9600

A window, as shown in Fig. 9, will come up. Press Ctrl+A keys followed by Q on the keyboard to exit without resetting.

Python code

Start your Raspberry Pi and create a new ‘XBeeTest’ folder. For this tutorial, the libraries used are ‘serial’ and ‘time.’ Create a new file using nano editor as given below:

 [stextbox id=”grey”]

$ pi@raspberrrypi ~ $ cd /XBeeTest

pi@raspberrrypi ~ /XBeeTest$ sudo nano

Here is the name of the project. Type the following code:

import serial

// For serial communication

import time

 [stextbox id=”grey”]


// For delay function

 [stextbox id=”grey”]ser = serial.Serial(‘/dev/ttyAMA0’)[/stextbox]

// Set ser as object

 [stextbox id=”grey”]ser.baudrate = 9600[/stextbox]

// Set baud rate to 9600

[stextbox id=”grey”]



// Send character ‘A’

 [stextbox id=”grey”]time.sleep(1)[/stextbox]

// Give 1 second delay

 [stextbox id=”grey”]ser.write(“B”)[/stextbox]

// Send character ‘B’

 [stextbox id=”grey”]time.sleep(1)[/stextbox]

 // Give 1 second delay

[stextbox id=”grey”]ser.close()[/stextbox]

// Close communication

To save this code, press Ctrl+O keys followed by Ctrl+X.

fig 10Fig. 10: Receiver console
Fig. 10: Receiver console

This code sends character ‘A’ to the console (refer Fig. 10) of the receiver end, pauses for a second and then sends character ‘B.’


  1. Hi,
    Thanks for sharing your knowledge. While I update the radio module firmware, I only have “ZIGBEE TH Reg”, “805.15.4 TH” and “DIGIMESH 2.4 TH” function set. Is it compulsory to have “XBEE COORDINATOR AT”. Could you please tell me how can I go forward with the available function sets.


Electronics News

Truly Innovative Tech

MOst Popular Videos

Electronics Components