pzem-004t returns NaN values

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
bart.butenaers
New user
Posts: 9
Joined: 11 Nov 2023, 07:50

pzem-004t returns NaN values

#1 Post by bart.butenaers » 11 Nov 2023, 09:53

Hi everybody,

My first post in this community...

I want to measure the energy of my home via pzem-004t devices connected to a wt32-eth01. But it returns NaN for all measured values:

Image

Note that currently my clamp is not around any AC main wire, but I assume I should get 0 values in this case?

When I change the data acquisition interval of my device in EspEasy:

Image

Then the LED D3 starts flashing at the same interval (and meanwhile the LED D3 is always fixed ON). So I assume that the data communication from the wt32-eth01 towards the pzem-004t is ok?

Image

But the LED D2 is always OFF, so I assume the pzem-004t isn't responding any resonse back to the wt32-eth01 resulting in NaN values?
Not sure if this is because I have used address 1 for this pzem-004t device (because 0 seems to be the broadcast address):

Image

I have nowhere configured this pzem-004t device to have address 1, so not sure whether/where I should do that.
This will be important when I add later on extra pzem-004t devices to the same ModBus...

Or perhaps my wiring between the wt32-eth01 and the pzem-004t is not correct:

Image

I have added the diodes and the pullup resistor, because I was adviced in another community to do it like that, because I want to connect multiple pzem-004t devices to the same serial interface gpio ports of my wt32-eth01. But currently only 1 pzem-004t is connected this way.

Thanks!!!
Bart

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: pzem-004t returns NaN values

#2 Post by TD-er » 11 Nov 2023, 10:18

I suggest to use diferent pins as both GPIO-2 and -4 have an internal pull-down resistor.
See: https://espeasy.readthedocs.io/en/lates ... e-on-esp32
Just use pins > GPIO-12 and keep in mind GPIO-34 and up are input-only.

Since your board also has Ethernet, some pins cannot be used. See: https://espeasy.readthedocs.io/en/lates ... hernet-phy

Another tip is to not use Software Serial as you have 3 hardware serial ports on an ESP32.

And why do you have zener diodes on the TX pins of the PZEM sensors?
They do cause drop in voltage leaving not much for the signal to be detected.

User avatar
Ath
Normal user
Posts: 3522
Joined: 10 Jun 2018, 12:06
Location: NL

Re: pzem-004t returns NaN values

#3 Post by Ath » 11 Nov 2023, 13:29

bart.butenaers wrote: 11 Nov 2023, 09:53 I have added the diodes and the pullup resistor, because I was adviced in another community to do it like that,
Not sure what they are trying to make you do there, as those diodes (what voltage let they pass through?) effectively block any signal to flow to the ESP. First test a single device (as you are doing) with only a pull-up resistor, and use HWSerial1 or HWSerial2 and different pins as TD-er suggested (that will keep HWSerial0 available for console logging).
/Ton (PayPal.me)

bart.butenaers
New user
Posts: 9
Joined: 11 Nov 2023, 07:50

Re: pzem-004t returns NaN values

#4 Post by bart.butenaers » 11 Nov 2023, 21:25

@TD-er,
Thanks for joining (so fast...)!

Ok I will try some other ports. Unfortunately there are not a lot of gpio pins available on a wt32-eth01:

Image

I had used the software serial interface, because I assumed (from the red text in the user interface) that that was preferred if you want to read multiple pzem-004t devices:

Image

So appearantly I have somehow misinterpreted that warning.

@Ath,
Good question. Since I am a Node-RED contributor, I had also discussed this on the Node-RED community. And there I got the advice to use diodes:
https://discourse.nodered.org/t/3-phase ... /68489/163

Somebody else used a level shifter, to make sure the 3.3V gpio's of the esp are not damaged by the 5V signals from the pzem-004t. But others advised to use diodes. There are other examples on the web (e.g. in the EspHome repo) where they also use diodes. Very weird that their setups work fine, while I understand from your explanation that it cannot work. But I have to admit that I am far from an electronics specialist, so I don't know whether I need the diodes or not. If I don't need that, that would be better because it simplifies my setup...

I will do some extra tests, and get back here.

User avatar
Ath
Normal user
Posts: 3522
Joined: 10 Jun 2018, 12:06
Location: NL

Re: pzem-004t returns NaN values

#5 Post by Ath » 11 Nov 2023, 21:51

The setup with the diodes can work if these diodes point in the right direction, but in the schema you've shown they point in the wrong direction... (AFAICS) These diodes only seem to be used to lower the signal voltage, so a level shifter could be a proper solution too.
I haven't used these devices myself (yet) so can't tell from experience :shock:

The message about the HW serial vs the SW serial is based on ESP8266, that only has HWSerial0 and HWSerial0 swap, that uses different pins but still is using Serial0, so the console port can't be used. This message should be disabled for ESP32.
/Ton (PayPal.me)

bart.butenaers
New user
Posts: 9
Joined: 11 Nov 2023, 07:50

Re: pzem-004t returns NaN values

