ModbusMaster (community library)


Name Value
Name ModbusMaster
Version 1.2.0
Installs 49676
License GPL v3 (
Author Anurag Chugh
Download .tar.gz
All Versions 1.2.0, 1.1.0

Modbus Master Library for Particle Photon

Example Build Testing

Device OS Version:

This table is generated from an automated build. Success only indicates that the code compiled successfully.

Library Read Me

This content is provided by the library maintainer and has not been validated or approved.

##Overview## This is an Arduino class library for communicating with Modbus slaves over RS232/485 (via RTU protocol). Updated to support Arduino 1.0.

##Features## The following Modbus functions have been implemented:

Discrete Coils/Flags

  • 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

##Uploading Sketches## Arduinos prior to the Mega have one serial port which must be connected to USB (FTDI) for uploading sketches and to the RS232/485 device/network for running sketches. You will need to disconnect pin 0 (RX) while uploading sketches. After a successful upload, you can reconnect pin 0.

##Hardware## This library has been tested with an Arduino Duemilanove, PHOENIX CONTACT nanoLine controller, connected via RS485 using a Maxim MAX488EPA transceiver.


  • Arduino 17 (or later):

Determine the location of your sketchbook by selecting File > Preferences from within the Arduino IDE. If you don't already have a libraries folder within your sketchbook, create one and unzip the archive there. See this for more information.

  • Arduino 16 (or earlier):

Download the zip file, extract and copy the ModbusMaster folder to _ARDUINO_HOME/hardware/libraries_. If you are upgrading from a previous version, be sure to delete ModbusMaster.o.

##Support## Please report any bugs on the Issue Tracker.

##Questions/Feedback## I can be contacted at 4-20ma at wvfans dot net.

##Example## The library contains a few sketches that demonstrate use of the ModbusMaster library. You can find these in the examples folder.

##Acknowledgements## Project inspired by Arduino Modbus Master.

##Port to Spark Core## Adapted for Spark Core by Paul Kourany, March 14, 2014

##Port to Particle Photon## Further modifications and port to Particle Photon by Anurag Chugh, July 5, 2016 Changes:

  1. Replaced spaces with tabs for indentation
  2. If the initial bytes received in response to a transmitted frame are "zeros", keep discarding untl a non-zero byte is received
  3. Assign an use a TX_Enable pin to switch RS485 driver from receiving to transmitting.
  4. If debug is enabled, print TX and RX frames on Serial. Beware, enabling this messes up the timings for RS485 Transactions, causing them to fail.
  5. Empty the receive before beginning Modbus transaction by repeatedly calling read() until available() returns 0.

Browse Library Files