Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculation error due to using uint16_t = 65535? 66.5kW = 0.5kW! #199

Open
ilya7zz opened this issue Nov 22, 2024 · 4 comments
Open

Calculation error due to using uint16_t = 65535? 66.5kW = 0.5kW! #199

ilya7zz opened this issue Nov 22, 2024 · 4 comments

Comments

@ilya7zz
Copy link

ilya7zz commented Nov 22, 2024

When the active power (W) and accumulated power (Wh) measurements are exceeded, the buffer overflows.
For example:
65.535 kWh is the limit after which it starts counting from zero.
i.e. 65.537 kWh = 0.001 kWh
6553.5 W is the limit after which it starts counting from zero.
6553.7 W = 0.1 W

bool PR_alarm;
uint8_t result;
float U_PR, I_PR, P_PR, PPR, PR_F, PR_PF; 
void PZEM() {
  result = node.readInputRegisters(0x0000, 10);
  if (result == node.ku8MBSuccess) {
  U_PR = (node.getResponseBuffer(0x00)/10.0f); // Voltage
  I_PR = (node.getResponseBuffer(0x01)/1000.000f); // Current
  P_PR = (node.getResponseBuffer(0x03)/10.0f); // Power
  PPR = (node.getResponseBuffer(0x05)/1000.0f); // Power consumption max:9999.99
  PR_F = (node.getResponseBuffer(0x07)/10.0f); // Frequency 45 – 65 Hz
  PR_PF = (node.getResponseBuffer(0x08)/100.0f); // Power Factor
  PR_alarm = (node.getResponseBuffer(0x09)); // Active power threshold
  sendSerial();
}

void sendSerial() {
  Serial.print("U_PR: " + String(U_PR,1) + " V,  ");
  Serial.print("I_PR: " + String(I_PR,3) + " A,  ");
  Serial.print("P_PR: " + String(P_PR,1) + " W,  ");
  Serial.print("PPR: " + String(PPR,3) + " kW*h,  ");
  Serial.print("PR_F: " + String(PR_F,1) + " Hz,  ");
  Serial.print("PR_PF: " + String(PR_PF) + " cos φ,  ");    // Power factor (cos φ)
  Serial.println("PR_alarm: " + String(PR_alarm,0)); // Active power threshold
}

I really liked this library, I ask you to improve it!
Or please advise me how to fix this error ;)

@ilya7zz
Copy link
Author

ilya7zz commented Nov 22, 2024

Also, there is an error during compilation:

sketch/src/ModbusMaster.cpp: In member function 'uint8_t ModbusMaster::requestFrom(uint16_t, uint16_t)':
sketch/src/ModbusMaster.cpp:94:33: warning: 'read' is used uninitialized in this function [-Wuninitialized]
   _u8ResponseBufferLength = read;
                                 ^

@Fluxanode
Copy link

I'm seeing the same "read" warning and started a new issue. I think this lib is not maintained/updated.

@ilya7zz
Copy link
Author

ilya7zz commented Dec 4, 2024

I also thought that the project was abandoned. That's why I found the PZEM-004T-v30 library and switched to it. It turned out to be more convenient to work with it and the answers are accurate. However, there are errors there too :)
I wrote to the author, I hope for his answer.

@Fluxanode
Copy link

I use it for reading industrial sensors typically flow meters. It works but there are a lot of issues opened and just wonder what happened to the author?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants