Skip to content

vinayraj02/ModbusLite_Arduino

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

14 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

ModbusLite for Arduino Opta

ModbusLite_Arduino is a lightweight, industrial-grade Modbus SDK built specifically for the Arduino Opta platform. It brings the reliability and structure of our Linux-based Modbus SDK into the embedded Opta environment โ€” with support for both Modbus TCP and Modbus RTU communication.

๐Ÿง  Overview

ModbusLite_Arduino provides a consistent and portable API that allows the Opta to operate as:

  • ๐Ÿ–ง Modbus TCP Master or Slave over Ethernet
  • ๐Ÿ”Œ Modbus RTU Master or Slave over RS485
  • โš™๏ธ A future-ready hybrid bridge between TCP โ†” RTU networks

It was developed to ensure stable, crash-free operation on industrial Opta PLCs while maintaining full interoperability with the existing Linux ModbusLite SDK.

๐Ÿญ Industrial Motivation

In industrial automation, you often have a mix of devices:

  • Field sensors and actuators speaking Modbus RTU (RS485)
  • Gateways and controllers using Modbus TCP (Ethernet)
  • Edge devices like Raspberry Pi or Linux-based controllers running custom logic

The Opta sits perfectly in between โ€” acting as:

  • A Modbus master collecting data from remote devices
  • A slave exposing local process variables
  • Or a bridge, forwarding Modbus data between fieldbus and network domains

However, standard Arduino Modbus libraries are too heavy, unstable, or inflexible for real industrial use. ModbusLite_Arduino was designed to solve that.

๐Ÿš€ Key Features

  • Full Modbus/TCP and Modbus/RTU compliance
  • Optimized for Optaโ€™s mbed OS stack โ€” no crashes or watchdog resets
  • Unified ModbusLite API shared with the Linux SDK
  • Lightweight memory footprint suitable for real-time control
  • Asynchronous-ready architecture for future expansions
  • Cross-platform interoperability with Linux and other controllers

๐Ÿ”ง Supported Modes

Mode Description Typical Use Case
Modbus TCP Master Opta polls Modbus TCP slaves over Ethernet Control or data aggregation
Modbus TCP Slave Opta exposes holding/input registers to TCP masters PLC data access
Modbus RTU Master Opta sends Modbus frames over RS485 Fieldbus device control
Modbus RTU Slave Opta responds to serial Modbus queries Local register interface

๐Ÿ”ฉ Example Scenarios

1๏ธโƒฃ Opta TCP Master โ†” Opta TCP Slave

Two Optas exchange register data over Ethernet. Used to simulate control between nodes or test register mapping.

2๏ธโƒฃ Opta TCP Master โ†” Linux Modbus SDK Slave

Demonstrates interoperability with industrial gateways or simulators.

3๏ธโƒฃ Opta RTU Master โ†” Opta RTU Slave

RS485-based communication between PLCs and field sensors.

4๏ธโƒฃ Future: Opta Hybrid Bridge

TCP master โ†’ Opta โ†’ RTU slave Opta acts as a gateway between Ethernet and serial Modbus networks.

๐Ÿงฉ Integration with Linux SDK

This Arduino SDK directly mirrors the Linux ModbusLite SDKโ€™s internal architecture:

Layer Arduino SDK Linux SDK Purpose
Core Context modbus_context.h Same Shared PDU/ADU state machine
TCP Transport EthernetClient, EthernetServer BSD sockets Identical protocol framing
RTU Transport Serial1 (RS485) /dev/ttySx CRC-compatible data exchange
High-Level API ModbusLite ModbusLite Same class interface

This ensures full cross-platform communication between Opta and Linux-based gateways.

๐Ÿงฑ Repository Structure

ModbusLite_Arduino/

โ”œโ”€โ”€ src/

โ”‚ โ”œโ”€โ”€ ModbusLite.cpp

โ”‚ โ”œโ”€โ”€ ModbusLite.h

โ”‚ โ””โ”€โ”€ core/

