Code Monkey home page Code Monkey logo

pzem-017-v1's Introduction

PZEM-017 v1.0

Arduino communication library for Peacefair PZEM-017 v1.0 Energy monitor, a slightly modify version of Jakub Mandula's PZEM-004T-v30 library (https://github.com/mandulaj/PZEM-004T-v30)


Common issue:

Make sure the device is connected to the 5v power!

Example

#include <PZEM017v1.h>

/* Use software serial for the PZEM
 * Pin 4 Rx (Connects to the Tx pin on the PZEM)
 * Pin 5 Tx (Connects to the Rx pin on the PZEM)
*/
PZEM017v1 pzem(4, 5); //WMOS D1 4=D1, 5=D2

void setup() {
  Serial.begin(115200);
}

void loop() {
    float voltage = pzem.voltage();
    if( !isnan(voltage) ){
        Serial.print("Voltage: "); Serial.print(voltage); Serial.println("V");
    } else {
        Serial.println("Error reading voltage");
    }

    float current = pzem.current();
    if( !isnan(current) ){
        Serial.print("Current: "); Serial.print(current); Serial.println("A");
    } else {
        Serial.println("Error reading current");
    }

    float power = pzem.power();
    if( !isnan(power) ){
        Serial.print("Power: "); Serial.print(power); Serial.println("W");
    } else {
        Serial.println("Error reading power");
    }

    float energy = pzem.energy();
    if( !isnan(energy) ){
        Serial.print("Energy: "); Serial.print(energy,3); Serial.println("kWh");
    } else {
        Serial.println("Error reading energy");
    }

    Serial.println();
    delay(2000);
}

Installation instructions

You should be able to install the library from the Library Manager in the Arduino IDE. You can also download the ZIP of this repository and install it manually. A guide on how to do that is over here: https://www.arduino.cc/en/guide/libraries


Thank you to @olehs and Jakub Mandula for this great library.

pzem-017-v1's People

Contributors

maxzerker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pzem-017-v1's Issues

ModBus? TTL to RS485 converter?

Thank you for the code, but it is not working for me. I have used pzem-004tv3 module and related code with arduino Uno and it works great.

I'm trying to talk to Arduino Uno, and need (I believe) TTL to rs485 translation. Would you describe how this code is intended to work with pzem-017 module (and arduino Uno)? For example, Modbus library is apparently not used; is the code performing some of those tasks? Also, is a TTL to rs485 module needed? If so, which type is presumed, 2-pin (A,B) or 4-pin (DI,DE,RE,RO)? Thanks.

Compilation error

I am getting the following error when compiling for arduino nano:
....\Arduino\libraries\PZEM-017-v1-master\PZEM017v1.cpp: In constructor 'PZEM017v1::PZEM017v1(uint8_t, uint8_t, uint8_t)': ....\Arduino\libraries\PZEM-017-v1-master\PZEM017v1.cpp:90:32: error: 'SWSERIAL_8N2' was not declared in this scope port->begin(PZEM_BAUD_RATE,SWSERIAL_8N2); ^~~~~~~~~~~~ ....\Arduino\libraries\PZEM-017-v1-master\PZEM017v1.cpp:90:32: note: suggested alternative: 'SERIAL_8N2' port->begin(PZEM_BAUD_RATE,SWSERIAL_8N2); ^~~~~~~~~~~~ SERIAL_8N2 exit status 1

How can I make it compile?
Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.