HELP! PZEM-017 and D1 Mini 32 ESP32 Clone Setup

My information is that the mini boards are only GPIO 3.3V and this is a mini board. I have the same here. Try using GPIO 21, 22 (D1, D2).
There is a danger that you will destroy 5V GPIO. It may not be immediate, but over time it will.

1 Like

So I should put the logic level shifter between the RS232 to TTL board and the Mini esp32, correct?

Yes correct. I also have a PZEM-017 and I am measuring the current coming into the battery. The second measurement is the current coming from the battery. I don’t have D1mini32 but only D1mini 8266
reg
What you still have with the RS232 board, you need RS485-TTL

So this would be the complete diagram, correct?

Oops! Looks like the level shifter needs HV and LV. Here’s the updated diagram:

For the board in OP’s picture, you want D1 TX to 485 TX and D1 RX to 485 RX. The boards are labeled weird. Also you probably want a 120 Ohm resistor across A and B. See my post Alpine Boiler with ESPHome Modbus Sucess

you can power the rs485 with 5 volts.

Thank you for the tip about the TTL to UART module. If I connected a resistor in parallel to A and B on the converter, instead of down the wire an inch or so, would that solve the issue of reflection, or would that be too close?

As for the TX and RX…are you saying the TTL to UART module is incorrectly labelled? I’m using the Mini ESP32, which is not the D1 Mini in the original picture with the first post.

Mine is only down a couple mm from the terminals on the stripped wire end, but not directly across the terminal. I guess try and see if it helps. It was necessary for me, but I am connecting to a different device than you.

Yes, if you have the TTL 485 board in the picture, it is mislabeled according to the standard convention. The TX goes to the ESP TX and the RX to the ESP RX. Shouldn’t matter what ESP board you have. In this youtube video at the 2:30 mark, a guy explains it. UART To RS-485 Interface / Pro Mini / LoRa Interface - YouTube

Good luck

1 Like

An interesting idea with a 120 ohm resistor between the A + B terminals of the converter. Mine works without it well see the measurement entities in the picture.

I should be receiving the level shifter today, but shouldn’t the pzem-017 work with the ttl to uart adapter without it, even if it’s not the right level???

Do as you think. I just suggested how it works on my D1mini without a problem for more than a year.

OK, I hooked up everything and I’m still getting "Entity is Non-numeric ", and I even tried a different uart, but that gave more problems.

Maybe it’s my sensor setup. Did you configure anything differently??

You tried to switch Tx, Rx. Just do it in the configuration

I have it this way

uart:
  tx_pin: D1
  rx_pin: D2
  baud_rate: 9600
  stop_bits: 2

I tried connecting to a different set of pins designed for uart. The esp32 supposedly has 3 sets. The tx pin on pin 9 made the WiFi stop working when installed in the software, but pin10 which is rx was fine, but I switched it to both the tx and rx pins of the ttl to uart adapter. Everything resulted in the entity is non-numeric error. I even tried the resistor trick, still nothing.

I ordered some esp8266’s and a nodemcu esp32 to see if I can make anything different happen with everyone else’s known configurations.

I still would like to know if the code you used was dissimilar to the example for the pzem-017 example on the earphone website, or if you configured the sensor in a special way. Thanks!

I used an example from the ESPhome documentation

Connect pins IO22 and IO21 (D1, D2) as Tx pin D1 to TTL converter to Tx and Rx pin D2 to TTL to Rx. The TTL board is probably incorrectly marked

Found the solution! Turns out the pinout I had was not complete, and on the ESP32 there is a 3rd UART pair: Pins 16 (RX) and 17 (TX). Through a level shifter, I connected the ESP TX and RX to the TTL to UART adapter’s TX and RX (respectively)…yes, TX to TX, and RX to RX. A to A and B to B from the TTL to UART adapter and the PZEM-017. No resistor needed, so far :slight_smile:

According to the ESPHome debugger, the UART1 pair (pin 9 and 10) is used for the programmer and wifi, so that pair is a non-option, and it was causing the ESP32 to go into a bootloop and then safemode…so that’s why I tried the UART2 option, and I’m super glad it worked!

This the fully correct Mini ESP32 pinout:

Here’s the final wiring schematic:

Code was almost exactly what ESPHome recommends, except the pin difference. I hope this helps someone in the future. Take care!

2 Likes

Hello,
I have a similar setup (ESP32 DEVKIT1). I have connected all the boards the same way as described, but I am receiving errors regarding CRC checks:

[17:51:08][W][modbus:121]: Modbus CRC Check failed! 9FBD!=9F32
[17:52:08][W][modbus:121]: Modbus CRC Check failed! 3745!=F610

I have connected the board on the UART2 (GPIO17 for TX and GPIO16 for RX). I have bought another pair of UART adapter and logic sifter, but the same issue… Does anyone know, what could be the issue?

Many thanks.

Hi, I’m in the same situation. Setup with ESP-wroom-32, worked for about half a year and after updating Esphome sometime in December 2022, CRC errors started to increase. A correct value appears here and there, but only exceptionally. I haven’t found a solution yet :confused: