Arduino Library – Modbus
Installatie van Arduino IDE libraries: Arduino info
Modbus RTU (smarmengol)
libmodbus is a library that provides a Serial Modbus implementation for Arduino.
A primary goal was to enable industrial communication for the Arduino in order to link it to industrial devices such as HMIs, CNCs, PLCs, temperature regulators or speed drives.
now you can use software serial with the update from Helium6072!
It is not compatible with ARDUINO LEONARDO and not tested under ARDUINO DUE and newer boards.
Common to Master and Slave:
- Implement other Serial settings: parity, stop bits, …
- End frame delay, also known as T35
- Test it with several Arduino boards: UNO, Mega, etc..
- Extend it to Leonardo
- Function code 1 and 2 still not implemented
- Function code 15 still not implement
- Other codes under development
New features by Helium6072 29 July 2016
- “port->flush();” changed into “while(port->read() >= 0);”
Since Serial.flush() (port->flush(); in ModbusRtu.h line 287, 337, & 827) no longer empties incoming buffer on 1.6 (Arduino.cc : flush() “Waits for the transmission of outgoing serial data to complete. Prior to Arduino 1.0, this instead removed any buffered incoming serial data.), use “while(port->read() >= 0);” instead.
- software serial compatible
New constructor Modbus::Modbus(uint8_t u8id) and method void Modbus::begin(SoftwareSerial *sPort, long u32speed) that makes using software serial possible. Check out sexample “software_serial_simple_master” and learn more!
Modbus RTU (SimpleModbus NG)
SimpleModbus is a collection of Arduino libraries that enables you to communicate serially using the Modicon Modbus RTU protocol.
This project was born as an updated version of http://code.google.com/p/simple-modbus/ by Bester Juan because it lacks support for commands other than 3 and 16. More important the code is now on github, so you can contribute more easily.
This projects is actively maintained, so feel free to ask for features or reporting bugs!
This library adds support for command 6 and provides a more extensive support for arduino pins. The goal of the project is to support all usable MODBUS commands on arduino and expose all arduino pins so you can use an arduino as an advanced automation controller for both analog/digital in/out.
NEW: Support for SoftwareSerial, really useful on AtTiny85. You can find both library and an example that works reliable on attiny85 microcontroller.
Simply copy the SimpleModbusMaster or SimpleModbusSlave or both into your Arduino IDE libraries folder. Than restart the ide and open the corresponding example into the example_master or example_slave folder.
Modbus TCP/IP – Mudbus (luizcantoni)
A minimal Modbus TCP slave for Arduino. It has function codes 1(read coils), 3(read registers), 5(write coil), and 6(write register). It is set up to use as a library, so the Modbus related stuff is separate from the main sketch. The register and coil data is held as Mb.R[0-125] signed int and Mb.C[0-128] bool
Martin Pettersson Has furnished some changes for compatibility with Arduino 1.0. He also has a git repository at
Modbus TCP/IP – MgsModbus
This page is holds my ModbusTCP library for the Arduino. The library gives the program the possibility to be a master, a slave or both on a TCP network.
The Modbus functions 1, 2, 3, 4, 5, 6 15 and 16 are implemented. The port 502 is used as standard.
Please report bugs to me to improve the library.
The library uses a single data space for all the Modbus data. This means that all the Modbus data spaces are overlapping and all starting with 0 (zero). This means that several Modbus functions can reach the same data. The user must assign the correct Modbus address to the data.
This library is started as a spinoff of the Mudbus.h slave library from Dee Wykoff from 2011.
Modbus RTU & TCP/IP (andresarmento)
This library allows your Arduino to communicate via Modbus protocol. The Modbus is a master-slave protocol used in industrial automation and can be used in other areas, such as home automation.
The Modbus generally uses serial RS-232 or RS-485 as physical layer (then called Modbus Serial) and TCP/IP via Ethernet or WiFi (Modbus IP).
In the current version the library allows the Arduino operate as a slave, supporting Modbus Serial and Modbus over IP.
Author’s note (motivation and thanks):
It all started when I found the Modbus RTU Arduino library of Juan Pablo Zometa. I had extend the library to support other Modbus functions.
After researching several other Modbus libraries I realized strengths and weaknesses in all of them. I also thought it would be cool have a base library for Modbus and derive it for each type of physical layer used.
I appreciate the work of all the authors of the other libraries, of which I used several ideas to compose the modbus-arduino. At the end of this document is a list of libraries and their authors.
- Operates as a slave (master mode in development)
- Supports Modbus Serial (RS-232 or RS485) and Modbus IP (TCP)
- Reply exception messages for all supported functions
- Modbus functions supported:
- 0x01 – Read Coils
- 0x02 – Read Input Status (Read Discrete Inputs)
- 0x03 – Read Holding Registers
- 0x04 – Read Input Registers
- 0x05 – Write Single Coil
- 0x06 – Write Single Register
- 0x0F – Write Multiple Coils
- 0x10 – Write Multiple Registers
- Modbus TCP-IP - Mudbus (luizcantoni) v1.0 arduino ide 1.0+ (2012-02-09).7z 4,06 kb
- Modbus TCP-IP - Mudbus (luizcantoni) v1.0 arduino ide 0.22 (2011-08-10).7z 3,87 kb
- Modbus TCP-IP - MsgModbus v1.0.7z 4,68 kb
- Modbus TCP-IP - MsgModbus v0.1.7z 4,32 kb
- Modbus RTU (smarmengol) (DL 2018-01-20 @ github).7z 93,53 kb
- Modbus RTU (SimpleModbus NG) (DL 2018-01-19 @ github).7z 21,89 kb
- Modbus RTU & TCP-IP (andresarmento) (DL 2018-03-02 @ github).7z 19,42 kb