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:
ArduinoRS485ArduinoModbus
Example Code
The complete example is available on GitHub:
ModbusRTUServerLED.ino
Step-by-Step Guide
Step 1: Setup the Arduino Environment
- Connect your MICRO to your computer.
- Open the Arduino IDE.
- Ensure the appropriate board and port are selected in the Tools menu.
- Install
ArduinoRS485andArduinoModbusvia the Library Manager.
Step 2: Understanding the Code
- Libraries: Include
ArduinoRS485andArduinoModbus. - 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
1to coil address0x00to turn the LED on. - Write
0to coil address0x00to 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.