Reading data from LG5310 energy meter using modbus protocols

I am stuck with reading data from my energy meter for about a month. I have tried many things/programs. But still cannot read data till now. I seek your help.
Thank you.

By the way, I am using Arduino mega 2650. and trying to read ELmeasure meter(LG5310).
From Modbus tester software I am getting results successfully.

Kindly check my code here,

#include <ModbusMaster.h>


#define MAX485_DE      3
#define MAX485_RE_NEG  2

// instantiate ModbusMaster object
ModbusMaster node;

void preTransmission()
{
  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);
  // Init in receive mode

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

  // Modbus communication runs at 9600 baud
  Serial.begin(9600);
Serial1.begin(9600,SERIAL_8N1);
  // Modbus slave ID 1
  node.begin(1, Serial1);
  // Callbacks allow us to configure the RS485 transceiver correctly
  node.preTransmission(preTransmission);
  node.postTransmission(postTransmission);
}

void loop()
{
  float result;

  result = node.readInputRegisters(40156, 2);
  if (result == node.ku8MBSuccess)
  {

    
    Serial.println(node.getResponseBuffer(0x01));

   
    Serial.println(node.getResponseBuffer(0x02));
    
    
  }
  delay(1000);
}

Now im trying to read holding registers value in arduino and display it in serial monitor but in serial monitor the output is always zero.

kINDLY DO THE NEEDFUL

Try a different register. Your test software (oddly) doesn't appear to show any data for even numbered registers.

I'm going from memory here, but @pylon will probably have a better answer than me .... :grinning:

When you see address 40156 the actual address you want to put in the function call is either 155 or 157 (sorry, can't recall if you add 1 or subtract 1!).

use 40156-40001 = 155,
then read two bytes.

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