Communication Modbus and Arduino

Hi Everyone, I am trying to read holding register of a electromagnetic flowmeter Proline Promag P 300 via RS485 using Modbus RTU but unable to do. I am new to Arduino and getting so much confused by different library e.g. ModbusMaster.h and SimpleModbusMaster.h etc.

I am using RS-485 toTTL to module and also have 1 arduino mega.
This is register addres:


For more information use this link about Promag 300:

My code:

#include <ModbusMaster.h>
#include <SoftwareSerial.h>

SoftwareSerial mySerial(5, 3); // RX, TX
ModbusMaster node;

void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);
  node.begin(1, mySerial);
}

void loop() {
  uint8_t result;
  uint16_t data;

  result = node.readHoldingRegisters(5050, 1);
  if (result == node.ku8MBSuccess) {
    data = node.getResponseBuffer(0);
    Serial.print("Register 5051 value: ");
    Serial.println(data);
  } else {
    Serial.println("Error reading from register 5051.");
  }

  delay(1000);
}

and module what i use:


Please help me out and thanks in advance.

And please let me know if any other information I need to provide.

And what is result of calling your code? Do you see any output in the console?

this is result in console
image

use the debug function, printing the read value in HEX:

Ex:
After the line:
result = node.readHoldingRegisters(5050, 1);
use:
Serial.println(result,HEX);

And say what you printed.

1 Like

Did you change the parameters, address defaults to 247, baud defaults to 19,200??
per your pdf anyways..

good luck.. ~q

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