Open mandulaj opened 1 year ago
### I had been connecting pzem to TTGO ESP32. but the issue was my serial monitor can't read the reading even though I successfully upload my file. They just display the unit but when I turn on main supply and load, they did not detect the value.. Hopefully someone can help me to figure out this issue.
LiquidCrystal_I2C lcd(0x27, 16, 2);
PZEM004Tv30 pzem(Serial1, TX, RX);
PZEM004Tv30 pzem(Serial1);
void setup() { / Debugging serial / Serial.begin(9600); lcd.init(); lcd.backlight(); lcd.setCursor(0, 0); lcd.setCursor(0, 1); lcd.print("ENERGY METER"); delay(500); lcd.clear();
}
void loop() {
float voltage = pzem.voltage();
if(voltage != NAN){
Serial.print("Voltage: ");
Serial.print(voltage);
Serial.println("V");
lcd.setCursor(0,0);
lcd.print("V:");
lcd.print("VOLTAGE");
}else{
Serial.println("Error reading voltage");
}
float current = pzem.current();
if (current != NAN){
Serial.print("Current: ");
Serial.print(current);
Serial.println("A");
lcd.setCursor(0,1);
lcd.print("I:");
lcd.print("CURRENT");
}else{
Serial.println("Error reading current");
}
float power = pzem.power();
if (power != NAN) {
Serial.print("Power: ");
Serial.print(power);
Serial.println("W");
lcd.setCursor(8,0);
lcd.print("P:");
lcd.print("POWER");
}else{
Serial.println("Error reading power");
}
float energy = pzem.energy();
if (energy != NAN) {
Serial.print("Energy: ");
Serial.print(energy,3);
Serial.println("kWh");
}else{
Serial.println("Error reading energy");
}
float frequency = pzem.frequency();
if (frequency != NAN) {
Serial.print("Frequency: ");
Serial.print(frequency, 1);
Serial.println("Hz");
lcd.setCursor(8,1);
lcd.print("F:");
lcd.print("FREQUENCY");
}else{
Serial.println("Error reading frequency");
}
float pf = pzem.pf();
if (pf != NAN) {
Serial.print("PF: ");Serial.println(pf);
lcd.setCursor(0,3);
lcd.print("PF:");
lcd.print("pf");
}else{
Serial.println("Error reading power factor");
}
Serial.println();
delay(2000);
}
SERIAL MONITOR: Energy:
Voltage: nanV Current: nanA Power: nanW Energy: nankWh Frequency: nanHz PF: nan .
I have tried your code for hardserial but i think it is not for ttgo.thanks
On Tue, Nov 15, 2022 at 12:00 AM Jakub Mandula @.***> wrote:
Originally posted by @margohaux in https://github.com/mandulaj/PZEM-004T-v30/issues/47#issuecomment-1314571440