Modbus RTU Server

Modbus RTU Server

This tutorial guides you through setting up a Modbus RTU server on a NEXTuino BASE. The server controls an LED via a Modbus RTU client writing to a coil register.

Prerequisites

  • Arduino IDE installed
  • NEXTuino BASE board

Required Libraries

Install the following libraries via the Library Manager in the Arduino IDE:

  • ArduinoRS485
  • ArduinoModbus

Example Code

The complete example is available on GitHub:
ModbusRTUServerLED.ino

Step-by-Step Guide

Step 1: Setup the Arduino Environment

  1. Connect your MICRO to your computer.
  2. Open the Arduino IDE.
  3. Ensure the appropriate board and port are selected in the Tools menu.
  4. Install ArduinoRS485 and ArduinoModbus via the Library Manager.

Step 2: Understanding the Code

  • Libraries: Include ArduinoRS485 and ArduinoModbus.
  • RS485 Configuration: Set up RS485 serial communication parameters.
  • Setup Function: Initialize serial communication, configure the Modbus RTU server, and set up the LED pin.
  • Loop Function: Continuously poll for Modbus requests and toggle the LED based on the coil value at address 0x00.

Step 3: Testing

After uploading, use a Modbus RTU client to send requests to the server:

  • Write 1 to coil address 0x00 to turn the LED on.
  • Write 0 to coil address 0x00 to turn the LED off.

Troubleshooting

  • Verify the correct COM port and board settings in the Arduino IDE.
  • Check the RS485 wiring between client and server.
  • Ensure the Modbus client is configured with the correct device address, baud rate, and parity settings.