#6 Post by bart.butenaers » 11 Nov 2023, 22:06

@ath,
Ah yes indeed you are right. In our Node-RED discussion afterwards somebody explained that the diodes in the diagram needed to be installed in the other direction (and explained why):
https://discourse.nodered.org/t/3-phase ... tbutenaers
I had totally forgotten about that. Thanks for reminding me about this!!

And again yes, the message in the user interface is quite confusing when using an ESP32. But I will write it down in my step-by-step notes. Thanks again for this one!!

I will solder my diode in the right direction first before continuing...

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: pzem-004t returns NaN values

#7 Post by TD-er » 11 Nov 2023, 22:15

Ah yep that warning in red is utterly confusing.

bart.butenaers
New user
Posts: 9
Joined: 11 Nov 2023, 07:50

Re: pzem-004t returns NaN values

#8 Post by bart.butenaers » 11 Nov 2023, 23:34

I have done some changes, but still NaN values:

Image

This is what I tried:
  • Changed software serial to HW serial 1
  • Used other gpio ports (gpio14 and gpio15)
  • Reversed the diode
  • Tried with and without the external pull-up resistor
What I don't really get is the behaviour of the LED's on the pzem-004t:
  • LED D3: is continiously shining, and start flashing extra when the EspEasy data acquisition interval is reached
  • LED D2: doesn't shine or flash at all
When watching the following youtube video (starting from 26m40s) the LED's are off, and only flash both simultaneously at the data acquisition interval:

https://youtu.be/qRsjsenvlJA?si=LLMmUDI ... d&t=26m40s

Does anybody have any idea what could cause this? I assume I have done something wrong, since it works fine for other users...

Do I need to do something special to assign address 0x01 to this first pzem-004t module? If yes, how can I do that? Perhaps the module doesn't returen anything, because it has another address?

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: pzem-004t returns NaN values

#9 Post by TD-er » 11 Nov 2023, 23:57

I have never used those modules myself.
But I know they should be using modbus.
Do you need to set some Modbus address?

Is there a default Modbus address?
Can you try Modbus address 0xFF (255 decimal) as that's a broadcast Modbus address.

bart.butenaers
New user
Posts: 9
Joined: 11 Nov 2023, 07:50

Re: pzem-004t returns NaN values

#10 Post by bart.butenaers » 12 Nov 2023, 09:57

Morning...
I tried to setup the 0xFF but still NaN values:

Image

I also tried to disable the next setting, but again no luck:

Image

Ah damn, no I see that - in the above pzem actions section of the screen - I have always selected "read_value", but I probably need to set the address value first.
How stupid of me ;-(

The problem is that I cannot test this right now.
Because - since yesterday evening - my wt32-eth01 has become VERY unresponsive.
I currently use it via WIFI (i.e. not via ethernet yet) so I first thought that it was a temporary WIFI issue.
But this morning I have a mix of issues when trying to access it:
  • Totally unresponsive due to timeout issue in my browser
  • At best very slow loading of the UI
  • Sometimes I can see the UI as html without CSS applied:
Image

The LED on my pzem-004t is still flickering at the correct interval so my wt32-eth01 is not dead, it just looks like it is too busy to respond to my ui http requests.
Could this be due to the software serial stuff that I have been doing yesterday?
I mean that it somehow is still doing a lot of (unnecessary) calculations behind my back perhaps?
I have no idea whether I can see somewhere what he is doing right now...

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: pzem-004t returns NaN values

#11 Post by TD-er » 12 Nov 2023, 11:44

You could also flash a blank bin file over it and start over, if you can't get it to respond long enough to do a factory reset.

The serial console only outputs to Serial0, so if you're using any other serial port it won't make a difference.

The note stated in your screenshot regarding the modbus address mentioned the 'broadcast' address is 0 for this module, so you can also try that.

But I have to say that this plugin (and perhaps its documentation) is heavily outdated as all remarks and notes seem to be specific to ESP8266 and not ESP32.
So that needs to be looked at for sure as this is really hard to debug when a user tries to follow exactly the given directions but the directions are outdated. (so by no means your fault)

Can you give commands via a serial console?
If so, please try to disable the task for the PZEM.
Like if it is task 1: taskdisable,1
Then the web interface may be responsive again.

Or you can create a web URL to give this command and try several times until it is responsive again.
For example:
http://192.168.10.190/tools?cmd=taskdisable%2C1

The 1 at the end is the task index
And you need to replace the IP address of course

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: pzem-004t returns NaN values

#12 Post by chromo23 » 13 Nov 2023, 12:14

bart.butenaers wrote: 12 Nov 2023, 09:57 Ah damn, no I see that - in the above pzem actions section of the screen - I have always selected "read_value", but I probably need to set the address value first.
How stupid of me ;-(
Just got a couple of pzem-004t v3

It seems you have to set a device address initially!!!
Important:
For setting up the device (especially for setting an address) the device needs to be powered through the high-voltage side!!!!

1. downloaded latest energy build
2. enable the device; set pins for HW Serial(1) (e.g.: 19 -> TX; 18 -> RX)
3. Set "PZEM Mode" to "Program_adress"
4. Hit "submit"
5. Set "Confirm address programming ?:" to "YES" ; Enter a number in "Address of PZEM" (see screenshot)
6. Hit "submit"

The device now should transmit data

EDIT: i didn´t use a resistor nor a diode

pzem.png
pzem.png (45.11 KiB) Viewed 3528 times
EDIT2: I am really surprised how accurate this thing is :)

bart.butenaers
New user
Posts: 9
Joined: 11 Nov 2023, 07:50

Re: pzem-004t returns NaN values

#13 Post by bart.butenaers » 13 Nov 2023, 22:31

Hi @chromo23,

Ah that is a good tip. Really appreciate your feedback!
I will try this in a couple of days from now. Need to find some free time first ;-)

