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

ESP32 Serial2 + 14 PZEM-004T Sensor Module #92

Open
MFayH opened this issue Aug 9, 2022 · 24 comments
Open

ESP32 Serial2 + 14 PZEM-004T Sensor Module #92

MFayH opened this issue Aug 9, 2022 · 24 comments

Comments

@MFayH
Copy link

MFayH commented Aug 9, 2022

Hi everyone. I try to read 14 PZEM-004T Sensor Module with single serial port (Serial2, RX16, TX17). But it like there is a limit for connections. just can communicate 5 sensors module randomly from 14 sensors. So if I connect the 6th sensor, the respon in serial monitor is "Sensor Error Measuring". There is any limitation of connection in Serial port? Any solution for it? Thank you before

There is my program (long, but similar, just different variables and sensor address)

`
#include <PZEM004Tv30.h>
#include <WiFi.h>
#include <HTTPClient.h>

HTTPClient http;

#define PZEM_RX_PIN 16
#define PZEM_TX_PIN 17
#define PZEM_SERIAL Serial2
#define NUM_PZEMS 13

PZEM004Tv30 pzems[NUM_PZEMS];

const char WIFI_SSID[] = "OPPO Reno6 Pro 5G";
const char WIFI_PASSWORD[] = "34567890";

void setup() {
Serial.begin(9600);
//
// For each PZEM, initialize it
for(int i = 0; i < NUM_PZEMS; i++) {
pzems[i] = PZEM004Tv30(PZEM_SERIAL, PZEM_RX_PIN, PZEM_TX_PIN, 0x01 + i);
}
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.println("Connecting");
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected WiFi with IP Address: ");
Serial.println(WiFi.localIP());
}

float calib = 3.5;

float vGVDMain, cGVDMain, pGVDMain, eGVDMain, fGVDMain, pfGVDMain;
float vGVDClean, cGVDClean, pGVDClean, eGVDClean, fGVDClean, pfGVDClean;
float vRVD901, vSVD901, vTVD901, cRVD901, cSVD901, cTVD901, pRVD901, pSVD901, pTVD901, eRVD901, eSVD901, eTVD901, fRVD901, fSVD901, fTVD901, pfRVD901, pfSVD901, pfTVD901;
float vRVD301, vSVD301, vTVD301, cRVD301, cSVD301, cTVD301, pRVD301, pSVD301, pTVD301, eRVD301, eSVD301, eTVD301, fRVD301, fSVD301, fTVD301, pfRVD301, pfSVD301, pfTVD301;
float vRPRC, vSPRC, vTPRC, cRPRC, cSPRC, cTPRC, pRPRC, pSPRC, pTPRC, eRPRC, eSPRC, eTPRC, fRPRC, fSPRC, fTPRC, pfRPRC, pfSPRC, pfTPRC;
float vRPMB, vSPMB, vTPMB, cRPMB, cSPMB, cTPMB, pRPMB, pSPMB, pTPMB, eRPMB, eSPMB, eTPMB, fRPMB, fSPMB, fTPMB, pfRPMB, pfSPMB, pfTPMB;

void VD901() {
Serial.print("VD901");
Serial.print(" - Address : ");
Serial.println(pzems[0].getAddress(), DEC);
Serial.println("===================");

vRVD901 = pzems[0].voltage()+calib; vSVD901 = pzems[1].voltage()+calib; vTVD901 = pzems[2].voltage()+calib;
cRVD901 = pzems[0].current(); cSVD901 = pzems[1].current(); cTVD901 = pzems[2].current();
pRVD901 = pzems[0].power(); pSVD901 = pzems[1].power(); pTVD901 = pzems[2].power();
eRVD901 = pzems[0].energy(); eSVD901 = pzems[1].energy(); eTVD901 = pzems[2].energy();
fRVD901 = pzems[0].frequency(); fSVD901 = pzems[1].frequency(); fTVD901 = pzems[2].frequency();
pfRVD901 = pzems[0].pf(); pfSVD901 = pzems[1].pf(); pfTVD901 = pzems[2].pf();

if(isnan(vRVD901)){
Serial.println("Sensor Error Measuring");
} else {
Serial.print("Voltage R : "+String(vRVD901)+"V");
Serial.print("Current R : "+String(cRVD901)+"A");
Serial.print("Power R : "+String(pRVD901)+"W");
Serial.print("Energy R : "+String(eRVD901, 3)+"kWh");
Serial.print("Freq R : "+String(fRVD901, 1)+"Hz");
Serial.println("PF R : "+String(pfRVD901));
}

if(isnan(vSVD901)){
Serial.println("Sensor Error Measuring");
} else {
Serial.print("Voltage S : "+String(vSVD901)+"V");
Serial.print("Current S : "+String(cSVD901)+"A");
Serial.print("Power S : "+String(pSVD901)+"W");
Serial.print("Energy S : "+String(eSVD901, 3)+"kWh");
Serial.print("Freq S : "+String(fSVD901, 1)+"Hz");
Serial.println("PF S : "+String(pfSVD901));
}

if(isnan(vTVD901)){
  Serial.println("Sensor Error Measuring");
} else {
  Serial.print("Voltage T : "+String(vTVD901)+"V");
  Serial.print("Current T : "+String(cTVD901)+"A");
  Serial.print("Power T   : "+String(pTVD901)+"W");
  Serial.print("Energy T  : "+String(eTVD901, 3)+"kWh");
  Serial.print("Freq T    : "+String(fTVD901, 1)+"Hz");
  Serial.println("PF T    : "+String(pfTVD901));
}

Serial.println("-------------------");
Serial.println();

http.begin("http://192.168.227.118/moniHLT/VD901.php?vR="+String(vRVD901)+"&cR="+String(cRVD901)+"&pR="+String(pRVD901)+"&eR="+String(eRVD901)+"&fR="+String(fRVD901)+"&pfR="+String(pfRVD901)+"&vS="+String(vSVD901)+"&cS="+String(cSVD901)+"&pS="+String(pSVD901)+"&eS="+String(eSVD901)+"&fS="+String(fSVD901)+"&pfS="+String(pfSVD901)+"&vT="+String(vTVD901)+"&cT="+String(cTVD901)+"&pT="+String(pTVD901)+"&eT="+String(eTVD901)+"&fT="+String(fTVD901)+"&pfT="+String(pfTVD901));
int httpCode = http.GET();

if(httpCode > 0) {
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
} else {
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}

http.end();
}

void VD301() {
Serial.print("VD301");
Serial.print(" - Address : ");
Serial.println(pzems[3].getAddress(), DEC);
Serial.println("===================");

vRVD301 = pzems[3].voltage()+calib; vSVD301 = pzems[4].voltage()+calib; vTVD301 = pzems[5].voltage()+calib;
cRVD301 = pzems[3].current(); cSVD301 = pzems[4].current(); cTVD301 = pzems[5].current();
pRVD301 = pzems[3].power(); pSVD301 = pzems[4].power(); pTVD301 = pzems[5].power();
eRVD301 = pzems[3].energy(); eSVD301 = pzems[4].energy(); eTVD301 = pzems[5].energy();
fRVD301 = pzems[3].frequency(); fSVD301 = pzems[4].frequency(); fTVD301 = pzems[5].frequency();
pfRVD301 = pzems[3].pf(); pfSVD301 = pzems[4].pf(); pfTVD301 = pzems[5].pf();

if(isnan(vRVD301)){
Serial.println("Sensor Error Measuring");
} else {
Serial.print("Voltage R : "+String(vRVD301)+"V");
Serial.print("Current R : "+String(cRVD301)+"A");
Serial.print("Power R : "+String(pRVD301)+"W");
Serial.print("Energy R : "+String(eRVD301, 3)+"kWh");
Serial.print("Freq R : "+String(fRVD301, 1)+"Hz");
Serial.println("PF R : "+String(pfRVD301));
}

if(isnan(vSVD301)){
Serial.println("Sensor Error Measuring");
} else {
Serial.print("Voltage S : "+String(vSVD301)+"V");
Serial.print("Current S : "+String(cSVD301)+"A");
Serial.print("Power S : "+String(pSVD301)+"W");
Serial.print("Energy S : "+String(eSVD301, 3)+"kWh");
Serial.print("Freq S : "+String(fSVD301, 1)+"Hz");
Serial.println("PF S : "+String(pfSVD301));
}

if(isnan(vTVD301)){
  Serial.println("Sensor Error Measuring");
} else {
  Serial.print("Voltage T : "+String(vTVD301)+"V");
  Serial.print("Current T : "+String(cTVD301)+"A");
  Serial.print("Power T   : "+String(pTVD301)+"W");
  Serial.print("Energy T  : "+String(eTVD301, 3)+"kWh");
  Serial.print("Freq T    : "+String(fTVD301, 1)+"Hz");
  Serial.println("PF T    : "+String(pfTVD301));
}

Serial.println("-------------------");
Serial.println();

http.begin("http://192.168.110.118/moniHLT/VD301.php?vR="+String(vRVD301)+"&cR="+String(cRVD301)+"&pR="+String(pRVD301)+"&eR="+String(eRVD301)+"&fR="+String(fRVD301)+"&pfR="+String(pfRVD301)+"&vS="+String(vSVD301)+"&cS="+String(cSVD301)+"&pS="+String(pSVD301)+"&eS="+String(eSVD301)+"&fS="+String(fSVD301)+"&pfS="+String(pfSVD301)+"&vT="+String(vTVD301)+"&cT="+String(cTVD301)+"&pT="+String(pTVD301)+"&eT="+String(eTVD301)+"&fT="+String(fTVD301)+"&pfT="+String(pfTVD301));
int httpCode = http.GET();

if(httpCode > 0) {
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
} else {
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}

http.end();
}

void PRC003A() {
Serial.print("PRC-003A");
Serial.print(" - Address : ");
Serial.println(pzems[6].getAddress(), DEC);
Serial.println("===================");

vRPRC = pzems[6].voltage()+calib; vSPRC = pzems[7].voltage()+calib; vTPRC = pzems[8].voltage()+calib;
cRPRC = pzems[6].current(); cSPRC = pzems[7].current(); cTPRC = pzems[8].current();
pRPRC = pzems[6].power(); pSPRC = pzems[7].power(); pTPRC = pzems[8].power();
eRPRC = pzems[6].energy(); eSPRC = pzems[7].energy(); eTPRC = pzems[8].energy();
fRPRC = pzems[6].frequency(); fSPRC = pzems[7].frequency(); fTPRC = pzems[8].frequency();
pfRPRC = pzems[6].pf(); pfSPRC = pzems[7].pf(); pfTPRC = pzems[8].pf();

if(isnan(vRPRC)){
Serial.println("Sensor Error Measuring");
} else {
Serial.print("Voltage R : "+String(vRPRC)+"V");
Serial.print("Current R : "+String(cRPRC)+"A");
Serial.print("Power R : "+String(pRPRC)+"W");
Serial.print("Energy R : "+String(eRPRC, 3)+"kWh");
Serial.print("Freq R : "+String(fRPRC, 1)+"Hz");
Serial.println("PF R : "+String(pfRPRC));
}

if(isnan(vSPRC)){
Serial.println("Sensor Error Measuring");
} else {
Serial.print("Voltage S : "+String(vSPRC)+"V");
Serial.print("Current S : "+String(cSPRC)+"A");
Serial.print("Power S : "+String(pSPRC)+"W");
Serial.print("Energy S : "+String(eSPRC, 3)+"kWh");
Serial.print("Freq S : "+String(fSPRC, 1)+"Hz");
Serial.println("PF S : "+String(pfSPRC));
}

if(isnan(vTPRC)){
  Serial.println("Sensor Error Measuring");
} else {
  Serial.print("Voltage T : "+String(vTPRC)+"V");
  Serial.print("Current T : "+String(cTPRC)+"A");
  Serial.print("Power T   : "+String(pTPRC)+"W");
  Serial.print("Energy T  : "+String(eTPRC, 3)+"kWh");
  Serial.print("Freq T    : "+String(fTPRC, 1)+"Hz");
  Serial.println("PF T    : "+String(pfTPRC));
}

Serial.println("-------------------");
Serial.println();

http.begin("http://192.168.110.118/moniHLT/PRC.php?vR="+String(vRPRC)+"&cR="+String(cRPRC)+"&pR="+String(pRPRC)+"&eR="+String(eRPRC)+"&fR="+String(fRPRC)+"&pfR="+String(pfRPRC)+"&vS="+String(vSPRC)+"&cS="+String(cSPRC)+"&pS="+String(pSPRC)+"&eS="+String(eSPRC)+"&fS="+String(fSPRC)+"&pfS="+String(pfSPRC)+"&vT="+String(vTPRC)+"&cT="+String(cTPRC)+"&pT="+String(pTPRC)+"&eT="+String(eTPRC)+"&fT="+String(fTPRC)+"&pfT="+String(pfTPRC));
int httpCode = http.GET();

if(httpCode > 0) {
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
} else {
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}

http.end();
}

void PMB001C() {
Serial.print("PMB-001C");
Serial.print(" - Address : ");
Serial.println(pzems[9].getAddress(), DEC);
Serial.println("===================");

vRPMB = pzems[9].voltage()+calib; vSPMB = pzems[10].voltage()+calib; vTPMB = pzems[11].voltage()+calib;
cRPMB = pzems[9].current(); cSPMB = pzems[10].current(); cTPMB = pzems[11].current();
pRPMB = pzems[9].power(); pSPMB = pzems[10].power(); pTPMB = pzems[11].power();
eRPMB = pzems[9].energy(); eSPMB = pzems[10].energy(); eTPMB = pzems[11].energy();
fRPMB = pzems[9].frequency(); fSPMB = pzems[10].frequency(); fTPMB = pzems[11].frequency();
pfRPMB = pzems[9].pf(); pfSPMB = pzems[10].pf(); pfTPMB = pzems[11].pf();

if(isnan(vRPMB)){
Serial.println("Sensor Error Measuring");
} else {
Serial.print("Voltage R : "+String(vRPMB)+"V");
Serial.print("Current R : "+String(cRPMB)+"A");
Serial.print("Power R : "+String(pRPMB)+"W");
Serial.print("Energy R : "+String(eRPMB, 3)+"kWh");
Serial.print("Freq R : "+String(fRPMB, 1)+"Hz");
Serial.println("PF R : "+String(pfRPMB));
}

if(isnan(vSPMB)){
Serial.println("Sensor Error Measuring");
} else {
Serial.print("Voltage S : "+String(vSPMB)+"V");
Serial.print("Current S : "+String(cSPMB)+"A");
Serial.print("Power S : "+String(pSPMB)+"W");
Serial.print("Energy S : "+String(eSPMB, 3)+"kWh");
Serial.print("Freq S : "+String(fSPMB, 1)+"Hz");
Serial.println("PF S : "+String(pfSPMB));
}

if(isnan(vTPMB)){
  Serial.println("Sensor Error Measuring");
} else {
  Serial.print("Voltage T : "+String(vTPMB)+"V");
  Serial.print("Current T : "+String(cTPMB)+"A");
  Serial.print("Power T   : "+String(pTPMB)+"W");
  Serial.print("Energy T  : "+String(eTPMB, 3)+"kWh");
  Serial.print("Freq T    : "+String(fTPMB, 1)+"Hz");
  Serial.println("PF T    : "+String(pfTPMB));
}

Serial.println("-------------------");
Serial.println();

http.begin("http://192.168.110.118/moniHLT/PMB.php?vR="+String(vRPMB)+"&cR="+String(cRPMB)+"&pR="+String(pRPMB)+"&eR="+String(eRPMB)+"&fR="+String(fRPMB)+"&pfR="+String(pfRPMB)+"&vS="+String(vSPMB)+"&cS="+String(cSPMB)+"&pS="+String(pSPMB)+"&eS="+String(eSPMB)+"&fS="+String(fSPMB)+"&pfS="+String(pfSPMB)+"&vT="+String(vTPMB)+"&cT="+String(cTPMB)+"&pT="+String(pTPMB)+"&eT="+String(eTPMB)+"&fT="+String(fTPMB)+"&pfT="+String(pfTPMB));
int httpCode = http.GET();

if(httpCode > 0) {
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
} else {
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}

http.end();
}

void GVDMain() {
Serial.print("GVD Main Vacuum");
Serial.print(" - Address : ");
Serial.println(pzems[12].getAddress(), DEC);
Serial.println("===================");

vGVDMain = pzems[12].voltage()+calib;
cGVDMain = pzems[12].current();
pGVDMain = pzems[12].power();
eGVDMain = pzems[12].energy();
fGVDMain = pzems[12].frequency();
pfGVDMain = pzems[12].pf();

if(isnan(vGVDMain)){
Serial.println("Sensor Error Measuring");
} else {
Serial.print("Voltage: "+String(vGVDMain)+"V");
Serial.print("Current: "+String(cGVDMain)+"A");
Serial.print("Power : "+String(pGVDMain)+"W");
Serial.print("Energy : "+String(eGVDMain, 3)+"kWh");
Serial.print("Freq : "+String(fGVDMain, 1)+"Hz");
Serial.print("PF : "+String(pfGVDMain));
}

Serial.println("-------------------");
Serial.println();

http.begin("http://192.168.110.118/moniHLT/GVDMain.php?vR="+String(vGVDMain)+"&cR="+String(cGVDMain)+"&pR="+String(pGVDMain)+"&eR="+String(eGVDMain)+"&fR="+String(fGVDMain)+"&pfR="+String(pfGVDMain)); //HTTP
int httpCode = http.GET();

if(httpCode > 0) {
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
} else {
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}

http.end();
}

void GVDClean() {
Serial.print("GVD Clean Vacuum");
Serial.print(" - Address : ");
Serial.println(pzems[13].getAddress(), DEC);
Serial.println("===================");

vGVDClean = pzems[13].voltage()+calib;
cGVDClean = pzems[13].current();
pGVDClean = pzems[13].power();
eGVDClean = pzems[13].energy();
fGVDClean = pzems[13].frequency();
pfGVDClean = pzems[13].pf();

if(isnan(vGVDClean)){
Serial.println("Sensor Error Measuring");
} else {
Serial.print("Voltage: "+String(vGVDClean)+"V");
Serial.print("Current: "+String(cGVDClean)+"A");
Serial.print("Power : "+String(pGVDClean)+"W");
Serial.print("Energy : "+String(eGVDClean, 3)+"kWh");
Serial.print("Freq : "+String(fGVDClean, 1)+"Hz");
Serial.print("PF : "+String(pfGVDClean));
}

Serial.println("-------------------");
Serial.println();

http.begin("http://192.168.110.118/moniHLT/GVDClean.php?vR="+String(vGVDClean)+"&cR="+String(cGVDClean)+"&pR="+String(pGVDClean)+"&eR="+String(eGVDClean)+"&fR="+String(fGVDClean)+"&pfR="+String(pfGVDClean)); //HTTP
int httpCode = http.GET();

if(httpCode > 0) {
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
} else {
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}

http.end();
}

void loop() {
VD901();
delay(2000);
VD301();
delay(2000);
PRC003A();
delay(2000);
PMB001C();
delay(2000);
GVDMain();
// delay(2000);
// GVDClean();

Serial.println();
delay(5000);
}
`

