Connecting a PeaceFair Pzem-004T to an Espressif ESP8266


#1

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?

Two reasons:

  1. Teo Swee Ann, CEO of Espressif has gone on record as saying the chips are 5V tolerant.

  2. 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 :slight_smile:

PeaceFair Pzem-004 with 100A Split Core Current Transformer

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.
ESPproMon wiring up the ESP8266 with a trimpot
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.


PeaceFair Pzem-004T Energy Meters
Source for WeMos D1 Mini
About the PeaceFair Pzem-004T category
Provisioning your ESP8266 with our server
#2

Why do we use the PCB trimpots when connecting the Pzem-004T to our WeMos D1 Mini (ESP8266)?

In simple terms it’s for flexibility. The ESPproMon bridge is designed to work with a variety of different energy monitoring systems and some of them operate at 3.3V. The emonTx manufactured by Open Energy Monitor (OEM) is one such system. This means a voltage divider is not required between the monitoring hardware and your ESP8266. So the trimpot would be set at 0 ohms across pins 1 and 2.

If you look closely at the photo in the last post some of you will know that it’s a 10K trimpot. When we ordered our trimpots we wrongly thought the 10K trimpot would give us maximum flexibility for the ESPproMon bridge.

The expectation was to set the trimpot in a 1:2 ratio like you would a voltage divider resistor pair (1K : 2K) to reduce 5V down to 3.3V. So the 10K would be set at 3.3K:6.7K. Wrong, if like us, you do this the current will be too low for the ESP8266 to recognise the TTL signal from the PeaceFair Pzem-004T. So with a 10K trimpot the actual ratio needs to be around 1:9. We have ordered 3K trimpots for our future use and the normal 1:2 ratio should be fine with these.

We have also ordered some bi-directional logic level converters which we will discuss in a future post.

We recommend you “bench test” the ESPproMon bridge before burying it deep inside your electrical consumer unit (ECU). There has been suggestions that locating the ESP8266 right by your main 110 / 240V power lines might cause interference on the TTL lines, necessitating ferrite beads etc.


#3

Where can I order the PCB ? Thanks !


#4

The system can be built without a dedicated PCB but we have them in stock here if you think they would be useful. Maybe one day we will provide a full kit of components for makers to build.

The PCB’s are 3 Euros each plus P + P.

Shoot me a PM with your address if you need a PCB.


#5

A few more details regarding the PCB for connecting a WeMos D1 Mini to your Peacefair Pzem-004T. The PCB we use was designed as a generic board for various WeMos D1 Mini projects and therefore not all connections are used with the ESPproMon, so currently JP5 for example is not used. Partly because we don’t really like soldering but also to make it easy to swap parts in and out we don’t solder most of the components directly to the PCB. We expect you to populate the board with 3 and 8 way female headers and 3 way block terminals. If you prefer to solder the components directly to the board that is your choice.
Peacefair Pzem-004T TTL connections
The 4 way cable that connects from the TTL port on the Pzem to the ESP, marked A, B, C and D in the image above is not using the markings on the cable to indicate which pins it connects to on the ESP. For example the cable with the “+” markings is purely an identifier on the cable and doesn’t relate to the positive (3V3 or 5V) on the ESP. The actual connections are as follows:

  • A = Pzem GND -----> ESP GND
  • B = Pzem VDD -----> ESP 5V
  • C = Pzem RX -------> ESP D7
  • D = Pzem TX -------> ESP D6

In the next post we will provide details for the DS18B20 temperature sensor and the RF transmitter etc.


#6

We use these kind of DS18B20’s and they plug straight into a 3 pin female header on the left hand side of the PCB (marked JP1 on the board but not visible in the photo). Marked as GND, D5 and 3V3 in the photo. The sensor faces outwards from the PCB rather than across the PCB.

ESPproMon DS18B20 and RF Transmitter

There is only one resistor needed on the PCB. R1 is 510 Ohms and is used with the RF transmitter at JP2 in the photo. The RF transmitters are almost always sold as transmitter / receiver pairs and should cost you less than $1.

Again the component faces outwards from the PCB rather than across it and shown as GND, 5V, R1 on the photo. The RF transmitter will work at 3V but you will get better range at 5V. R1 connects to D0 on the PCB (or your WeMos if you are not using the PCB).

If you have any questions about any of the connections please post them here.


#7

If I’m correct these are the right connections :slight_smile:


#8

Yes @Tony they are correct but remember the markings you have on the last image are the connections ON THE PZEM, not the connections you are making to the ESP. The importance of this is simply that the RX and TX are crossed over to the ESP i.e. Pzem RX to ESP TX (D7 GPIO 13) and users choice of putting a voltage divider or not between Pzem TX and ESP RX (D6 GPIO 12).

Are they Peacefair Pzem-004T images from the internet or do you actually have the Pzem with you? I thought you only ordered yours about a week ago?

As an aside is your computer set for English or your native language?


#9

Correct RX/TX crossed. Yes it’s mine … I just received it. Now waiting for your Pcb :slight_smile:

English is indeed set as my native language on my Pc, Why ?


#10

For a few dollars more you could have had the Pzem with the case and LED display. Easier to fit in the consumer unit and an extra point of presentation for the data.

The first Pzem I bought was actually without the case and LED display but then I bought two further full units. Unfortunately you can’t but the case and LED separately.

I’m looking for someone that doesn’t use English on their computer to test out our multilingual facility as per this.


#11

Quick question … does the PZEM provide power to the Wemos D1 via the 5V/GND on the PZEM ?


#12

No it’s the other way round. The ESP is providing power to the TTL port of the Pzem.


#13

“This” shows me Chinese and Taiwanese characters ?


#14

So indeed the Wemos D1 also needs power via it’s USB port for example …


#15

Yes but if you click the globe icon it will translate the post to English or whatever language your computer is using.


#16

Will check this …


#17

That’s correct.


#18

Ok … I have everything hooked up in a test setup. When I start the ESPproMon App it keeps telling me “EspproMon” is offline. I can see that the device is connected to my AP. Is yjis because my license isn’t activated yet (which I will do right now)


#20

I have received your registration details thanks @Tony
Please confirm the following:

You scanned the required QR image.
You created an account on our cloud based server.


#21

Hmmm … I have the App up and running and yes I scanned the QR code. What server are you referring too ? I registered on emocms.org