RDobrinov / pzem-004T-v3.0

Arduino interface library for Peacefair PZEM-004T-100A v3.0
MIT License
0 stars 1 forks source link

Please share an Example code of how to use it. Thank you. #1

Open MegoVaTx opened 10 months ago

MegoVaTx commented 10 months ago

Please share the working code using your library.

RDobrinov commented 10 months ago

Something like this.

#ifndef SENSOR_PZEM_TXPIN
#define SENSOR_PZEM_TXPIN   GPIO_NUM_25
#endif

#ifndef SENSOR_PZEM_RXPIN
#define SENSOR_PZEM_RXPIN   GPIO_NUM_32
#endif

#ifndef SENSOR_PZEM_ESP32_UART
#define SENSOR_PZEM_ESP32_UART  2
#endif
...
_serial = new HardwareSerial(SENSOR_PZEM_ESP32_UART);
_pzem = new PZEM004Tv30(_serial, SENSOR_PZEM_RXPIN, SENSOR_PZEM_TXPIN);
_pzem->readInputRegister();

double readout = _pzem->getVoltage();
readout =_pzem->getCurrent();
readout =_pzem->getPower();
readout =_pzem->getPowerFactor();
readout =_pzem->getEnergy();
readout =_pzem->getFrequency();
err =_pzem->getErrorState();