@vortigont
Copy link
Contributor

Check LINKS section for additional information. ESP's gpio pin can't drive many opto's in parallel due to current limitation. You need HW MOD something like this. Or if you do not like modding many pzems it could be better to use external bipolar transistors of FETs to drive serial line (i.e. like here ) If you use esp32 than you might wanna check async event-driven library for communicating with multiple pzem devs.

@MFayH
Copy link
Author

MFayH commented Aug 9, 2022

Thank Vortigont for your comment, it's not possible for me to mod the R8 into 300-500k ohm, so the possibility is to remove the R4 yeah? So I removing 13 of 14 PZEM R4's right?

@MFayH
Copy link
Author

MFayH commented Aug 9, 2022

Or I use all 3 serial ports of ESP. So each port connect to 5 PZEMs. It's tolerated? Sorry for my messy type

@vortigont
Copy link
Contributor

R8 and R4 pulls different lines - rx and tx. You can't tune one and omit the other. It might be OK to pull more than 5 devices with only removing R4, but I'm not sure for how many. You can experiment.
I think it would be better (and safe) to use some FET level-shifter as a buffer. You can find lot's of those on aliexpress.

@vortigont
Copy link
Contributor

Or I use all 3 serial ports of ESP. So each port connect to 5 PZEMs. It's tolerated?

