Modbus RTU With Feather Boards

by Zihatec in Circuits > Microcontrollers

7 Views, 0 Favorites, 0 Comments

Modbus RTU With Feather Boards

Deckblatt.jpg

The MODBUS RTU bus system is still used today for many control tasks in industry, building automation, access control and energy management.

MODBUS RTU uses the RS485 interface. The RS485 standard (EIA-485) is characterized by various advantages over other standards:

  1. up to 32 devices can be connected to one bus (256 in newer systems)
  2. Cable lengths of up to one mile are possible
  3. No special requirements are placed on the cable used.
  4. very resistant to interference

In the following project I show how to connect the well-known microcontroller boards in Feather format, which are available from various manufacturers, e.g. Adafruit or Sparkfun for different platforms (e.g. ESP32, RP2040, Cortex M4 etc.), to a MODBUS RTU system.

Supplies

web0.jpg

As mentioned above, an RS485 interface is required to connect a microcontroller to the MODBUS. To do this, we extend the Feather board with an additional board (called a “wing” in the Feather universe). The RS485/RS422 Feather wing from Zihatec is used in these instructions. This wing has an electrically isolated RS485 interface, which protects the feather board and any connected computer.

Furthermore a Feather microcontroller board e.g. Adafruit Huzzah32 and another MODBUS capable device e.g. a relay box from Waveshare is required.

Wiring Connection

Modbus_connection.png

The RS485 uses two lines for signal transmission. These two signals are often labeled A and B on RS485 devices. Unfortunately, the use of the letters A and B is not uniformly regulated. In the RS485 Wing, "A" means R+/T+ (also known as D+) and "B" means R-/T- (also known as D-). This may also differ for other devices.

(DIP) Switch Setting

features Modbus wing.jpg
dip switch setting.jpg

The Feather wing has two DIP switches and a slide switch, which must be set accordingly for proper function:

The S1 DIP switch can be used to select the control of the send/receive switchover. We let the wing automatically switch the transmit/receive direction. This means that we no longer have to worry about this later in the software. S1 is therefore set to OFF - ON - ON - OFF.

The wing can be configured to half or full duplex mode with S4. S4 can also be used to switch on the pull-up and pull-down resistors for fail safe biasing.

We need half-duplex for the RS485 function and also activate biasing. All S4 switches are therefore set to ON.

The terminating resistor can be switched on with slide switch S2. This is only necessary if the wing is connected to one of the two ends of the bus line. Otherwise, S2 remains off.

C++ Software

The Wing can be operated either as a MODBUS master (also called "client" in more recent publications) or MODBUS slave (also called "server" in more recent publications). Different software is required for both types of operation.

We use the Arduino IDE for our examples. The example code for master and client can be found in our Github repository. Our code uses CSE libraries for RS485 and Modbus RTU by Vishnu Mohanan.

Important note: For the software to work properly, the correct (micrcontroller) board must be configured in the Arduino IDE.

Otherwise, only the correct baud rate and parameters needs to be set in the setup function:

RS485.begin (9600,SERIAL_8N1);

Example

Modbus RTU communication with Feather boards #shorts

Here is a short video to illustrate the function in which the COIL registers of a Waveshare relay module are set cyclically via Modbus: