RS485 MODBUS Relay Control for Raspberry Pi – Eight Relays Stackable HAT Application Note

📘 Application Note: RS485 / MODBUS Control of the Eight Relays 4A/120V 8-Layer Stackable HAT for Raspberry Pi

Overview
This application note explains how to use the RS485/MODBUS interface built into the Eight Relays 4A/120V 8-Layer Stackable HAT for Raspberry Pi to control relay outputs from any MODBUS-capable master device — such as a PLC or industrial controller. It covers hardware setup, protocol basics, example command flows, integration with GitHub tools, and network configuration.


🚀 Product Summary

The Eight Relays Stackable HAT adds eight high-power relays (4 A at 120 VAC or 24 VDC) to any Raspberry Pi (Zero through Pi 5) with pluggable connectors and LED status indicators. The board exposes a robust RS485 port supporting industry-standard MODBUS RTU communications alongside I²C for the Pi itself.

Key Features

  • 8 relay outputs with NO/NC contacts and LED status

  • RS485 port with TVS surge protection for industrial communication

  • Supports MODBUS RTU for remote control

  • Stackable up to 8 boards (64 relays total)

  • Command line, Python, and Node-RED support via GitHub drivers


📡 Why RS485 & MODBUS?

RS485 provides differential signaling engineered for noise-resilient communication over long distances in industrial environments — essential when controlling relays far from the Raspberry Pi controller. MODBUS RTU is the standard protocol over RS485 networks, enabling multiple devices to be controlled from a master controller.


🧩 Hardware Setup

  1. Mount the HAT on the Raspberry Pi GPIO header.

  2. Configure the onboard DIP switches to select the board ID (if stacking) and RS485 mode (Pi serial vs onboard MCU).

  3. Connect A/B lines of the RS485 network from the HAT’s terminal block to your MODBUS master network.

  4. Terminate the RS485 bus if required (set the terminator DIP switch).


📏 MODBUS Architecture

MODBUS RTU frames consist of:

  • Address (1–247)

  • Function Code (e.g., read/write)

  • Data (register or coil data)

  • CRC checksum

This protocol enables reliable control of discrete coils — like relay outputs — across industrial networks.


🛠️ Software Support from GitHub

Sequent Microsystems maintains open repositories to control the relay HAT from the Raspberry Pi side or to expose commands for automation tools.

Command-Line & Python Tools

  • 8relind‑rpi on GitHub (MODBUS & GPIO control) – Command line and Python functions for version 4 HATs.

    • Install:


      git clone https://github.com/SequentMicrosystems/8relind-rpi.git cd 8relind-rpi/ sudo make install
    • After installation, run:


      8relind -h

      to list available commands.

💡 This tool interfaces locally via I²C. For true MODBUS over RS485 control from another device, see the MODBUS master integration section below.


📘 Example MODBUS Command Flows

Note: Exact register addresses and function codes vary per firmware — the relay board uses MODBUS function codes to read/write coil status.

Purpose MODBUS Function Data
Turn relay ON Write Single Coil (0x05) Address of coil + ON
Turn relay OFF Write Single Coil (0x05) Address of coil + OFF
Read relay state Read Coils (0x01) Starting address + number of coils

Example Frame to Turn Relay 1 ON

Field Value
Slave Address 01
Function Code 05
Coil Address High 00
Coil Address Low 00
Coil ON High FF
Coil ON Low 00
CRC

(Insert standard MODBUS RTU frame diagram here)

📌 Insert Diagram Placeholder:
Illustrate the MODBUS RTU frame structure: [Address][Function][Data][CRC]


🖧 MODBUS Master Integration

Once the HAT is on the RS485 bus:

  1. Set unique MODBUS addresses for each relay board if using several.

  2. Use any MODBUS master (e.g., PLC/HMI or industrial controller) to send Write Coil and Read Coils commands.

  3. Confirm responses to ensure proper coil state transitions (relay ON/OFF).

For Raspberry Pi as master, popular Python libraries like pymodbus allow scripting:


from pymodbus.client.sync import ModbusSerialClient as ModbusClient client = ModbusClient(method='rtu', port='/dev/serial0', baudrate=9600, timeout=1) client.connect() # Turn Relay 1 ON client.write_coil(0, True, unit=1)

📌 Insert Diagram Placeholder:
Wiring diagram of Raspberry Pi RS485 connection to the Relays HAT and optionally to a PLC master.


🧪 Testing & Validation

  1. Power all devices and verify DIP switch bus termination.

  2. Send a test Read Coils request from your MODBUS master.

  3. Toggle each relay and observe LED state changes on the HAT.

  4. Log success/failure responses for diagnostics.


🧠 Best Practices

  • Use proper RS485 termination resistors at network ends.

  • Assign unique MODBUS node IDs per board.

  • Shield RS485 cabling in electrical noise environments.


📎 References

  • Eight Relays HAT product details from Sequent Microsystems.

  • RS485 port design and standalone MODBUS support.

  • 8relind-rpi GitHub repository for control tools