possible, but it may be unstable. Too close to the edge :)

@MFayH
Copy link
Author

MFayH commented Aug 10, 2022

Is there any problem if I connect the L-N of PZEM with 2 of 3 phase wire (RST)? The actual is

  1. PZEM 1 -> R-S
  2. PZEM 2 -> S-T
  3. PZEM 3 -> R-T

@MFayH
Copy link
Author

MFayH commented Aug 10, 2022

Because while I protoyping with 14 PZEM Sensor, the connection of L-N of PZEM is R-N (neutral), and there is no problem with serial connection

@MFayH
Copy link
Author

MFayH commented Aug 10, 2022

image

Red highlight happened if I connect the 6th PZEM, the program just read the last.

image

This is the wiring

@vortigont
Copy link
Contributor

@MFayH quite a nice setup :)
Sorry, but I did not get what is "RTS"?
You also have some read errors even before connecting 6th device. Try using bipolar transitor for buffering, would be much safer this way.

@MFayH
Copy link
Author

MFayH commented Aug 10, 2022

RST I mean Phase 1 phase 2 and phase 3 I'm sorry for that :).
The buffer is for just RX? Or both?

@MFayH
Copy link
Author

MFayH commented Aug 10, 2022

Can you give example circuit for the transistor? It's very helpful

