If you are going to use the flashing tool provided by Espressif please see this post Connecting a PeaceFair Pzem-004T to an Espressif ESP8266 regarding the flash size of your WeMos / NodeMCU.
We will start by saying that in all likelihood you can simply wire the PeaceFair Pzem-004T to the ESP8266 without worrying about the 5V damaging the ESP8266.
Why do we say this when the ESP8266 is a 3.3V device?
Teo Swee Ann, CEO of Espressif has gone on record as saying the chips are 5V tolerant.
Many ESP users, us included, have been wired up to 5V for weeks or months with no apparent harm to the chip.
If you check the forums you are unlikely to find anyone that has had a problem.
OK, now we have got that out of the way let’s drop the voltage down to 3.3V
In this post we are just going to discuss the TTL port shown on the left of the image above.
The Pzem-004T requires a “5V” feed from somewhere to power the TTL port, it’s not taken from the mains 110 / 240V feed that it’s monitoring. Other than a minimum amount of testing we have always taken the 5V from the ESP, which will probably be about 4.7V to 4.8V if you are using a WeMos.
It’s not clear from the image but the 4-way ribbon cable actually has markings on the other side but it would be better if it was colour coded for VDD, RX, TX and GND.
This is a line of code from the firmware bin file:
PZEM004T pzem(12, 13); // RX,TX D6 and D7 VOLTAGE DIVIDER!!!
So it’s using Software Serial on GPIO 12 and 13 (marked D6 and D7 on a WeMos).
GPIO 12 (D6) is receiving data from the Pzem and connected to the port marked TX in the image above.
GPIO 13 (D7) is sending a request to the Pzem to send data and connected to the port marked RX.
Unlike some of the hardware covered elsewhere on this site it is a two way communication, ESP asks for the data and the Pzem sends the data.
Let’s look at ways of dropping the voltage returning to the ESP8266 from the Pzem-004T. It’s only GPIO 12 (D6) that needs protecting as GPIO 13 is sending the request to the Pzem at 3.3V.
You can just use a couple of resistors as a voltage divider (1K from Pzem, 2K to ground and intersection to GPIO 12 (D6) on the ESP8266) but we use a PCB trimpot as shown in the image below.
You should see numbers 1, 2 and 3 marked in yellow by the PCB connector and they match the same numbers on the trimpot. 1 is the TX line from the Pzem, 3 is GND and 2 (the intersection) is to GPIO 12 (D6) on the ESP8266. We will post further details on why we use trimpots later but if you are in any doubt as to how the PeaceFair Pzem-004T connects to the ESP then simply reply to this post.