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

stm32 bluepill hardware serial example not working #76

Open
binarymaker opened this issue Sep 25, 2021 · 1 comment
Open

stm32 bluepill hardware serial example not working #76

binarymaker opened this issue Sep 25, 2021 · 1 comment

Comments

@binarymaker
Copy link

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)
#define PZEM_SERIAL Serial2
#endif

PZEM004Tv30 *pzem;

void setup() {
    // Debugging Serial port
    Serial1.begin(115200);
    pzem = new PZEM004Tv30(PZEM_SERIAL);

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

void loop() {
    // Print the custom address of the PZEM
    Serial1.print("Custom Address:");
    Serial1.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)){
        Serial1.println("Error reading voltage");
    } else if (isnan(current)) {
        Serial1.println("Error reading current");
    } else if (isnan(power)) {
        Serial1.println("Error reading power");
    } else if (isnan(energy)) {
        Serial1.println("Error reading energy");
    } else if (isnan(frequency)) {
        Serial1.println("Error reading frequency");
    } else if (isnan(pf)) {
        Serial1.println("Error reading power factor");
    } else {

        // Print the values to the Serial console
        Serial1.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);
}
@binarymaker binarymaker changed the title stm32 bluebill hardware serial example not working stm32 bluepill hardware serial example not working Sep 25, 2021
@vortigont
Copy link
Contributor

Looks like this is a wrong lib :) you might be talking about this one

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

2 participants