mandulaj / PZEM-004T-v30

Arduino library for the Updated PZEM-004T v3.0 Power and Energy meter
MIT License
256 stars 108 forks source link

Example code using TTGO TCALL ESP32? #97

Open mandulaj opened 1 year ago

mandulaj commented 1 year ago
    Good day, do you have an example code for pzem004t using ttgo tcall esp32?

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:

@123salee https://github.com/123salee could you please be a bit more specific? Is this related to this issue? Do you want example code? Do you have a problem?

— Reply to this email directly, view it on GitHub https://github.com/mandulaj/PZEM-004T-v30/issues/47#issuecomment-1313981643, or unsubscribe https://github.com/notifications/unsubscribe-auth/A4FXZDA3MT2TDYIVOK4S7K3WIJOYBANCNFSM4WXK54EA . You are receiving this because you were mentioned.Message ID: @.***>

Originally posted by @margohaux in https://github.com/mandulaj/PZEM-004T-v30/issues/47#issuecomment-1314571440

margohaux commented 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.

include

include

include

include

LiquidCrystal_I2C lcd(0x27, 16, 2);

if defined(ESP32)

PZEM004Tv30 pzem(Serial1, TX, RX);

else

PZEM004Tv30 pzem(Serial1);

endif

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 .