BACnet is an internationally standardized communication protocol for building automation that enables devices from different manufacturers—such as heating, ventilation, air conditioning, lighting, and security systems—to communicate with one another. While current BACnet systems mostly use Ethernet as the transmission medium (BACnet/IP), RS485 (BACnet MSTP) was typically used as Layer 0 in the early days.
BACnet stacks are available for the Raspberry Pi in C++ and Python. However, most tutorials focus almost exclusively on BACnet/IP.
In this tutorial, I’d like to show you how to use BACnet MSTP on the Raspberry Pi.
HardwareIt is recommended to use a newer Raspberry Pi 4 or Pi 5 for BACnet implementation. There are two reasons for this. First, the BACnet stack is relatively large and resource-intensive; second, these models have multiple hardware UARTs that are available exclusively for this purpose and are not used simultaneously for other functions such as Bluetooth.
Additionally, we need an RS485 interface for communication via BACnet MSTP. For this, I use a Zihatec RS485 HAT with galvanic isolation.
As for BACnet MS/TP, the most common connection method is the daisy-chain bus configuration, where all the devices in the network are connected in a linear chain using a single RS485 cable.
To do this, connect the “+” and “-” terminals of each device to one another. The HAT is equipped with a 5-pin connector, where two pins are labeled ‘A’ and “B.” Pin A must be connected to the “+” terminals, and pin B to the “-” terminals of the other devices.
For longer distances, it is recommended to use a twisted-pair cable. Distances of up to one mile are possible via RS485.
Settings on the HATThe DIP switches on the HAT must be set to RS485 mode (half-duplex). To do this, set the switches as follows:
- S1: OFF - ON - ON - OFF
- S2: OFF - OFF - ON - ON
- S3: OFF - OFF - ON - ON
Now we need to select the UART we want to use on K3 using two jumpers. The jumpers must be set to either position U3 (UART3), U4 (UART4), or U5 (UART5).
Note: On a Raspberry Pi 5, the UARTs are numbered differently. Here, U3 is UART2, U4 is UART3, and so on.
Preparing the operating systemFirst, install a current version of the Raspbian OS (in our case, Debian Trixie, 64-bit) onto an SD card. Then, as usual, update the OS to the latest version:
sudo apt update
sudo apt full-upgrade -yNow we need to enable the UART we want to use. To do this, open the Config.txt file:
sudo nano sudo nano /boot/firmware/config.txtNow let's enable the respective UART at the end of the file. For UART3, for example, that would be:
dtoverlay=uart3After saving the Config.txt file and restarting the Raspberry Pi, we can now check whether our UART is enabled:
sudo ls /dev/tty*Among others, an interface should now be available at the path /dev/ttyAMAx for the corresponding UART.
Now we can begin installing the BACnet stack.
git clone https://github.com/bacnet-stack/bacnet-stack.git
cd bacnet-stack
make clean all
cd bin
sudo lsThese compiled files should now be located in the bacnet-stack/bin directory—specifically, the three sample programs for BACnet MSTP:
The stack includes various sample programs for MSTP, including a tool for capturing data from a BACnet MSTP bus.
All we need to do is connect our RS485 interface to an existing system to record the protocols. (If no BACnet MSTP system is available, you can simply install YABE on a PC and record this communication.)
To do this, enter the following command in the /bacnet-stack/bin directory:
./mstpcap --baud 38400 /dev/ttyAMA3The baud rate and path to the interface may need to be adjusted, of course.
mstpcap then records all received packets in a file until the program is terminated with Ctrl+C.
Another way to use BACnet IP and MSTP on the Raspberry Pi is to use YABE (Yet Another BACnet Explorer). Since YABE is actually a Windows program written using Microsoft's.NET Framework, we first need to install mono-complete so that YABE can run on Linux.
sudo apt install mono-complete -yNow we can download the latest version of YABE as a ZIP file (not the EXE installer!!!) and unzip it.
wget https://sourceforge.net/projects/yetanotherbacnetexplorer/files/Yabe_v2.1.0.zip
unzip Yabe_v2.1.0.zip -d YABEYabe can now be started using mono. To access the interfaces, the startup command should be run via sudo
cd YABE
sudo mono Yabe.exeThe configuration window for the channel opens automatically. Under “Port, ” select the path to the serial interface, e.g., /dev/ttyAMA3.
After pressing the Start button, YABE automatically sends a Whois query, and the devices available on the bus are displayed:










Comments