@vortigont
Copy link
Contributor

For TX (from ESP) it's just simple emitter-follower
image, any typical low-voltage pnp will do I suppose.

For TX (from PZEMs) it won't work since each PZEM has it's own optocoupler that should pull the line for all paralleled devices, so you have to remove R4's. Might even need to remove R9's for such a lot of devices. R9 is sinking current through TX LED.

@vortigont
Copy link
Contributor

@MFayH you may also find this scheme quite handy to check on

@vortigont
Copy link
Contributor

Is there any problem if I connect the L-N of PZEM with 2 of 3 phase wire (RST)? The actual is

1. PZEM 1 -> R-S

2. PZEM 2 -> S-T

3. PZEM 3 -> R-T

Now I got your point. You mean feed PZEM with phase-to-phase wires. That's a good question actually. I see this issues for such a setup

  • interphase voltage is 380 V, polycap (yellow one) that works as power source for PZEM migth not be rated for this. Need to check.
  • need to check specs for the sensor chip and Vsens divider if it's capable to measure >380V
  • I really doubt how it will integrate power/energy values for phase-to-phase current. Expect it to produce some strange results.

Pls, keep us posted if u dare to try this setup. I'm really interested with the outcome :)

@Nismonx
Copy link

Nismonx commented Aug 11, 2022

