/*
Function readVoltage()
Description: read voltage value from the Finder energy meter holding registers
*/
float readVoltage() {
float volt = 0.;
// Send reading request over RS485
if (!ModbusRTUClient.requestFrom(0x01, HOLDING_REGISTERS, 0x000C, 2)) {
// Error handling
Serial.print("- Failed to read the voltage! ");
Serial.println(ModbusRTUClient.lastError());
} else {
// Response handler
uint16_t word1 = ModbusRTUClient.read(); // Read word1 from buffer
uint16_t word2 = ModbusRTUClient.read(); // Read word2 from buffer
uint32_t millivolt = word1 << 16 | word2; // Join word1 and word2 to retrieve voltage value in millivolts
volt = millivolt/1000.0; // Convert to volts
}
return volt;
}
Can anybody help oh what value "0x000C" should be change to when using this meter, page 9
0x0000 if you want the voltage of L1 to N. You didn't define which voltage you want to read.
But attention: your code expects to read a 32bit Millivolt value but the linked meter returns Decivolt!
It's quite bad style to edit the original post and fill in completely different code than there was while I was writing post #2. Somebody reading the thread won't realize that you there was a completely different code before.
That's because secion 2.1 states that the order is LSW before MSW. So your code is wrong, it should read
uint32_t decivolt = word2 << 16 | word1;
Because the resolution is 0.1kWh. Using that resolution you cannot display a value of 0.86kWh.