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 Hardware Serial doesn't work #85

Open
Ncent-EP opened this issue Apr 3, 2022 · 5 comments
Open

ESP32 Hardware Serial doesn't work #85

Ncent-EP opened this issue Apr 3, 2022 · 5 comments

Comments

@Ncent-EP
Copy link

Ncent-EP commented Apr 3, 2022

I am using the hardware serial on ESP32 but it seems doesn't work, the PZEM cannot give a response to ESP32. The serial monitor shows only.

Custom Address:0 Error reading voltage

I was think the command that give from ESP32 isn't send properly to PZEM. please fix it, thanks :)

@sergiocntr
Copy link

Hi,
There are many Esp32 working with this lib ,so check deeply your code and connections.
If everything looks fine, take a look at closed issue #64 .

@lequangthinhhaui
Copy link

Please plug the voltage, it will work when voltage >0

@MegoVaTx
Copy link

Same issue Rx TX leds on sensor stay lit all the time. begin(9600,SERIAL_8N1,16,17);
does work.
Also SoftwareSerial on uno works with sensor.
Looks like Library cant communicate with sensor at all.
Tried multiple ESP32, Rx connected to TX, TX to RX, wired properly.

Code Im using
`/*
Copyright (c) 2021 Jakub Mandula

Example of using one PZEM module with Hardware Serial interface.

If desired, a HardwareSerial handle can be passed to the constructor
which will then be used for the communication with the module.

Note that ESP32 HardwareSerial must also be provided with the RX and TX
pins.

*/

#include <PZEM004Tv30.h>
//RX 16 to white
//TX 17 to green
PZEM004Tv30 pzem(Serial2, 16, 17);

void setup() {
// Debugging Serial port
Serial.begin(115200);

// Uncomment in order to reset the internal energy counter
// pzem.resetEnergy()

}

void loop() {
// Print the custom address of the PZEM
Serial.print("Custom Address:");
Serial.println(pzem.readAddress(), HEX);

// Read the data from the sensor
float voltage = pzem.voltage();
float current = pzem.current();
float power = pzem.power();
float energy = pzem.energy();
float frequency = pzem.frequency();
float pf = pzem.pf();

// Check if the data is valid
if(isnan(voltage)){
    Serial.println("Error reading voltage");
} else if (isnan(current)) {
    Serial.println("Error reading current");
} else if (isnan(power)) {
    Serial.println("Error reading power");
} else if (isnan(energy)) {
    Serial.println("Error reading energy");
} else if (isnan(frequency)) {
    Serial.println("Error reading frequency");
} else if (isnan(pf)) {
    Serial.println("Error reading power factor");
} else {

    // Print the values to the Serial console
    Serial.print("Voltage: ");      Serial.print(voltage);      Serial.println("V");
    Serial.print("Current: ");      Serial.print(current);      Serial.println("A");
    Serial.print("Power: ");        Serial.print(power);        Serial.println("W");
    Serial.print("Energy: ");       Serial.print(energy,3);     Serial.println("kWh");
    Serial.print("Frequency: ");    Serial.print(frequency, 1); Serial.println("Hz");
    Serial.print("PF: ");           Serial.println(pf);

}


Serial.println();
delay(2000);

}
`

@MegoVaTx
Copy link

MegoVaTx commented Dec 30, 2023

The module is powered by AC.
As mentioned earlier, Sensor is finer (tested with Swserial on Uno)
Esp32 is good tested with MeterSerial.begin(9600,SERIAL_8N1,16,17);
The ESPs Tested on:
ESP32-CH340C-TYPE C : https://www.aliexpress.us/item/2251832773226694.html?spm=a2g0o.order_list.order_list_main.50.21ef1802xSLq1O&gatewayAdapt=glo2usa
and: ESP32-3248S035 : https://www.aliexpress.us/item/3256804446638703.html?spm=a2g0o.order_list.order_list_main.11.21ef1802xSLq1O&gatewayAdapt=glo2usa
both ESP-WROOM-32
The board selected in IDE is: Esp32 Dev Module

@MegoVaTx
Copy link

I managed to get it working with:https://github.com/jaggil/Control-of-meter-PZEM-004T-with-ESP32-Modbus?tab=readme-ov-file
with ModBus lib eModbus downgraded to 1.5.0

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