Is there any problem if I connect the L-N of PZEM with 2 of 3 phase wire (RST)? The actual is

  1. PZEM 1 -> R-S
  2. PZEM 2 -> S-T
  3. PZEM 3 -> R-T

The pzem is designed to work at 120vac or 240vac, Phase and Neutral. In other words:
L1 to N
L2 to N
L3 to N

In your case you are running of an RST transformer without the Neutral, effectively a Delta system.

Even if your nominal voltage is below 240vac for example
L1 to L2 = 240vac
Or
R to S = 240vac

I doubt you'll getting anything out of it.

But like @vortigont mentioned, it would be interesting to see what you get out of it.

Just be safe and ask an electrician if you are uncertain.

Good luck 👍

@MFayH
Copy link
Author

MFayH commented Aug 12, 2022

Yes you all @vortigont @Nismonx got my point about phase-to-phase connection that I have installed. I think isn't affected to the PZEM because the voltage is in range 80~260V AC. but I'll try to connect again with Phase-to-Neutral as my protoyping before.
So, for the solution I'll try this step.

  1. Program trial-error like How to enable multiple slave in an same Serial Interface ? #40 issue.
  2. Change phase-to-phase -> phase-to-neutral.
  3. Separate PZEM connection by 5 per group, and to switching I'll use relay changeover.

