├── PZEM_ArduinoNANOSoftSerial ├── PZEM_ArduinoNANOSoftSerial.ino └── README.md ├── PZEM_ArduinoUNO-ETHSoftSerial ├── PZEM_ArduinoUNO-ETHSoftSerial.ino └── README.md ├── PZEM_ESP32HwSerial ├── PZEM_ESP32HwSerial.ino └── README.md ├── PZEM_ESP8266HwSerial ├── PZEM_ESP8266HwSerial.ino └── README.md ├── PZEM_Python ├── README.md └── PZEM-004-python.py └── README.md /PZEM_ArduinoNANOSoftSerial/PZEM_ArduinoNANOSoftSerial.ino: -------------------------------------------------------------------------------- 1 | #include // Arduino IDE <1.6.6 2 | #include 3 | 4 | PZEM004T pzem(10,11); // RX,TX 5 | IPAddress ip(192,168,1,1); 6 | 7 | /* 8 | * PDAControl 9 | * Documentation PDAControl English: 10 | * http://pdacontrolen.com/meter-pzem-004t-with-arduino-esp32-esp8266-python-raspberry-pi/ 11 | * Documentacion PDAControl Español: 12 | * http://pdacontroles.com/medidor-pzem-004t-con-arduino-esp32-esp8266-python-raspberry-pi/ 13 | * Video Tutorial : https://youtu.be/qt32YT_1oH8 14 | * 15 | */ 16 | 17 | void setup() { 18 | Serial.begin(115200); 19 | pzem.setAddress(ip); 20 | 21 | } 22 | 23 | void loop() { 24 | 25 | Serial.println(""); 26 | 27 | float v = pzem.voltage(ip); 28 | if(v >= 0.0){ Serial.print(v);Serial.print("V; "); } 29 | 30 | float i = pzem.current(ip); 31 | if(i >= 0.0){ Serial.print(i);Serial.print("A; "); } 32 | 33 | float p = pzem.power(ip); 34 | if(p >= 0.0){ Serial.print(p);Serial.print("W; "); } 35 | 36 | float e = pzem.energy(ip); 37 | if(e >= 0.0){ Serial.print(e);Serial.print("Wh; "); } 38 | 39 | Serial.println(); 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /PZEM_ArduinoUNO-ETHSoftSerial/PZEM_ArduinoUNO-ETHSoftSerial.ino: -------------------------------------------------------------------------------- 1 | #include // Arduino IDE <1.6.6 2 | #include 3 | 4 | 5 | //https://www.arduino.cc/en/Tutorial/SoftwareSerialExample 6 | 7 | 8 | PZEM004T pzem(8,9); // RX,TX 9 | IPAddress ip(192,168,1,1); 10 | 11 | /* 12 | * PDAControl 13 | * Documentation PDAControl English: 14 | * http://pdacontrolen.com/meter-pzem-004t-with-arduino-esp32-esp8266-python-raspberry-pi/ 15 | * Documentacion PDAControl Español: 16 | * http://pdacontroles.com/medidor-pzem-004t-con-arduino-esp32-esp8266-python-raspberry-pi/ 17 | * Video Tutorial : https://youtu.be/qt32YT_1oH8 18 | * 19 | */ 20 | 21 | void setup() { 22 | Serial.begin(115200); 23 | pzem.setAddress(ip); 24 | 25 | } 26 | 27 | void loop() { 28 | 29 | Serial.println(""); 30 | 31 | float v = pzem.voltage(ip); 32 | if(v >= 0.0){ Serial.print(v);Serial.print("V; "); } 33 | 34 | float i = pzem.current(ip); 35 | if(i >= 0.0){ Serial.print(i);Serial.print("A; "); } 36 | 37 | float p = pzem.power(ip); 38 | if(p >= 0.0){ Serial.print(p);Serial.print("W; "); } 39 | 40 | float e = pzem.energy(ip); 41 | if(e >= 0.0){ Serial.print(e);Serial.print("Wh; "); } 42 | 43 | Serial.println(); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /PZEM_ESP32HwSerial/PZEM_ESP32HwSerial.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* 5 | An example on how to use ESP32 hardware serial with PZEM004T 6 | */ 7 | 8 | HardwareSerial Serial2(2); // Use hwserial UART2 at pins IO-16 (RX2) and IO-17 (TX2) 9 | PZEM004T pzem(&Serial2); 10 | IPAddress ip(192,168,1,1); 11 | 12 | /* 13 | * PDAControl 14 | * Documentation PDAControl English: 15 | * http://pdacontrolen.com/meter-pzem-004t-with-arduino-esp32-esp8266-python-raspberry-pi/ 16 | * Documentacion PDAControl Español: 17 | * http://pdacontroles.com/medidor-pzem-004t-con-arduino-esp32-esp8266-python-raspberry-pi/ 18 | * Video Tutorial : https://youtu.be/qt32YT_1oH8 19 | * 20 | */ 21 | 22 | void setup() { 23 | Serial.begin(115200); 24 | while (true) { 25 | Serial.println("Connecting to PZEM..."); 26 | if(pzem.setAddress(ip)) 27 | break; 28 | delay(1000); 29 | } 30 | } 31 | 32 | void loop() { 33 | 34 | float v = pzem.voltage(ip); 35 | if (v < 0.0) v = 0.0; 36 | Serial.print(v);Serial.print("V; "); 37 | 38 | float i = pzem.current(ip); 39 | if(i >= 0.0){ Serial.print(i);Serial.print("A; "); } 40 | 41 | float p = pzem.power(ip); 42 | if(p >= 0.0){ Serial.print(p);Serial.print("W; "); } 43 | 44 | float e = pzem.energy(ip); 45 | if(e >= 0.0){ Serial.print(e);Serial.print("Wh; "); } 46 | 47 | Serial.println(); 48 | 49 | delay(3000); 50 | } 51 | -------------------------------------------------------------------------------- /PZEM_ESP8266HwSerial/PZEM_ESP8266HwSerial.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 4 | An example on how to use ESP8266 hardware serial with PZEM004T 5 | 6 | Note: ESP8266 UART0 pins GPIO1 (TX) and GPIO3 (RX) are usually connected 7 | to an onboard USB2serial converter, it can affect PZEM communication. 8 | It's better not to share USB2serial pins for PZEM communication 9 | 10 | Default UART0 pins could be swapped to gpio13(rx),gpio15(tx) 11 | Note: gpio15 pin must be pulled lOW on esp start, otherwise it won't boot from eeprom. 12 | PZEM004T always pulls it's RX pin HIGH via optocoupler's led, so make sure to workaround it anyhow while esp boots up 13 | */ 14 | 15 | 16 | /* 17 | * PDAControl 18 | * Documentation PDAControl English: 19 | * http://pdacontrolen.com/meter-pzem-004t-with-arduino-esp32-esp8266-python-raspberry-pi/ 20 | * Documentacion PDAControl Español: 21 | * http://pdacontroles.com/medidor-pzem-004t-con-arduino-esp32-esp8266-python-raspberry-pi/ 22 | * Video Tutorial : https://youtu.be/qt32YT_1oH8 23 | * 24 | */ 25 | 26 | HardwareSerial hwserial(UART0); // Use hwserial UART0 at pins GPIO1 (TX) and GPIO3 (RX) 27 | PZEM004T pzem(&hwserial); // Attach PZEM to hwserial 28 | IPAddress ip(192,168,1,1); 29 | 30 | bool pzemrdy = false; 31 | 32 | void setup() { 33 | hwserial.swap(); // (optionally) swap hw_serial pins to gpio13(rx) (D7) , gpio15(tx)(D8) 34 | Serial1.begin(115200); /* Since UART0 is occupied with PZEM004T, we use UART1 to output data to serial monitor 35 | UART1 uses hwserial at pin GPIO2 (D4) 36 | */ 37 | 38 | 39 | while (!pzemrdy) { 40 | Serial1.println("Connecting to PZEM..."); 41 | pzemrdy = pzem.setAddress(ip); 42 | delay(1000); 43 | } 44 | } 45 | 46 | void loop() { 47 | 48 | float v = pzem.voltage(ip); 49 | if (v < 0.0) v = 0.0; 50 | Serial1.print(v);Serial1.print("V; "); 51 | 52 | float i = pzem.current(ip); 53 | if(i >= 0.0){ Serial1.print(i);Serial1.print("A; "); } 54 | 55 | float p = pzem.power(ip); 56 | if(p >= 0.0){ Serial1.print(p);Serial1.print("W; "); } 57 | 58 | float e = pzem.energy(ip); 59 | if(e >= 0.0){ Serial1.print(e);Serial1.print("Wh; "); } 60 | 61 | Serial1.println(); 62 | 63 | delay(3000); 64 | } 65 | -------------------------------------------------------------------------------- /PZEM_ESP32HwSerial/README.md: -------------------------------------------------------------------------------- 1 | # Test Meter PZEM-004T with ESP32 2 | 3 | Date 11-07-2018 [PDAControl](http://pdacontrolen.com) 4 | 5 | 6 | ## Description / Descripción 7 | 8 | test Active power measurement or power consumption with Peacefair **PZEM-004T Meter with Module ESP32** 9 | 10 | Contains 1 Files: 11 | 12 | Prueba de medición de potencia Activa o consumo eléctrico con **Medidor PZEM-004T con Modulo ESP32** 13 | 14 | Contiene 1 Archivo: 15 | 16 | * **PZEM_ESP32HwSerial.ino** : Example ESP32 with Arduino IDE 17 | 18 | ## Library / Librerias 19 | 20 | * [**PZEM004T.h** ](https://github.com/olehs/PZEM004T) - Arduino communication library for Peacefair PZEM-004T Energy monitor 21 | 22 | Thanks [olehs](https://github.com/olehs) for contributing 23 | 24 | 25 | # Materials / Materiales 26 | 27 | * [1 PZEM-004T](https://bit.ly/2HPyVJL) - Banggood 28 | * [1 ESP32 DEVKIT V1 Doit](http://bit.ly/2zuUGje) - Banggood 29 | * [2 Breadboard / Protoboard 8.5 x 5.5cm 400 Points](http://bit.ly/2uant7G) - Banggood 30 | * [Jumper Wires Male-Female / Cables puente Macho-Hembra ](http://bit.ly/2KK4F9s) - Banggood 31 | * [Jumper Wires Male-Male / Cables puente Macho-Macho](http://bit.ly/2N7MZSb) - Banggood 32 | * [Jumper Wires Female-Female / Cables puente Hembra-Hembra ](http://bit.ly/2L7HxOn) - Banggood 33 | 34 | 35 | ## Mounting / Montaje 36 | 37 | * ESP32 DEVKIT V1 Doit 38 | 39 | ![alt text](http://pdacontroles.com/wp-content/uploads/2018/07/ESP32-MONTAJE-PDAControl.jpg "mounting") 40 | 41 | 42 | # Documentation / Documentación 43 | * Read Considerations, Recommendations and Suggestions complete documentation of the project in [Meter PZEM-004T with Arduino ESP32 ESP8266 Python & Raspberry Pi](http://pdacontrolen.com/meter-pzem-004t-with-arduino-esp32-esp8266-python-raspberry-pi/). 44 | 45 | * Leer Consideraciones, Recomendaciones y sugerencias documentacion Completa del proyecto en [Medidor PZEM-004T con Arduino ESP32 ESP8266 Python & Raspberry Pi](http://pdacontroles.com/medidor-pzem-004t-con-arduino-esp32-esp8266-python-raspberry-pi/). 46 | 47 | # Donations / Donaciones 48 | Collaborate this project and other projects in [PDAControl](http://pdacontrolen.com) via [Paypal](https://www.paypal.me/pdacontrol). 49 | 50 | Respalde este proyecto y otros proyectos en [PDAControl](http://pdacontrolen.com) mediante [Paypal](https://www.paypal.me/pdacontrol). 51 | 52 | [![Support via PayPal](https://cdn.rawgit.com/twolfson/paypal-github-button/1.0.0/dist/button.svg)](https://www.paypal.me/pdacontrol) 53 | 54 | # More about PDAControl / Mas sobre PDAControl 55 | * [PDAControl English](http://pdacontrolen.com). 56 | * [PDAControl Español](http://pdacontroles.com). 57 | * [PDAControl Youtube Channel](https://www.youtube.com/channel/UCv1D6zrC0ZL0PSgM6tdEpPg/videos). 58 | * [Jhon_Control Twitter](https://twitter.com/Jhon_Control). 59 | 60 | -------------------------------------------------------------------------------- /PZEM_ArduinoUNO-ETHSoftSerial/README.md: -------------------------------------------------------------------------------- 1 | # Test Meter PZEM-004T with Arduino UNO + Shield Ethenet W5100 2 | 3 | Date 11-07-2018 [PDAControl](http://pdacontrolen.com) 4 | 5 | 6 | ## Description / Descripción 7 | 8 | test Active power measurement or power consumption with **PZEM-004T Meter with Arduino UNO + Shield Ethenet W5100** 9 | 10 | Contains 1 Files: 11 | 12 | Prueba de medición de potencia Activa o consumo eléctrico con **Medidor PZEM-004T con Arduino UNO + Shield Ethenet W5100** 13 | 14 | Contiene 1 Archivo: 15 | 16 | 17 | * **PZEM_ArduinoUNO-ETHSoftSerial.ino**: Example Arduino UNO + Shield Ethernet W5100 with Arduino IDE 18 | 19 | ## Library / Librerias 20 | 21 | * [**PZEM004T.h** ](https://github.com/olehs/PZEM004T) - Arduino communication library for Peacefair PZEM-004T Energy monitor 22 | 23 | Thanks [olehs](https://github.com/olehs) for contributing 24 | 25 | 26 | # Materials / Materiales 27 | 28 | * [1 PZEM-004T](https://bit.ly/2HPyVJL) - Banggood 29 | * [1 Arduino UNO + Shield Ethernet W5100](https://bit.ly/2leWqDr) - Banggood 30 | * [Jumper Wires Male-Female / Cables puente Macho-Hembra ](http://bit.ly/2KK4F9s) - Banggood 31 | * [Jumper Wires Male-Male / Cables puente Macho-Macho](http://bit.ly/2N7MZSb) - Banggood 32 | * [Jumper Wires Female-Female / Cables puente Hembra-Hembra ](http://bit.ly/2L7HxOn) - Banggood 33 | 34 | 35 | ## Mounting / Montaje 36 | 37 | * Arduino UNO & Shield Ethenet W5100 38 | 39 | ![alt text](http://pdacontroles.com/wp-content/uploads/2018/07/ARD-ETHERNET-MONTAJE.jpg "mounting") 40 | 41 | 42 | # Documentation / Documentación 43 | * Read Considerations, Recommendations and Suggestions complete documentation of the project in [Meter PZEM-004T with Arduino ESP32 ESP8266 Python & Raspberry Pi](http://pdacontrolen.com/meter-pzem-004t-with-arduino-esp32-esp8266-python-raspberry-pi/). 44 | 45 | * Leer Consideraciones, Recomendaciones y sugerencias documentacion Completa del proyecto en [Medidor PZEM-004T con Arduino ESP32 ESP8266 Python & Raspberry Pi](http://pdacontroles.com/medidor-pzem-004t-con-arduino-esp32-esp8266-python-raspberry-pi/). 46 | 47 | # Donations / Donaciones 48 | Collaborate this project and other projects in [PDAControl](http://pdacontrolen.com) via [Paypal](https://www.paypal.me/pdacontrol). 49 | 50 | Respalde este proyecto y otros proyectos en [PDAControl](http://pdacontrolen.com) mediante [Paypal](https://www.paypal.me/pdacontrol). 51 | 52 | [![Support via PayPal](https://cdn.rawgit.com/twolfson/paypal-github-button/1.0.0/dist/button.svg)](https://www.paypal.me/pdacontrol) 53 | 54 | # More about PDAControl / Mas sobre PDAControl 55 | * [PDAControl English](http://pdacontrolen.com). 56 | * [PDAControl Español](http://pdacontroles.com). 57 | * [PDAControl Youtube Channel](https://www.youtube.com/channel/UCv1D6zrC0ZL0PSgM6tdEpPg/videos). 58 | * [Jhon_Control Twitter](https://twitter.com/Jhon_Control). 59 | 60 | -------------------------------------------------------------------------------- /PZEM_ESP8266HwSerial/README.md: -------------------------------------------------------------------------------- 1 | # Test Meter PZEM-004T with ESP8266 2 | 3 | Date 11-07-2018 [PDAControl](http://pdacontrolen.com) 4 | 5 | 6 | ## Description / Descripción 7 | 8 | test Active power measurement or power consumption with **PZEM-004T Meter with Module ESP8266** 9 | 10 | Contains 1 Files: 11 | 12 | Prueba de medición de potencia Activa o consumo eléctrico con **Medidor PZEM-004T con Modulo ESP8266** 13 | 14 | Contiene 1 Archivo: 15 | 16 | * **PZEM_ESP8266HwSerial.ino** : Example ESP8266 with Arduino IDE 17 | 18 | ## Library / Librerias 19 | 20 | * [**PZEM004T.h** ](https://github.com/olehs/PZEM004T) - Arduino communication library for Peacefair PZEM-004T Energy monitor 21 | 22 | Thanks [olehs](https://github.com/olehs) for contributing 23 | 24 | 25 | # Materials / Materiales 26 | 27 | * [1 PZEM-004T](https://bit.ly/2HPyVJL) - Banggood 28 | * [1 ESP8266 12E NodeMCU](http://bit.ly/2uni5Nz) - Banggood 29 | * [1 FTDI TTL to USB Serial Converter](http://bit.ly/2ujroOI) - Banggood 30 | * [1 2N2907 TO-92 or similar PNP](https://global.oup.com/us/companion.websites/fdscontent/uscompanion/us/pdf/microcircuits/students/bjt/2N2907-motorola.pdf) - transistor PNP 31 | * [1 Breadboard / Protoboard 8.5 x 5.5cm 400 Points](http://bit.ly/2uant7G) - Banggood 32 | * [Jumper Wires Male-Female / Cables puente Macho-Hembra ](http://bit.ly/2KK4F9s) - Banggood 33 | * [Jumper Wires Male-Male / Cables puente Macho-Macho](http://bit.ly/2N7MZSb) - Banggood 34 | * [Jumper Wires Female-Female / Cables puente Hembra-Hembra ](http://bit.ly/2L7HxOn) - Banggood 35 | 36 | 37 | ## Mounting / Montaje 38 | 39 | * ESP8266 GEEKCREIT 40 | 41 | ![alt text](http://pdacontroles.com/wp-content/uploads/2018/07/ESP8266-MONTAJE2.jpg "mounting") 42 | 43 | 44 | # Documentation / Documentación 45 | * Read Considerations, Recommendations and Suggestions complete documentation of the project in [Meter PZEM-004T with Arduino ESP32 ESP8266 Python & Raspberry Pi](http://pdacontrolen.com/meter-pzem-004t-with-arduino-esp32-esp8266-python-raspberry-pi/). 46 | 47 | * Leer Consideraciones, Recomendaciones y sugerencias documentacion Completa del proyecto en [Medidor PZEM-004T con Arduino ESP32 ESP8266 Python & Raspberry Pi](http://pdacontroles.com/medidor-pzem-004t-con-arduino-esp32-esp8266-python-raspberry-pi/). 48 | 49 | # Donations / Donaciones 50 | Collaborate this project and other projects in [PDAControl](http://pdacontrolen.com) via [Paypal](https://www.paypal.me/pdacontrol). 51 | 52 | Respalde este proyecto y otros proyectos en [PDAControl](http://pdacontrolen.com) mediante [Paypal](https://www.paypal.me/pdacontrol). 53 | 54 | [![Support via PayPal](https://cdn.rawgit.com/twolfson/paypal-github-button/1.0.0/dist/button.svg)](https://www.paypal.me/pdacontrol) 55 | 56 | # More about PDAControl / Mas sobre PDAControl 57 | * [PDAControl English](http://pdacontrolen.com). 58 | * [PDAControl Español](http://pdacontroles.com). 59 | * [PDAControl Youtube Channel](https://www.youtube.com/channel/UCv1D6zrC0ZL0PSgM6tdEpPg/videos). 60 | * [Jhon_Control Twitter](https://twitter.com/Jhon_Control). 61 | 62 | -------------------------------------------------------------------------------- /PZEM_ArduinoNANOSoftSerial/README.md: -------------------------------------------------------------------------------- 1 | # Test Meter PZEM-004T with Arduino Nano 2 | 3 | Date 11-07-2018 [PDAControl](http://pdacontrolen.com) 4 | 5 | 6 | ## Description / Descripción 7 | 8 | test Active power measurement or power consumption with **PZEM-004T Meter with Arduino Nano** 9 | 10 | Contains 1 Files: 11 | 12 | Prueba de medición de potencia Activa o consumo eléctrico con **Medidor PZEM-004T con Arduino Nano** 13 | 14 | Contiene 1 Archivo: 15 | 16 | * **PZEM_ArduinoNANOSoftSerial.ino** : Example Arduino Nano with Arduino IDE 17 | 18 | 19 | ## Library / Librerias 20 | 21 | * [**PZEM004T.h** ](https://github.com/olehs/PZEM004T) - Arduino communication library for Peacefair PZEM-004T Energy monitor 22 | 23 | Thanks [olehs](https://github.com/olehs) for contributing 24 | 25 | 26 | # Materials / Materiales 27 | 28 | * [1 PZEM-004T](https://bit.ly/2HPyVJL) - Banggood 29 | * [1 ARDUINO NANO V3 CLONE ](http://bit.ly/2uopXi5) - Banggood 30 | * [1 Breadboard / Protoboard 8.5 x 5.5cm 400 Points](http://bit.ly/2uant7G) - Banggood 31 | * [Jumper Wires Male-Female / Cables puente Macho-Hembra ](http://bit.ly/2KK4F9s) - Banggood 32 | * [Jumper Wires Male-Male / Cables puente Macho-Macho](http://bit.ly/2N7MZSb) - Banggood 33 | * [Jumper Wires Female-Female / Cables puente Hembra-Hembra ](http://bit.ly/2L7HxOn) - Banggood 34 | * [Shield/PCB Arduino-OTA V1.0](http://pdacontrolen.com) - Optional 35 | 36 | ## Mounting / Montaje 37 | 38 | * Ard-Nano-OTA Board Mount / Montaje en Placa Ard-Nano-OTA. 39 | 40 | ![alt text](http://pdacontroles.com/wp-content/uploads/2018/07/ARDUINO-NANO-MONTAJE.jpg "mounting") 41 | 42 | * Breadboard mounting / Montaje en protoboard 43 | 44 | ![alt text](http://pdacontroles.com/wp-content/uploads/2018/07/ARDUINO-NANO-Montaje2.jpg "mounting") 45 | 46 | 47 | # Documentation / Documentación 48 | * Read Considerations, Recommendations and Suggestions complete documentation of the project in [Meter PZEM-004T with Arduino ESP32 ESP8266 Python & Raspberry Pi](http://pdacontrolen.com/meter-pzem-004t-with-arduino-esp32-esp8266-python-raspberry-pi/). 49 | 50 | * Leer Consideraciones, Recomendaciones y sugerencias documentacion Completa del proyecto en [Medidor PZEM-004T con Arduino ESP32 ESP8266 Python & Raspberry Pi](http://pdacontroles.com/medidor-pzem-004t-con-arduino-esp32-esp8266-python-raspberry-pi/). 51 | 52 | # Donations / Donaciones 53 | Collaborate this project and other projects in [PDAControl](http://pdacontrolen.com) via [Paypal](https://www.paypal.me/pdacontrol). 54 | 55 | Respalde este proyecto y otros proyectos en [PDAControl](http://pdacontrolen.com) mediante [Paypal](https://www.paypal.me/pdacontrol). 56 | 57 | [![Support via PayPal](https://cdn.rawgit.com/twolfson/paypal-github-button/1.0.0/dist/button.svg)](https://www.paypal.me/pdacontrol) 58 | 59 | # More about PDAControl / Mas sobre PDAControl 60 | * [PDAControl English](http://pdacontrolen.com). 61 | * [PDAControl Español](http://pdacontroles.com). 62 | * [PDAControl Youtube Channel](https://www.youtube.com/channel/UCv1D6zrC0ZL0PSgM6tdEpPg/videos). 63 | * [Jhon_Control Twitter](https://twitter.com/Jhon_Control). 64 | 65 | -------------------------------------------------------------------------------- /PZEM_Python/README.md: -------------------------------------------------------------------------------- 1 | # Test Meter PZEM-004T with Python On Raspberry Pi 3 2 | 3 | Date 11-07-2018 [PDAControl](http://pdacontrolen.com) 4 | 5 | 6 | ## Description / Descripción 7 | 8 | test Active power measurement or power consumption with **PZEM-004T Meter with Python Run on Raspberry Pi 3** 9 | 10 | Contains 1 Files: 11 | 12 | Prueba de medición de potencia Activa o consumo eléctrico con **Medidor PZEM-004T con Python corriendo en Raspberry Pi 3** 13 | 14 | Contiene 1 Archivo: 15 | 16 | * **PZEM-004-python.py** : Example Python for Computer or Raspberry Pi 17 | 18 | 19 | ## Source code / Codigo fuente 20 | 21 | This very well structured routine, I found it in the Raspberrypi.org [**Raspberrypi.org forum**](https://www.raspberrypi.org/forums/viewtopic.php?t=124958#p923274) and apparently created by [**Massi**](https://www.raspberrypi.org/forums/viewtopic.php?t=124958#p923274), thanks to him for his contribution. Based on the code shared by Massi, the file **PZEM-004-python.py** has been created with the routine that we will execute in our Raspberry Pi to request data from our meter, make some modifications to the original code. 22 | 23 | 24 | Esta rutina muy bien estructurada, la encontré en el foro de [**Raspberrypi.org forum**](https://www.raspberrypi.org/forums/viewtopic.php?t=124958#p923274) y creada al parecer por [**Massi**](https://www.raspberrypi.org/forums/viewtopic.php?t=124958#p923274), gracias a el por su contribución. En base al código compartido por Massi se ha creado el archivo **PZEM-004-python.py**  con la rutina que ejecutaremos en nuestra Raspberry Pi para solicitar datos a nuestro medidor, realice algunas modificaciones al código original. 25 | 26 | 27 | * [**Peaceview PZEM-004T Energy Module** ](https://www.raspberrypi.org/forums/viewtopic.php?t=124958#p923274) - 28 | 29 | ![alt text](http://pdacontroles.com/wp-content/uploads/2018/07/python_file.png "python file") 30 | 31 | 32 | 33 | # Materials / Materiales 34 | 35 | * [1 PZEM-004T](https://bit.ly/2HPyVJL) - Banggood 36 | * [1 Raspberry Pi 3 Model B + ](http://bit.ly/2NKRnaO) - Banggood 37 | * [1 FTDI TTL to USB Serial Converter](http://bit.ly/2ujroOI) - Banggood 38 | * [1 Power Supply 5V 2A](http://bit.ly/2uh5jAi) - Banggood 39 | * [Jumper Wires Male-Female / Cables puente Macho-Hembra ](http://bit.ly/2KK4F9s) - Banggood 40 | * [Jumper Wires Male-Male / Cables puente Macho-Macho](http://bit.ly/2N7MZSb) - Banggood 41 | * [Jumper Wires Female-Female / Cables puente Hembra-Hembra ](http://bit.ly/2L7HxOn) - Banggood 42 | * [1 MicroSD 8GB Card](https://www.raspberrypi.org/documentation/installation/installing-images/) - with Raspbian OS Installed 43 | 44 | 45 | ## Mounting / Montaje 46 | 47 | * Raspberry Pi 3 Model B 48 | 49 | ![alt text](http://pdacontroles.com/wp-content/uploads/2018/07/RASPBERRY-PI-CONECTADO.jpg "mounting") 50 | 51 | 52 | # Documentation / Documentación 53 | * Read Considerations, Recommendations and Suggestions complete documentation of the project in [Meter PZEM-004T with Arduino ESP32 ESP8266 Python & Raspberry Pi](http://pdacontrolen.com/meter-pzem-004t-with-arduino-esp32-esp8266-python-raspberry-pi/). 54 | 55 | * Leer Consideraciones, Recomendaciones y sugerencias documentacion Completa del proyecto en [Medidor PZEM-004T con Arduino ESP32 ESP8266 Python & Raspberry Pi](http://pdacontroles.com/medidor-pzem-004t-con-arduino-esp32-esp8266-python-raspberry-pi/). 56 | 57 | # Donations / Donaciones 58 | Collaborate this project and other projects in [PDAControl](http://pdacontrolen.com) via [Paypal](https://www.paypal.me/pdacontrol). 59 | 60 | Respalde este proyecto y otros proyectos en [PDAControl](http://pdacontrolen.com) mediante [Paypal](https://www.paypal.me/pdacontrol). 61 | 62 | [![Support via PayPal](https://cdn.rawgit.com/twolfson/paypal-github-button/1.0.0/dist/button.svg)](https://www.paypal.me/pdacontrol) 63 | 64 | # More about PDAControl / Mas sobre PDAControl 65 | * [PDAControl English](http://pdacontrolen.com). 66 | * [PDAControl Español](http://pdacontroles.com). 67 | * [PDAControl Youtube Channel](https://www.youtube.com/channel/UCv1D6zrC0ZL0PSgM6tdEpPg/videos). 68 | * [Jhon_Control Twitter](https://twitter.com/Jhon_Control). 69 | 70 | -------------------------------------------------------------------------------- /PZEM_Python/PZEM-004-python.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | #coding=utf-8 3 | 4 | # Code by Massi from https://www.raspberrypi.org/forums/viewtopic.php?t=124958#p923274 5 | 6 | 7 | # PDAControl 8 | # Documentation PDAControl English: 9 | # http://pdacontrolen.com/meter-pzem-004t-with-arduino-esp32-esp8266-python-raspberry-pi/ 10 | # Documentacion PDAControl Español: 11 | # http://pdacontroles.com/medidor-pzem-004t-con-arduino-esp32-esp8266-python-raspberry-pi/ 12 | # Video Tutorial : https://youtu.be/qt32YT_1oH8 13 | 14 | 15 | import serial 16 | import time 17 | import struct 18 | 19 | class PZEM: 20 | 21 | setAddrBytes = [0xB4,0xC0,0xA8,0x01,0x01,0x00,0x1E] 22 | readVoltageBytes = [0xB0,0xC0,0xA8,0x01,0x01,0x00,0x1A] 23 | readCurrentBytes = [0XB1,0xC0,0xA8,0x01,0x01,0x00,0x1B] 24 | readPowerBytes = [0XB2,0xC0,0xA8,0x01,0x01,0x00,0x1C] 25 | readRegPowerBytes = [0XB3,0xC0,0xA8,0x01,0x01,0x00,0x1D] 26 | 27 | 28 | # dmesg | grep tty list Serial linux command 29 | 30 | def __init__(self, com="/dev/ttyUSB0", timeout=10.0): # Usb serial port 31 | #def __init__(self, com="/dev/ttyAMA0", timeout=10.0): # Raspberry Pi port Serial TTL 32 | #def __init__(self,com="/dev/rfcomm0", timeout=10.0): 33 | 34 | 35 | self.ser = serial.Serial( 36 | port=com, 37 | baudrate=9600, 38 | parity=serial.PARITY_NONE, 39 | stopbits=serial.STOPBITS_ONE, 40 | bytesize=serial.EIGHTBITS, 41 | timeout = timeout 42 | ) 43 | if self.ser.isOpen(): 44 | self.ser.close() 45 | self.ser.open() 46 | 47 | def checkChecksum(self, _tuple): 48 | _list = list(_tuple) 49 | _checksum = _list[-1] 50 | _list.pop() 51 | _sum = sum(_list) 52 | if _checksum == _sum%256: 53 | return True 54 | else: 55 | raise Exception("Wrong checksum") 56 | 57 | def isReady(self): 58 | self.ser.write(serial.to_bytes(self.setAddrBytes)) 59 | rcv = self.ser.read(7) 60 | if len(rcv) == 7: 61 | unpacked = struct.unpack("!7B", rcv) 62 | if(self.checkChecksum(unpacked)): 63 | return True 64 | else: 65 | raise serial.SerialTimeoutException("Timeout setting address") 66 | 67 | def readVoltage(self): 68 | self.ser.write(serial.to_bytes(self.readVoltageBytes)) 69 | rcv = self.ser.read(7) 70 | if len(rcv) == 7: 71 | unpacked = struct.unpack("!7B", rcv) 72 | if(self.checkChecksum(unpacked)): 73 | tension = unpacked[2]+unpacked[3]/10.0 74 | return tension 75 | else: 76 | raise serial.SerialTimeoutException("Timeout reading tension") 77 | 78 | def readCurrent(self): 79 | self.ser.write(serial.to_bytes(self.readCurrentBytes)) 80 | rcv = self.ser.read(7) 81 | if len(rcv) == 7: 82 | unpacked = struct.unpack("!7B", rcv) 83 | if(self.checkChecksum(unpacked)): 84 | current = unpacked[2]+unpacked[3]/100.0 85 | return current 86 | else: 87 | raise serial.SerialTimeoutException("Timeout reading current") 88 | 89 | def readPower(self): 90 | self.ser.write(serial.to_bytes(self.readPowerBytes)) 91 | rcv = self.ser.read(7) 92 | if len(rcv) == 7: 93 | unpacked = struct.unpack("!7B", rcv) 94 | if(self.checkChecksum(unpacked)): 95 | power = unpacked[1]*256+unpacked[2] 96 | return power 97 | else: 98 | raise serial.SerialTimeoutException("Timeout reading power") 99 | 100 | def readRegPower(self): 101 | self.ser.write(serial.to_bytes(self.readRegPowerBytes)) 102 | rcv = self.ser.read(7) 103 | if len(rcv) == 7: 104 | unpacked = struct.unpack("!7B", rcv) 105 | if(self.checkChecksum(unpacked)): 106 | regPower = unpacked[1]*256*256+unpacked[2]*256+unpacked[3] 107 | return regPower 108 | else: 109 | raise serial.SerialTimeoutException("Timeout reading registered power") 110 | 111 | def readAll(self): 112 | if(self.isReady()): 113 | return(self.readVoltage(),self.readCurrent(),self.readPower(),self.readRegPower()) 114 | 115 | def close(self): 116 | self.ser.close() 117 | 118 | 119 | 120 | if __name__ == "__main__": 121 | sensor = PZEM() 122 | try: 123 | 124 | print("Checking readiness") 125 | print(sensor.isReady()) 126 | print("Reading voltage") 127 | print(sensor.readVoltage()) 128 | print("Reading current") 129 | print(sensor.readCurrent()) 130 | print("Reading power") 131 | print(sensor.readPower()) 132 | print("reading registered power") 133 | print(sensor.readRegPower()) 134 | print("reading all") 135 | print(sensor.readAll()) 136 | finally: 137 | sensor.close() -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Test Meter PZEM-004T with Arduino ESP32 ESP8266 Python & Raspberry Pi 2 | 3 | Date 11-07-2018 [PDAControl](http://pdacontrolen.com) 4 | 5 | ![alt text](http://pdacontroles.com/wp-content/uploads/2018/07/bangood-pzem-004t.png "PZEM-004t Portada") 6 | 7 | ## Description / Descripción 8 | 9 | In this opportunity we will collect tests with my new electric consumption meter **PZEM-004T** by Peacefair and **Arduino IDE** making integrations with some of the most known hardware platforms **ESP8266, Arduino Nano, ESP32, Arduino UNO + Shield Ethernet W5100 and Python in Raspberry Pi**. 10 | 11 | Contains 5 Folders: 12 | 13 | En esta oportunidad recopilaremos pruebas con mi nuevo medidor de consumo eléctrico **PZEM-004T** de Peacefair y **Arduino IDE** realizando integraciones con algunas de las plataformas de hardware mas conocidas **ESP8266, Arduino Nano,ESP32, Arduino UNO + Shield Ethernet W5100 y Python en Raspberry Pi** . 14 | 15 | Contiene 5 Carpetas: 16 | 17 | * [**PZEM_ArduinoNANOSoftSerial** ](https://github.com/JhonControl/PZEM-004t-basic-ESP32-Arduino-ESP8266-Python-RPi/tree/master/PZEM_ArduinoNANOSoftSerial) : Example **Arduino Nano** with Arduino IDE 18 | * [**PZEM_ArduinoUNO-ETHSoftSerial** ](https://github.com/JhonControl/PZEM-004t-basic-ESP32-Arduino-ESP8266-Python-RPi/tree/master/PZEM_ArduinoUNO-ETHSoftSerial) : Example **Arduino UNO + Shield Ethernet W5100** with Arduino IDE 19 | * [**PZEM_ESP32HwSerial** ](https://github.com/JhonControl/PZEM-004t-basic-ESP32-Arduino-ESP8266-Python-RPi/tree/master/PZEM_ESP32HwSerial) : Example **ESP32** with Arduino IDE 20 | * [**PZEM_ESP8266HwSerial** ](https://github.com/JhonControl/PZEM-004t-basic-ESP32-Arduino-ESP8266-Python-RPi/tree/master/PZEM_ESP8266HwSerial) : Example **ESP8266** with Arduino IDE 21 | * [**PZEM_Python** ](https://github.com/JhonControl/PZEM-004t-basic-ESP32-Arduino-ESP8266-Python-RPi/tree/master/PZEM_Python) : Example **Python** for Computer or Raspberry Pi 22 | 23 | 24 | 25 | ## Library / Librerias 26 | 27 | * [**PZEM004T.h** ](https://github.com/olehs/PZEM004T) - Arduino communication library for **Peacefair PZEM-004T Energy **. 28 | 29 | Thanks [olehs](https://github.com/olehs) for contributing 30 | 31 | 32 | 33 | # Materials / Materiales 34 | 35 | * [1 PZEM-004T Peacefair](https://bit.ly/2HPyVJL) - Banggood 36 | * [1 ESP8266 12E NodeMCU](http://bit.ly/2uni5Nz) - Banggood 37 | * [1 ARDUINO Nano V3 ](http://bit.ly/2uopXi5) - Banggood 38 | * [Shield/PCB Arduino-OTA V1.0](http://pdacontrolen.com) - Optional 39 | * [1 ESP32 DEVKIT V1 Doit](http://bit.ly/2zuUGje) - Banggood 40 | * [1 Arduino UNO + Shield Ethernet W5100](https://bit.ly/2leWqDr) - Banggood 41 | * [1 Raspberry Pi 3 Model B + ](http://bit.ly/2NKRnaO) - Banggood 42 | * [1 FTDI TTL to USB Serial Converter](http://bit.ly/2ujroOI) - Banggood 43 | * [1 MicroSD 8GB Card](https://www.raspberrypi.org/documentation/installation/installing-images/) - with Raspbian OS Installed 44 | * [2 Breadboard / Protoboard 8.5 x 5.5cm 400 Points](http://bit.ly/2uant7G) - Banggood 45 | * [1 2N2907 TO-92 or similar PNP](https://global.oup.com/us/companion.websites/fdscontent/uscompanion/us/pdf/microcircuits/students/bjt/2N2907-motorola.pdf) - transistor PNP 46 | * [1 Power Supply 5V 2A](http://bit.ly/2uh5jAi) - Banggood 47 | * [Jumper Wires Male-Female / Cables puente Macho-Hembra ](http://bit.ly/2KK4F9s) - Banggood 48 | * [Jumper Wires Male-Male / Cables puente Macho-Macho](http://bit.ly/2N7MZSb) - Banggood 49 | * [Jumper Wires Female-Female / Cables puente Hembra-Hembra ](http://bit.ly/2L7HxOn) - Banggood 50 | 51 | 52 | # Mounting / Montajes 53 | 54 | ### PZEM-004t with ESP8266 12E NodeMCU 55 | 56 | ![alt text](http://pdacontroles.com/wp-content/uploads/2018/07/SERIAL-ESP8266.png "mounting") 57 | 58 | ### PZEM-004t with Arduino Nano "Ard-Nano" 59 | 60 | ![alt text](http://pdacontroles.com/wp-content/uploads/2018/07/SERIAL-ARDUINO-NANO.png "mounting") 61 | 62 | ### PZEM-004t with ESP32 DEVKIT 63 | 64 | ![alt text](http://pdacontroles.com/wp-content/uploads/2018/07/SERIAL-ESP32.png "mounting") 65 | 66 | ### PZEM-004t with Arduino UNO + Shield Ethernet W5100 67 | 68 | ![alt text](http://pdacontroles.com/wp-content/uploads/2018/07/Serial-Arduino-ETH.png "mounting") 69 | 70 | ### PZEM-004t with Raspberry Pi 3 Model B using Python 71 | 72 | ![alt text](http://pdacontroles.com/wp-content/uploads/2018/07/SERIAL-RASPBERRY-PI-PYTHON.png "mounting") 73 | 74 | 75 | 76 | # Documentation / Documentación 77 | * Read Considerations, Recommendations and Suggestions complete documentation of the project in [Meter PZEM-004T with Arduino ESP32 ESP8266 Python & Raspberry Pi](http://pdacontrolen.com/meter-pzem-004t-with-arduino-esp32-esp8266-python-raspberry-pi/). 78 | 79 | * Leer Consideraciones, Recomendaciones y sugerencias documentacion Completa del proyecto en [Medidor PZEM-004T con Arduino ESP32 ESP8266 Python & Raspberry Pi](http://pdacontroles.com/medidor-pzem-004t-con-arduino-esp32-esp8266-python-raspberry-pi/). 80 | 81 | # Donations / Donaciones 82 | Collaborate this project and other projects in [PDAControl](http://pdacontrolen.com) via [Paypal](https://www.paypal.me/pdacontrol). 83 | 84 | Respalde este proyecto y otros proyectos en [PDAControl](http://pdacontrolen.com) mediante [Paypal](https://www.paypal.me/pdacontrol). 85 | 86 | [![Support via PayPal](https://cdn.rawgit.com/twolfson/paypal-github-button/1.0.0/dist/button.svg)](https://www.paypal.me/pdacontrol) 87 | 88 | # More about PDAControl / Mas sobre PDAControl 89 | * [PDAControl English](http://pdacontrolen.com). 90 | * [PDAControl Español](http://pdacontroles.com). 91 | * [PDAControl Youtube Channel](https://www.youtube.com/channel/UCv1D6zrC0ZL0PSgM6tdEpPg/videos). 92 | * [Jhon_Control Twitter](https://twitter.com/Jhon_Control). 93 | 94 | --------------------------------------------------------------------------------