bart.butenaers
New user
Posts: 9
Joined: 11 Nov 2023, 07:50

Re: pzem-004t returns NaN values

#14 Post by bart.butenaers » 13 Nov 2023, 22:51

When looking at the esphome wiki:
https://esphome.io/components/sensor/pzemac.html#

I see a very important warning:
Please note that metering chip inside of PZEM module is powered from AC side and it has to be on during startup of ESPHome device, othervise measure results won’t be visible.

Damn, damn, ...
I had assumed that the entire pzem-004t electronics was powered by the 5V which you need to apply via its white jst-xh2.54 connector. As a result and because I wanted to create quick (not...) setup to experiment, I had not connected AC wiring to its terminal block. Because - like I had mentioned in my original post - I assumed that in this case I would simply measure 0 values, which would have been more than enough for my first expiment I thought.

Seems that my both assumptions were completely incorrect. And yes I know: assumption is the mother of all ...

If I get this running, I owe to you guys a nice step-by-step tutorial :-)

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: pzem-004t returns NaN values

#15 Post by TD-er » 13 Nov 2023, 23:34

bart.butenaers wrote: 13 Nov 2023, 22:51 [...]
If I get this running, I owe to you guys a nice step-by-step tutorial :-)
Can we have this in writing? ;)
Literally of course :)

bart.butenaers
New user
Posts: 9
Joined: 11 Nov 2023, 07:50

Re: pzem-004t returns NaN values

#16 Post by bart.butenaers » 13 Nov 2023, 23:39

After a quick test I can confirm a couple of things:
  • After programming the address, the EspEasy user interfaces shows a green text "Address programming is done". However that does not mean that it is really done, because the first time I forgot the attach again the wires to my pzem-004t, and the text still appeared. So this text only means that some programming sequence has been executed, but it gets no acknowledge from the pzem-004t about it.
  • Like @chromo23 mentioned, it is not enough to program the address (without AC main wiring) because the TX led is still not flashing on the pzem-004t (so no data is returned).
  • So I attached the AC main wires to my pzem-004t, and then an extra LED near the terminal jack starts burning. When I program now again the address of my pzem-004t, then it looks like it starts to respond on the request from EspEasy: at an interval of 10 seconds the RX led of my pzem-004t starts flashing, because it receives a request from EspEasy. And now immediately afterwards the TX led of my pzem-004t starts flashing, because it responds since it has the specified address.
But when I wanted to have a look at my values, my user interface has become unresponsive again.
Very weird. Last night I have installed EspEasy from scratch again on my wt32-eth01.
And when I was doing my test without the pzem-004t being connected, the user interface was pretty fast.
After restarting my wt32-eth01 it doesn't respond anymore.
Both RX and TX leds on my pzem-004t are not flashing anymore, so I assume my wt32-eth01 is pretty died at the moment ;-(
My (free) time is up for today...

bart.butenaers
New user
Posts: 9
Joined: 11 Nov 2023, 07:50

Re: pzem-004t returns NaN values

#17 Post by bart.butenaers » 14 Nov 2023, 23:14

Ok, again a bit further:
  • For some reason the wt32-eth01 user interface kept being very unresponsive when the pzem-004t was attached to it. Still no clue why. But I managed to get the ethernet connection running (via my ...ENERGY...ETH build), and wired via a CAT cable the UI works like a charm.
  • After setting yesterday the unique address on my pzem-004t module, it seems I forgot to set the original "read value" dropdown option again (so the tx/rx leds on my pzem-004t were not flashing anymore):
Image
  • For some reason the formulat fields were empty, so I entered everywhere "%value%" but not sure if that is correct???
Image

But still Nan values :-(

Can I verify somehow which values arrive on my wt32-eth01? Because I am not sure whether no data is returned, or whether data is returned but I e.g. use the incorrect formula's to parse that data...

And also not sure whether the warning symbol has something to do with not receiving any data?

Image

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: pzem-004t returns NaN values

#18 Post by TD-er » 14 Nov 2023, 23:26

See this table:
https://espeasy.readthedocs.io/en/lates ... e-on-esp32
GPIO-15 does have a pull-up resistor.
So you can't use it for all use cases.

Post Reply

Who is online

Users browsing this forum: No registered users and 31 guests