โ”‚ โ”œโ”€โ”€ modbus_context.cpp

โ”‚ โ”œโ”€โ”€ modbus_tcp.cpp

โ”‚ โ”œโ”€โ”€ modbus_rtu.cpp

โ”‚ โ”œโ”€โ”€ modbus_server.cpp

โ”‚ โ”œโ”€โ”€ modbus_core.c

โ”‚ โ””โ”€โ”€ modbus_register_map.cpp

โ”œโ”€โ”€ examples/

โ”‚ โ”œโ”€โ”€ Opta_TCP_Master/

โ”‚ โ”œโ”€โ”€ Opta_TCP_Slave/

โ”‚ โ”œโ”€โ”€ Opta_RTU_Master/

โ”‚ โ””โ”€โ”€ Opta_RTU_Slave/

โ””โ”€โ”€ README.md

โš™๏ธ Requirements

  • Arduino IDE 2.3.2+
  • Opta board support package (Arduino-mbed 4.4.1+)
  • Ethernet library (included with Opta BSP)
  • RS485 shield or built-in port (Opta RS485 variant)

๐Ÿงฐ Installation

  1. Clone or download this repository into your Arduino libraries folder:
git clone https://github.com/vinayraj02/ModbusLite_Arduino
  1. Open Arduino IDE โ†’ File โ†’ Examples โ†’ ModbusLite_Arduino
  2. Select your Opta board and upload one of the example sketches.

๐Ÿงช Testing

Use any of the following setups:

  • ๐Ÿ–ฅ๏ธ QModMaster / Modbus Poll for PC-based TCP testing
  • ๐Ÿงฉ Raspberry Pi with ModbusLite SDK as the TCP or RTU counterpart
  • โš™๏ธ Two Opta boards for end-to-end industrial testing

๐Ÿงฎ Example Output

TCP Master Example

\=== Opta Modbus TCP Master ===

Local IP: 192.168.1.177

Connecting to Modbus slave...

\[OK\] Connected to Modbus slave.

Read Holding Registers:

Reg\[0\] = 29

Reg\[1\] = 10

Reg\[2\] = 20

Reg\[3\] = 30

Reg\[4\] = 40

\[OK\] Write success.

**RTU Slave Example**
\=== Opta Modbus RTU Slave ===

\[INFO\] RS485 initialized and listening...

\[INFO\] HoldingReg\[0\] = 42

\[INFO\] HoldingReg\[0\] = 43

๐Ÿ“œ License

This library is licensed under the MIT License. See the LICENSE file for full details.

๐Ÿค Contribution

Pull requests are welcome! If you find an issue, open a GitHub issue with:

  • Your Opta board type
  • Example sketch name
  • Short description of the problem

All contributions that improve stability, performance, or Modbus compliance are encouraged.

๐Ÿงญ Future Development

  • ๐Ÿ”„ Hybrid TCPโ†”RTU gateway mode
  • ๐Ÿงฐ Modbus diagnostics and hex frame monitor
  • โšก Async callback support
  • โ˜๏ธ Integration with Optaโ€™s secure MQTT edge gateway layer

๐Ÿคต Maintained By

VK

Reliable โ€ข Lightweight โ€ข Cross-Platform

๐Ÿข About ModbusLite SDK Family

The ModbusLite SDK family is a suite of robust, interoperable libraries designed for seamless Modbus communication across embedded and Linux environments.

  • ModbusLite_Arduino: Tailored for Arduino Opta โ€” lightweight and optimized for real-time industrial PLCs.
  • ModbusLite Linux SDK: Full-featured for gateways, edge servers, and custom automation stacks on Raspberry Pi, Ubuntu, and beyond.

Both share a unified core architecture, ensuring zero-friction interoperability. Deploy Opta as a field controller alongside Linux-based orchestration โ€” or bridge them effortlessly for hybrid networks. Built for reliability in mission-critical automation.

Explore the Linux SDK | Join the Family

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published