RS-485 MODBUS Serial Communication with Arduino as Master

Khairul's picture


Joined: Jun 27, 2019

Replies: 0
RS-485 MODBUS Serial Communication with Arduino as Master
June 27, 2019 - 12:53pm


im khairul from malaysia.

i try 1 of the project provided which is RS-485 MODBUS Serial Communication with Arduino as Master.

im using arduino UNO and ModbusMaster.h library

i having problem with the code while compiling.

node.begin(1,Serial); ---> this line keep getting error no matching function for call to 'ModbusMaster::begin(int, HardwareSerial&)'

also for this line

node.preTransmission(preTransmission);  ---> the error 'class ModbusMaster' has no member named 'preTransmission'


here is my full code:

#include <ModbusMaster.h>               //Library for using ModbusMaster

#define MAX485_DE      3
#define MAX485_RE_NEG  2

ModbusMaster node;                    //object node for class ModbusMaster

int countvalue = 0;
float pressurevalue = 0;

void preTransmission()            //Function for setting stste of Pins DE & RE of RS-485
  digitalWrite(MAX485_RE_NEG, 1);             
  digitalWrite(MAX485_DE, 1);

void postTransmission()
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);

void setup()
  pinMode(MAX485_RE_NEG, OUTPUT);
  pinMode(MAX485_DE, OUTPUT);
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);

  Serial.begin(115200);             //Baud Rate as 115200

 node.begin(1,Serial);            //Slave ID as 1
  node.preTransmission(preTransmission);         //Callback for configuring RS-485 Transreceiver correctly

void loop()
  countvalue = analogRead(A1);
  pressurevalue = map(countvalue, 3, 608, 0, 101.5);
  float voltage = countvalue * (3.0 / 608.0);
  int countvalue1 = countvalue *1.6825657;
  node.writeSingleRegister(0x40000,pressurevalue);  //Writes value to 0x40000 holding register


anyone can help me?

Pramoth Thangavel's picture


Joined: Aug 28, 2018

Replies: 1
RS-485 MODBUS Serial Communication with Arduino as Master
June 27, 2019 - 8:02pm

Hello Mr.Khairul,

This error is due to that the library doesn't match.

Download the ModbusMaster.h library zip from this link (The Link in the Tutorial is wrong! I apologise for the mistake )

Make sure you have included the ModbusMaster.h library in your sketch. (Tools->Include library->Add .zip library).

After that compile again! You will compile sucessfully :)