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

I have searched high and low for an answer to this one, so hopefully someone can help educate my n00b brain:

I have a Battery connected to my solar panel array, via charge controller, and I would like to hookup an energy meter to it (PZEM-017) which has support in ESPHome. I understand that the PZEM-017 doesn’t have UART output, so I have also purchased a TTL to RS485 converter and have connected the PZEM-017 to my D1 Mini32 Clone per this diagram:

This is the code I’m using for the device:

> esphome:
>   name: packva
> 
> esp32:
>   board: esp32dev
>   framework:
>     type: arduino
> 
> # Enable logging
> logger:
> #  level: none
>   baud_rate: 0
>   
> # Enable Home Assistant API
> api:
> 
> ota:
>   password: ***
> 
> wifi:
>   ssid: !secret wifi_ssid
>   password: !secret wifi_password
> 
>   # Enable fallback hotspot (captive portal) in case wifi connection fails
>   ap:
>     ssid: "Packva Fallback Hotspot"
>     password: ***
> 
> captive_portal:
> 
> uart:
>   id: uart0
>   tx_pin: GPIO1
>   rx_pin: GPIO3
>   baud_rate: 9600
>   stop_bits: 2
> 
> sensor:
>   - platform: pzemdc
>     current:
>       name: "PackCurrent"
>       #id: dc_current
>     voltage:
>       name: "PackVoltage"
>       #id: dc_voltage
>     power:
>       name: "PackPower"
>       #id: dc_power
>     update_interval: 1s

And the result I’m getting from the enabled entity in Lovelace is “Entity is non-numeric”

Am I missing something obvious? Is the PZEM-017 broken?

Thank you for any of your help and responses in advance :slight_smile:

1 Like

I use a D1 mini 8266 and a 5V / 3.3V level converter, because the output of the converter rs485 is 5V and the D1 mini to GPIO is only 3.3V.
I don’t understand the Entity is non-numeric?
I use GPIO5 (D1) and GPIO4 (D2)

1 Like

I’m powering the esp32 with a usb plug, and passing 5v to the rs232 to ttl adapter and the PZEM-017. Should I be sending those devices 3.3v from the esp32 instead?

PZEM-017 needs 5V power supply, otherwise it will not work. My solution is to insert a 5V / 3.3V level converter between Tx and Rx and D1 mini

Don’t forget to connect Tx rs485 - Rx D1 mini and Rx rs485 - Tx D1 mini

I am supplying the PZEM-017 5v from the esp32 (in parallel with the RS232 to TTL adapter from the usb pin of the esp32). Do I still need the logic level shifter for the data?

I am connecting the TX to RX and RX to TX appropriately from the esp32 to the RS232 to TTL adapter

Yes you need because there is 5V on the converter.
If you are using an rs232 converter it will not work. You need an rs485 converter

If you use nodemcu8266 instead of D1 mini, no level converter is needed because nodemcu is tolerant to 5V on GPIO. This is also written in the manual PZEM.

I see the esp32dev board in the configuration. Select d1mini32

I am using this board, which is effectively a d1 mini32, but the listing also says nodemcu, so it’s confusing. I am using this image as a pinout reference

and here’s the info on the board that I know of. Not sure if it is 5v or 3.3v tolerant for gpio: https://github.com/r0oland/ESP32_mini_KiCad_Library

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???