How to Use BACnet MSTP With Arduino UNO R4

by Zihatec in Circuits > Arduino

23 Views, 0 Favorites, 0 Comments

How to Use BACnet MSTP With Arduino UNO R4

overview_image_52373403_617032.png

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 typically use Ethernet as the transmission medium (BACnet/IP), older systems typically used RS485 (BACnet MSTP) as Layer 0.

Since BACnet stacks are very large and therefore place higher demands on RAM and program memory, it has been virtually impossible until now to integrate a BACnet server onto an Arduino UNO. However, with the Arduino UNO R4, which offers significantly more flash and RAM, the situation is quite different.

BACnet operates on the client-server principle. A BACnet server provides data (such as temperatures, sensor readings, or switch states) within a building automation network. A BACnet client is the receiving device or control software that actively retrieves this data or sends commands to the server.

In this tutorial, I’d like to show you how to implement a simple BACnet MSTP server on the Arduino UNO R4.


Supplies

UNO_R4.jpg
RS485_Ansicht_mit_Arduino_1_klein.jpg

Needed Materials:

Arduino UNO R4

RS485 Shield

USB-to-RS485 Adaptor

Wiring

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 RS485 Shield 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.

Configuring the RS485 Shield

Jumper_setting_power.png
Jumper_setting_UNO_R4.png

For BACnet MSTP communication, the DIP switches and jumpers on the RS485 shield must be configured correctly.

First, we set the DIP switches as follows:

  1. S1: OFF - ON - ON - OFF
  2. S2: OFF - OFF - ON - ON
  3. S3: ON - OFF - ON - ON

Now the jumpers must be set correctly. Jumper JP1 is set to the 5V position. The Arduino UNO R4 has its own hardware UART (Serial1) that operates independently of the debug interface and is connected to pins D0 and D1. The two corresponding jumpers on the shield must now also be set.

Arduino Software

BACnet Arduino Program.jpg

Since the resources of an Arduino UNO R4 are relatively limited, a full BACnet stack cannot be installed on the UNO R4. However, Harish Patel’s BACnetLight library provides a stripped-down version that runs on a microcontroller. Although this stack is actually intended for the ESP32, it also runs without any issues on the Arduino UNO R4.

Since this library cannot currently be installed via the Library Manager, we must first download the library from GitHub and unzip it into the Arduino\Library directory.

For an initial test, I created a small sample program that includes a simple BACnet MSTP server with two data points.

One data point is an analog input that, in our example, receives data from a temperature sensor (the sensor values are generated randomly by the program).

The other data point is a binary output, which in our example is implemented as a virtual “relay” and outputs the relay's switching state via the debug interface.

Downloads

YABE

YABE_ARDUINO_1.png
YABE_ARDUINO_2.png

We now have a simple BACnet MSTP server that we can integrate into an existing installation. However, to test the device, we still need a client.

You can easily set up a client on a Windows or Linux PC using the free software YABE (Yet Another BACnet Explorer). In order for YABE to communicate via BACnet MSTP, we also need a standard USB-to-RS485 adapter.

Once the installation is complete, we can launch YABE. First, we go to Functions --> Add BACnet Channel

Now, in the right-hand section of the window, under “BACnet/MSTP over serial,” we set the COM port for the connected RS485 adapter (COM12 in my case) and, if necessary, the baud rate and other parameters:

Test the Arduino BACnet Server

YABE_ARDUINO_3.png
YABE_ARDUINO_4.png
YABE_ARDUINO_5.png

Our BACnet device is now automatically detected and displayed under the channel. If we double-click on the detected device, we can see three objects in the “Objects” window: Device Properties, Analog_Value, and BINARY_OUTPUT.

When you click on an object, its properties are displayed in the “Properties” window on the right, and you can also modify those properties. For example, if we click on BINARY_OUTPUT, we can change the relay state by modifying the “Present Value” variable in the Properties window (0 = relay open, 1 = relay closed). We can then see the result in the debug output of the Arduino IDE.