Appreciate to you all for excited to this issue. Thanks

@MFayH
Copy link
Author

MFayH commented Aug 12, 2022

And when I try to call all of my PZEM (void) this is happen

Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
14:01:14.296 ->
14:01:14.296 -> Core 1 register dump:
14:01:14.296 -> PC : 0x400d2fec PS : 0x00060f30 A0 : 0x800d3071 A1 : 0x3ffb26d0
14:01:14.296 -> A2 : 0x3ffc32b8 A3 : 0x3ffc3828 A4 : 0x00000000 A5 : 0x0000000a
14:01:14.296 -> A6 : 0x00000000 A7 : 0x00000000 A8 : 0x800d2fe8 A9 : 0x3ffb26b0
14:01:14.343 -> A10 : 0x00000000 A11 : 0x3ffb26e3 A12 : 0x00000008 A13 : 0x0000d880
14:01:14.343 -> A14 : 0x00ff0000 A15 : 0xff000000 SAR : 0x0000000a EXCCAUSE: 0x0000001c
14:01:14.343 -> EXCVADDR: 0x00000000 LBEG : 0x400844ed LEND : 0x400844f5 LCOUNT : 0x00000027
14:01:14.343 ->
14:01:14.343 ->
14:01:14.343 -> Backtrace:0x400d2fe9:0x3ffb26d00x400d306e:0x3ffb2710 0x400d31e5:0x3ffb2730 0x400d27ae:0x3ffb2750 0x400d2c93:0x3ffb2800 0x400d950d:0x3ffb2820
14:01:14.343 ->
14:01:14.343 ->
14:01:14.343 ->
14:01:14.343 ->
14:01:14.343 -> ELF file SHA256: 0000000000000000
14:01:14.343 ->
14:01:14.343 -> Rebooting...
14:01:14.343 -> ets Jun 8 2016 00:22:57
14:01:14.390 ->
14:01:14.390 -> rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
14:01:14.390 -> configsip: 0, SPIWP:0xee
14:01:14.390 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
14:01:14.390 -> mode:DIO, clock div:1
14:01:14.390 -> load:0x3fff0030,len:1344
14:01:14.390 -> load:0x40078000,len:13864
14:01:14.390 -> load:0x40080400,len:3608
14:01:14.390 -> entry 0x400805f0

