You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PZEMHardSerial Example not working. Some issues in PZEM constructor and Serial.begin() in the library.
In stm32 library hardware configuration works after setup function invoke.
Please refer attached my workout example.
#include<PZEM004Tv30.h>#if !defined(PZEM_SERIAL)
#definePZEM_SERIAL Serial2
#endifPZEM004Tv30*pzem;
voidsetup() {
// Debugging Serial portSerial1.begin(115200);
pzem=newPZEM004Tv30(PZEM_SERIAL);
// Uncomment in order to reset the internal energy counter// pzem.resetEnergy()
}
voidloop() {
// Print the custom address of the PZEMSerial1.print("Custom Address:");
Serial1.println(pzem->readAddress(), HEX);
// Read the data from the sensorfloatvoltage=pzem->voltage();
floatcurrent=pzem->current();
floatpower=pzem->power();
floatenergy=pzem->energy();
floatfrequency=pzem->frequency();
floatpf=pzem->pf();
// Check if the data is validif(isnan(voltage)){
Serial1.println("Error reading voltage");
} elseif (isnan(current)) {
Serial1.println("Error reading current");
} elseif (isnan(power)) {
Serial1.println("Error reading power");
} elseif (isnan(energy)) {
Serial1.println("Error reading energy");
} elseif (isnan(frequency)) {
Serial1.println("Error reading frequency");
} elseif (isnan(pf)) {
Serial1.println("Error reading power factor");
} else {
// Print the values to the Serial consoleSerial1.print("Voltage: "); Serial1.print(voltage); Serial1.println("V");
Serial1.print("Current: "); Serial1.print(current); Serial1.println("A");
Serial1.print("Power: "); Serial1.print(power); Serial1.println("W");
Serial1.print("Energy: "); Serial1.print(energy,3); Serial1.println("kWh");
Serial1.print("Frequency: "); Serial1.print(frequency, 1); Serial1.println("Hz");
Serial1.print("PF: "); Serial1.println(pf);
}
Serial1.println();
delay(2000);
}
The text was updated successfully, but these errors were encountered:
binarymaker
changed the title
stm32 bluebill hardware serial example not working
stm32 bluepill hardware serial example not working
Sep 25, 2021
PZEMHardSerial Example not working. Some issues in PZEM constructor and Serial.begin() in the library.
In stm32 library hardware configuration works after setup function invoke.
Please refer attached my workout example.
The text was updated successfully, but these errors were encountered: