Skip to content

GavSun/PZEM004Tr4

Repository files navigation

Reading the PZEM-004Tv4 using RPi Pico2/Pico2W

In this project, the Rpi-PICO2W board is used to interface with the electrical energy / power monitoring module PZEM-004Tv4. The PZEM-004Tv4 measures the electrical quantities of a sigle phase electric supply line which includes: AC Voltage, Current, Power, Power Factor, Frequency, Energy. On the PZEM-004Tv4 board, the electrical measurement section and the data communication HW are electrically isolated. That makes interfacing it with Rpi Pico/2/w safe. (Safe from isolation point of view only. But working with such modules, which are connected to AC supply, needs lot precuations and use of safe handling practices to prevent dangerous electrical shock.)

Physical interfacing:

The physical interface is simple. The PZEM-004T module require connecting only 4 wires: Vcc, Gnd, TxD, RxD. The PZEM module accepts 5V or 3.3V for Vcc. The TxD and RxD lines are TTL level UART communication interface lines. From the Pico2W board - the UART 1 is used to interface with PZEM-004Tv4.

Software interface:

Though the physical interface is over TTL level UART lines, but the protocol provide on PZEM-004T is modbus-RTU. Baudrate: 9600, Data format: Databits: 8, StopBit: 1, No parity.

Refer the datasheet/user manual, provided in the documents folder, which cover the various commands supported by the PZEM-004T(but v3 and not v4) and it's response to those commands. The communication between PICO2W and PZEM-004tv4 is using only 3 commands:

  1. Pico initialises the PZEM-004T. (First PICO sets it's own UART for the required baud rate and data frame requirements of PZEM-004T, and then initialise it).
  2. Set's the slave address of PZEM-004tv4 as modbus-rtu protocol is to used.
  3. Finally reads the electrical parameters, at continuous interval, as measured by PZEM-004Tv4.

Firmware implementation:

The important code, to handle communication with PZEM-004Tv4, is covered by below mentioned files:

The purpose of main.c is only to read and print the electrical parameters from pzem-004tv4 using above mentioned 3 files.

Tools / Development environment:

Raspberri Pi Pico 2 W, VSCode, pico sdk 2.2

About

Monitor the AC power supply line parameters : Voltage, Current, PF, Power, Energy & PF

Topics

Resources

Stars

Watchers

Forks