How to add ModbusRtu.h library

`/**

  • Modbus slave example 3:
  • The purpose of this example is to link a data array
  • from the Arduino to an external device through RS485.
  • Recommended Modbus Master: QModbus
  • http://qmodbus.sourceforge.net/
    */

#include <ModbusRtu.h>

// assign the Arduino pin that must be connected to RE-DE RS485 transceiver
#define TXEN 4

const byte SwitchPin = 4;

// data array for modbus network sharing
uint16_t au16data_false[16] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0,0 };
uint16_t au16data_true[16] = {
1, 1, 1, 1, 1, 1, 1,1,1,1,1,1,1,1,1,1 };

/**

  • Modbus object declaration
  • u8id : node id = 0 for master, = 1..247 for slave
  • port : serial port
  • u8txenpin : 0 for RS-232 and USB-FTDI
  •           or any pin number > 1 for RS-485
    

*/
Modbus slave(4,Serial,TXEN); // this is slave @1 and RS-485

void setup() {
pinMode(SwitchPin, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin( 9600 ); // baud-rate at 9600
slave.start();
}

void loop() {
if(digitalRead(SwitchPin)){
slave.poll(au16data_true, 16 );
digitalWrite(LED_BUILTIN,LOW);

} else
{
slave.poll(au16data_false, 16 );
digitalWrite(LED_BUILTIN,HIGH);
}
} `
i am getting this as error
fatal error: ModbusRtu.h: No such file or directory
#include <ModbusRtu.h>
^~~~~
compilation terminated.
exit status 1

Compilation error: ModbusRtu.h: No such file or directory

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

Where did you get the code from ?

There are a number of ModbusRTU libraries available in the IDE Library Manager but it will be importtant to install the correct version

i will follow the proper guidelines to post code and questions next time .
it was written by my senior .
earlier when we use to dump this code it was working but now it is not working .
it is just simple code for push button .
i am new to arduino so please help.
thanks in advance

What do you me by this ? In what sense did you "dump" the code ? Do you mean that you uploaded it to the Arduino and, if so, are you using the same PC as you used to ?

I'm getting the same error, it seems to be a basic mistake, but can anyone help with basic anwer on adding ModbusRtu.h library? I could't find this library.... Thanks!

Where did you look for the library ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.