But, when I call just 6 PZEM (void) with 5 PZEM connected to ESP32. It's work fine. Any comments?

@MFayH
Copy link
Author

MFayH commented Aug 12, 2022

Is this because network connection code? I use <Wifi.h> and <HTTPClient.h> library to send the data to database.

@vortigont
Copy link
Contributor

What do you mean PZEM (void)? Stacktrace shows some null reference (add 0x00000), try to narrow down when it happens, in setup() or in loop()
Actually creating large number of objects on stack is not a good idea, especially if you need memory on things like HTTClient. Better to create objects dynamically and poll it one by one.
You may check this pool example, but it is another library.

@MFayH
Copy link
Author

MFayH commented Aug 15, 2022

I mean call PZEM read function

What do you mean PZEM (void)? Stacktrace shows some null reference (add 0x00000), try to narrow down when it happens, in setup() or in loop() Actually creating large number of objects on stack is not a good idea, especially if you need memory on things like HTTClient. Better to create objects dynamically and poll it one by one. You may check this pool example, but it is another library.

@MFayH
Copy link
Author

MFayH commented Aug 19, 2022

Update of this issue. I add wiring for changeover relay for separate RX pin of ESP32 to read from sensor 5 by 5 until 13 sensors. 1-10 sensors are working properly, but 11th to 13th sensor said "Sensor Error Measuring". I have flush the serial pin and begin again, but doesn't work. Any suggest?

image

Additional Wiring for Relay Changeover
image

@MFayH
Copy link
Author

MFayH commented Aug 19, 2022

The push button symbol just for simulation. The actual R1 activated by GPIO 18 and R2 activated by GPIO 19 of ESP32

@MFayH
Copy link
Author

MFayH commented Aug 19, 2022

Thank you everyone. Problem has solved.
Countermeasure 👍 :

  1. Additional Relay Changeover 2 Channel for separate sensor TX to RX ESP Connection 5 by 5
  2. Flush Serial ports in every 5 sensors measurement dan begin the serial again

Very pleasure interact with amazing guys like you. Thanks in advance

@nextstationcl
Copy link

Same problem, I only receive two measurements regardless of the directions of each sensor.

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

4 participants