I have been trying to interface Schneider EM6433H meter with ESP32 in Arduino IDE using ModbusMaster library.
I'm trying to read current & power consumption of a phase. But I'm getting all the readings as 0. Even if i directly tried printing the output of the registers, still output is 0. I'm reading the data from holding registers.
I can see the value of current & watt on the display of the meter, also it works fine in Modscan software.
The setting of the meter are as follows:
Parity : Even Baud rate: 19200 Stop bit: 1 Register: Holding register Meter setup: Single phase with neutral
Please see due to number of character constraints I'm not able to post the entire library here. so attaching the link for the same along with the changes I have done.
I have attached the header files in the code which I'm using currently( I have modified them as per my needs).
The getBufferRespose I changed back to 8bit because the address itself is 8bit format.
As of now I'm using the addresses given in the excel sheet shared by Schneider. I also try converting the address into HEX, but same result
The circuit works fine, I have tested it with other RS-485 meter.
I'm not getting the readings of the current or power, getting only 0, as an output of any register.
https://github.com/4-20ma/ModbusMaster this is the library I'm using, with the following changes
- line 191 (ModbusMaster.h) uint16_t getResponseBuffer(uint16_t);
- line 223 (ModbusMaster.h) static const uint16_t ku8MaxBufferSize = 4086; ///< size of response/transmit buffers
- line 228 ( ModbusMaster.cpp ) uint16_t ModbusMaster::getResponseBuffer(uint16_t u8Index)
Pasting the output here
15974
21103
ovf
15974
21103
65472
0
65472
0
......
15975
12294
0.00
15975
12294
65472
0
65472
0
Attaching code for your reference.
#include <ModbusMaster.h>
/*!
We're using a MAX485-compatible RS485 Transceiver.
Rx/Tx is hooked up to the hardware serial port at 'Serial'.
The Data Enable and Receiver Enable pins are hooked up as follows:
*/
#define MAX485_DE 2
#define MAX485_RE_NEG 4
// 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);
}
float V1,V2,V3;
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 115200 baud
Serial2.begin(9600, SERIAL_8E1); //Even parity & 1 stop bit baud rate 19200
Serial.begin (115200);
// Modbus slave ID 1
node.begin(1, Serial2);
// Callbacks allow us to configure the RS485 transceiver correctly
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
bool state = true;
void loop()
{
uint8_t result1,result2,result3;
uint16_t data1[6],data2[6],data3[6], data4[6];
// Read 16 registers starting at 0x3100)
/*
result1 = node.readHoldingRegisters(0xA8C,2);
delay(100);
if (result1 == node.ku8MBSuccess){
Serial.println(node.getResponseBuffer(0xA8C));
Serial.println(node.getResponseBuffer(0xA8D));
}*/
result1 = node.readHoldingRegisters(0x0BB7,10);
if (result1 == node.ku8MBSuccess){
data1[0] = node.getResponseBuffer(0x0);
data1[1] = node.getResponseBuffer(0x1);
Serial.println( data1[0]);
Serial.println( data1[1]);
float I2 = *((float *)data1);
Serial.println( I2 );
Serial.println( node.getResponseBuffer(0x0) );
Serial.println( node.getResponseBuffer(0x1) );
Serial.println( node.getResponseBuffer(0x2) );
Serial.println( node.getResponseBuffer(0x3) );
Serial.println( node.getResponseBuffer(0x4) );
Serial.println( node.getResponseBuffer(0x5) );
}
Serial.println( "......" );
delay(1000);
}