im doing an energy meter that i saw from the internet and i follow the right step.i'm clueless as to how does the lcd display doesnt display.Please share some insights
the code
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define BLYNK_PRINT Serial
#include "EmonLib.h"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
EnergyMonitor emon;
#define vCalibration 83.3
#define currCalibration 0.50
BlynkTimer timer;
char auth[] = "apYc_VS8FMFL6SWw5TMM4HXZRWN4ee4p";
char ssid[] = "Omar";
char pass[] = "password";
float kWh = 0;
unsigned long lastmillis = millis();
void myTimerEvent()
{
emon.calcVI(20, 2000);
kWh = kWh + emon.apparentPower * (millis() - lastmillis) / 3600000000.0;
yield();
Serial.print("Vrms: ");
Serial.print(emon.Vrms, 2);
Serial.print("V");
Serial.print("\tIrms: ");
Serial.print(emon.Irms, 4);
Serial.print("A");
Serial.print("\tPower: ");
Serial.print(emon.apparentPower, 4);
Serial.print("W");
Serial.print("\tkWh: ");
Serial.print(kWh, 5);
Serial.println("kWh");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Vrms:");
lcd.print(emon.Vrms, 2);
lcd.print("V");
lcd.setCursor(0, 1);
lcd.print("Irms:");
lcd.print(emon.Irms, 4);
lcd.print("A");
delay(2500);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Power:");
lcd.print(emon.apparentPower, 4);
lcd.print("W");
lcd.setCursor(0, 1);
lcd.print("kWh:");
lcd.print(kWh, 4);
lcd.print("W");
delay(2500);
lastmillis = millis();
Blynk.virtualWrite(V0, emon.Vrms);
Blynk.virtualWrite(V13, emon.Irms);
Blynk.virtualWrite(V2, emon.apparentPower);
Blynk.virtualWrite(V3, kWh);
}
void setup()
{
Serial.begin(9600);
lcd.begin();
lcd.backlight();
Blynk.begin(auth, ssid, pass);
emon.voltage(35, vCalibration, 1.7);
emon.current(34, currCalibration);
timer.setInterval(5000L, myTimerEvent);
lcd.setCursor(3, 0);
lcd.print("IoT Energy");
lcd.setCursor(5, 1);
lcd.print("Meter");
delay(3000);
lcd.clear();
}
void loop()
{
Blynk.run();
timer.run();
}
Start by only using the lcd and the microcontroller board. Get that working first.
Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project See About the Installation & Troubleshooting category .
i think its from my code because on other code that involves an lcd works but this doesnt
Do you have a simple "hello world" sketch for the LCD?
Does that work?
This wiring of LCD seems wrong for ESP32.
With this library changing lcd.begin
to lcd.init
your code can print on LCD with this wiring.
Here the pinout for ESP32
when i change to lcd.init
Install the library from my link or try your current code after fix the wiring.
@yabedibedoo Diagram illegible. Is the red trace connected to Vin, or 5V, on the Arduino and GND/0V on the LCD? It's impossible to tell.
Post good pictures showing how it's wired and show us your current code.
Also tell us if it can work with some example from library.
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include "EmonLib.h"
#include <EEPROM.h>
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
EnergyMonitor emon;
#define vCalibration 83.3
#define currCalibration 0.50
BlynkTimer timer;
char auth[] = "nrexz-lNuB963age87Dlm7GvtmGure2y";
char ssid[] = "prateeksingh";
char pass[] = "kumar@12345";
float kWh = 0;
unsigned long lastmillis = millis();
void myTimerEvent()
{
emon.calcVI(20, 2000);
kWh = kWh + emon.apparentPower * (millis() - lastmillis) / 3600000000.0;
yield();
Serial.print("Vrms: ");
Serial.print(emon.Vrms, 2);
Serial.print("V");
EEPROM.update(0, emon.Vrms);
delay(100);
Serial.print("\tIrms: ");
Serial.print(emon.Irms, 4);
Serial.print("A");
EEPROM.update(1, emon.Irms);
delay(100);
Serial.print("\tPower: ");
Serial.print(emon.apparentPower, 4);
Serial.print("W");
EEPROM.update(2, emon.apparentPower);
delay(100);
Serial.print("\tkWh: ");
Serial.print(kWh, 5);
Serial.println("kWh");
EEPROM.update(3, kWh);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Vrms:");
lcd.print(emon.Vrms, 2);
lcd.print("V");
lcd.setCursor(0, 1);
lcd.print("Irms:");
lcd.print(emon.Irms, 4);
lcd.print("A");
lcd.setCursor(0, 2);
lcd.print("Power:");
lcd.print(emon.apparentPower, 4);
lcd.print("W");
lcd.setCursor(0, 3);
lcd.print("kWh:");
lcd.print(kWh, 4);
lcd.print("W");
lastmillis = millis();
Blynk.virtualWrite(V0, emon.Vrms);
Blynk.virtualWrite(V1, emon.Irms);
Blynk.virtualWrite(V2, emon.apparentPower);
Blynk.virtualWrite(V3, kWh);
}
void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
lcd.begin();
lcd.backlight();
eepromState();
emon.voltage(35, vCalibration, 1.7); // Voltage: input pin, calibration, phase_shift
emon.current(34, currCalibration); // Current: input pin, calibration.
timer.setInterval(5000L, myTimerEvent);
lcd.setCursor(3, 0);
lcd.print("IoT Energy");
lcd.setCursor(5, 1);
lcd.print("Meter");
delay(3000);
lcd.clear();
void loop()
{
Blynk.run();
timer.run();
}
system
Closed
August 30, 2023, 3:25pm
13
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.