Pzem-004t &lcd(I2C)

I have some question is about pzem-004t and lcd.
I can't show the voltage、current... data on the LCD model, I hope someone can teach me how to do it.
Thanks~
this is my program~~
.
.
.
#include <PZEM004Tv30.h>
#include <LiquidCrystal_I2C.h>
PZEM004Tv30 pzem(9, 10);
const uint8_t up_arrow[8] = {0x04, 0x0E, 0x1F, 0x04, 0x04, 0x04, 0x00, 0x00};

LiquidCrystal_I2C lcd(0x27,16,2);

void setup() {
Serial.begin(115200);
lcd.begin(16,2);
lcd.init();
lcd.backlight();
lcd.setCursor(5,0);
lcd.print("Hello");
lcd.setCursor(4,1);
lcd.print("Welcome");
delay(2000);
}

void loop() {
lcd.init();
lcd.backlight();

float voltage = pzem.voltage();
if(voltage != NAN){
lcd.setCursor(0,0);
lcd.print(" V: "); lcd.print(voltage); lcd.println("V");
}else{
lcd.println("Error reading voltage");
}

 float current = pzem.current();
 if(current != NAN){
  lcd.setCursor(8,0);
  lcd.print(" I: "); lcd.print(current); lcd.println("A");
 }else{
  lcd.println("Error reading current"); 
 }

float power = pzem.power();
 if(power != NAN){
  lcd.setCursor(0,1);
  lcd.print("P: "); lcd.print(power); lcd.println("W");
 }else{
  lcd.println("Error reading power"); 
 } 
 
 float frequency = pzem. frequency();
 if( frequency != NAN){
  lcd.setCursor(7,1);
  lcd.print(" F: "); lcd.print(frequency); lcd.println("Hz");
 }else{
  lcd.println("Error reading  frequency"); 
 } 

 lcd.println();
 delay(2000);

}

Hi, welcome to the forum.

This one ? https://innovatorsguru.com/pzem-004t-v3/

Can you show a sketch ?
Please put a sketch between code-tags on this forum.

Can you send messages from your sketch to the Serial Monitor ? That is easier to start with. The LCD can be added later on.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.