Modbus RTU Server

Categories: ,

Introduction

This tutorial will guide you through setting up a Modbus RTU server on a CONTROLLINO MICRO. We’ll be using a modified version of an example code that demonstrates how to control an LED via a Modbus RTU server.

Prerequisites

  • Installed Arduino IDE.
  • CONTROLLINO MICRO board.

Example Code

Please grab the following example .ino file from Github:

Step-by-Step Guide

Step 1: Setup the Arduino Environment

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

Step 2: Understanding the Modbus RTU Server Code

The provided code snippet establishes a Modbus RTU server. Here’s a breakdown:

  • Libraries: Include ArduinoRS485 and ArduinoModbus.
  • RS485 Configuration: Set up the RS485 serial communication.
  • Setup Function: Initialize serial communication, set up the Modbus server and LED.
  • Loop Function: Constantly checks for Modbus requests and toggles the LED based on the coil value.

Step 3: Testing the code

After uploading, your CONTROLLINO MICRO should be ready to respond to Modbus RTU client requests. Use a Modbus RTU client to send requests to your server:

  • Writing a value of 1 to coil address 0x00 should turn the LED on.
  • Writing a value of 0 should turn it off.

Troubleshooting

If the LED does not respond as expected, check the following:

  • Correct wiring of the LED and Modbus connections.
  • Verify the correct COM port and board settings in the Arduino IDE.
  • Make sure the Modbus client is correctly configured to communicate with your server.

Conclusion

You have now successfully created a Modbus RTU server on your CONTROLLINO MICRO. This server can interact with Modbus clients, allowing for various automation and control applications. Experiment with different Modbus registers and functionalities to expand your project!

Share This Post

More Tutorials to explore

HTTP Web Client

Introduction Welcome to the “HTTP Web Client” tutorial using the CONTROLLINO MICRO. In this tutorial, we will learn how to create a web client that

Scan for I2C Devices

Introduction The I2C (Inter-Integrated Circuit) protocol is a popular means of communication between various sensors and devices. In this tutorial, we will learn how to