ModbusMaster library for Arduino

This project implements a Modbus RTU Master for the Arduino microcontroller. The code is packaged as an Arduino library, complete with example sketches.


The Playground wiki has been updated to include the above link. Code has been tested on a Phoenix Contact nanoLC controller.

The following Modbus functions have been implemented:

  • 0x01 - Read Coils
  • 0x02 - Read Discrete Inputs
  • 0x05 - Write Single Coil
  • 0x0F - Write Multiple Coils

  • 0x03 - Read Holding Registers

  • 0x04 - Read Input Registers

  • 0x06 - Write Single Register

  • 0x10 - Write Multiple Registers

  • 0x16 - Mask Write Register

  • 0x17 - Read Write Multiple Registers

Feedback is welcome.


Project inspired by Arduino Modbus Master

Nice! Might going to use this with a operator screen I have which has modbus as one of it's protocols.

The class has been revised so each object instantiation is tied to a particular Modbus slave. Functions have been added to get/set private variables and Modbus functions have been updated to simplify end user coding. See project Source tab for details on specific changes.

To do: - implement ability to select UART during object instantiation (on Arduinos with >1 UART)- add function to retrieve register data as 32-bit long words- add range checking on get/set functions Rx

You can now select serial ports 0..3. Range checking is implemented on get/set methods RX/TX. See project Source tab for details on specific changes.