several PZEM004T to esp or just one

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
BartSr
Normal user
Posts: 143
Joined: 27 Sep 2019, 17:45

several PZEM004T to esp or just one

#1 Post by BartSr » 18 Feb 2024, 22:40

Hi!
I have read lots of forum data about PZEM004T v3.
Now I wonder about current status of hooking up numeric devices to just one esp.
As I want to monitor almost every circuit in my main distribution a single esp might be great solution.
Thanks for your thoughts.
Bart

BartSr
Normal user
Posts: 143
Joined: 27 Sep 2019, 17:45

Re: several PZEM004T to esp or just one

#2 Post by BartSr » 20 Feb 2024, 23:10

No advices?

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

Re: several PZEM004T to esp or just one

#3 Post by TD-er » 20 Feb 2024, 23:29

Well as far as I know is this a modbus sensor.
So in theory you can have multiple connected to the same serial bus and each should be assigned an unique modbus address.
However I don't know for sure is the ESPEasy implementation of it does address the sensor at its specific address (or the standard "broadcast" address) and also how the modbus address should be set at the PZEM004T.
And if it can be set, will it be a persistent setting (thus still set after power cycle) ?

Thus I hoped someone may have experience with actually using multiple instances of this device on ESPEasy.
In theory it should be possible, but there are quite some "ifs".

BartSr
Normal user
Posts: 143
Joined: 27 Sep 2019, 17:45

Re: several PZEM004T to esp or just one

#4 Post by BartSr » 05 Aug 2024, 21:15

@ TD-er
See picture. Seems to be answer on my earlier question.
How to find more about the ESP-built?
I am having several PZEM004t units each having own address. Can I just hook these onto one ESP? If so, which? I own lots of ESP8266 NodeMCU's V3
Thanks!!
Image
Attachments
Afbeelding van WhatsApp op 2024-08-05 om 21.08.23_9dbd8b0b.jpg
Afbeelding van WhatsApp op 2024-08-05 om 21.08.23_9dbd8b0b.jpg (231.86 KiB) Viewed 5706 times

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

Re: several PZEM004T to esp or just one

#5 Post by TD-er » 05 Aug 2024, 22:58

If the modbus modules each have their own unique address and are using the same baudrate (and other UART settings like "8N1", which is kind of standard, just mentioning it to be complete)
Then they should be wired to the same RX/TX pins.

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

Re: several PZEM004T to esp or just one

#6 Post by Ath » 05 Aug 2024, 23:27

BartSr wrote: 05 Aug 2024, 21:15 I own lots of ESP8266 NodeMCU's V3
You should better use an ESP32 (or ESP32-S3), that has much more RAM available for processing the data, and sending it to a Controller for multiple tasks.
And if you're buying that new, get one with 16 MB Flash memory, so you can use a MAX build that has all plugins and features included.
/Ton (PayPal.me)

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

Re: several PZEM004T to esp or just one

#7 Post by TD-er » 06 Aug 2024, 01:16

Also ESP32 (any type) has more hardware serial ports, which are way more reliable compared to software serial.

BartSr
Normal user
Posts: 143
Joined: 27 Sep 2019, 17:45

Re: several PZEM004T to esp or just one

#8 Post by BartSr » 08 Aug 2024, 11:19

Thanks so far for your information.

I flashed the software to NODEMCU 8266 (as I have those available now ) and are having 4 units in operation. Load seems to be < 10%.

Software serial pin D6 and D7 or GPIO 12 and 13.

Can I also have 4 units in parallel while hooking op towards hardware serial e.g. RX-TX GPIO 1-3 as I understood that's a better solution.?

TIA Bart

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

Re: several PZEM004T to esp or just one

#9 Post by TD-er » 08 Aug 2024, 11:25

Most boards have an USB to serial chip which may affect the signalling.
On ESP8266 you can swap the pins for Serial0 to GPIO pins (not the D-notation!) 13 and 15. In ESPEasy this is called Serial0_swapped.
However GPIO-15 must be in a specific state during boot, so you must then add a PNP transistor for it, which makes it a bit more complex.

If you're using Serial0 (or Serial0_swapped) you need to turn off the ESPEasy serial console (Tools->Advanced page, used to be called "Enable Serial")

If it is working fine now, using SoftwareSerial, then I would say, just leave it like it is now.
Switching to HardwareSerial will not lower CPU load significantly, but it will be with less read/write errors.

BartSr
Normal user
Posts: 143
Joined: 27 Sep 2019, 17:45

Re: several PZEM004T to esp or just one

#10 Post by BartSr » 01 Sep 2024, 13:13

I bought some devices ESP32-S3_WROOM-1 for this application.
I tried flashing via website TD-er but got error message.
I also tried keeping pressed BOOT button, tried keeping reset button and tried keeping both buttons.
Do I need a special BIN?
Why do the devicess is foreseen with two USB connections?
I noted that while hooked up the device to an UDB port boyh red and blue LED's where burning. The one in between just flickerd a few times.

BTW, this my first ESP32 (apart from a mini) so maybe I do something wrong. I am using lots of esp8266 devices.

Bart
Attachments
esp-forum.jpg
esp-forum.jpg (15.25 KiB) Viewed 3336 times

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

Re: several PZEM004T to esp or just one

#11 Post by Ath » 01 Sep 2024, 13:37

BartSr wrote: 01 Sep 2024, 13:13 I bought some devices ESP32-S3_WROOM-1 for this application.
I tried flashing via website TD-er but got error message.
How much Flash memory is available on that unit?
And what exact build did you choose to install?
/Ton (PayPal.me)

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

Re: several PZEM004T to esp or just one

#12 Post by TD-er » 01 Sep 2024, 16:29

What browser are you using?
Chrome is for sure supposed to work.

Those boards with 2 USB ports have one connected to native USB on the ESP chip and one to an USB to serial chip.
So please also try the other USB port.

Since those boards have 2x USB-C you may also want to try to rotate the USB cable 180 degree as not all USB-C cables have all pins wired internally.

You can also try to see in the device manager (Windows) if you get an extra serial port when the module is inserted.
If not, then either the driver isn't installed or the computer cannot communicate well with the serial port.

BartSr
Normal user
Posts: 143
Joined: 27 Sep 2019, 17:45

Re: several PZEM004T to esp or just one

#13 Post by BartSr » 02 Sep 2024, 11:21

@ Ath
How can I know? Does N8R2 makes sense?
I tried 4M Flash SPIFFS 20240822 Energy 4M [ESP8266,ESP32,ESP32-S2/S3/C3]

@TD-er
I'm using Chrome
I tried both USB connections. Also turned connector upside down

I tried to flash from https://td-er.nl/ESPEasy/ There it's clearly mentioned which port belongs to this ESP xx Espressif


All goes fine until there s message as in previous picture

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

Re: several PZEM004T to esp or just one

#14 Post by Ath » 02 Sep 2024, 12:09

BartSr wrote: 02 Sep 2024, 11:21 How can I know? Does N8R2 makes sense?
I tried 4M Flash SPIFFS 20240822 Energy 4M [ESP8266,ESP32,ESP32-S2/S3/C3]
That's an 8MB Flash with 2MB PS-RAM unit.
You could try the 8MB MAX with PS-RAM option (Only available for S3) from https://td-er.nl/ESPEasy/ as some boards act a bit weird when PS-RAM is available, but not initialized properly. That MAX build includes _all_ available options and plugins ;)
/Ton (PayPal.me)

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

Re: several PZEM004T to esp or just one

#15 Post by TD-er » 02 Sep 2024, 12:17

Just some additional info on Ton's reply.

The S3 with 16M flash is available with and without PSRAM.
However the 8 MB PSRAM is wired differently internal compared to the 2 MB PSRAM.
For the ESP32-S3 with 8 MB PSRAM modules you need a specific build which has PSRAM in the name.
If you're flashing the wrong one on those boards, the board will enter a boot loop.

There is no build for ESP32-S3 with 8 MB flash with "PSRAM" in the name as those boards with 8 MB PSRAM only exist for 16M flash units.

Espressif made it quite complex for the S3, but I hope it is clear when you mainly follow the flash sizes and only pick "PSRAM" build on those 16MB flash units which do have PSRAM (thus have 8 MB PSRAM)

BartSr
Normal user
Posts: 143
Joined: 27 Sep 2019, 17:45

Re: several PZEM004T to esp or just one

#16 Post by BartSr » 02 Sep 2024, 15:19

Bad luck! No flash possible.
What do you advice?
Throw away these?

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

Re: several PZEM004T to esp or just one

#17 Post by TD-er » 02 Sep 2024, 15:24

Can you try with the Espressif Download tool?
It is included in the release build ZIP files and also here: https://github.com/letscontrolit/ESPEas ... tool_3.9.6
Or you can download it from the Espressif site: https://www.espressif.com/en/support/download/all (called "Flash Download Tools")

Make sure to use a "factory.bin" file and set the offset to 0 bytes.

BartSr
Normal user
Posts: 143
Joined: 27 Sep 2019, 17:45

Re: several PZEM004T to esp or just one

#18 Post by BartSr » 03 Sep 2024, 15:23

pfff
downloaded the flastool but it confuses me a bit because it overwhelmes me with bin files someting as we dutch say to may trees in the wood.
can you advice me which bin to use? And from the downloadtool I found bthere must be 3 files combined?

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

Re: several PZEM004T to esp or just one

#19 Post by TD-er » 03 Sep 2024, 15:38

Nope you do not need to combine anything. Only a single file is needed.

Just to be complete, when using the Espressif Download Tool:

- For ESP8266 you need a ".bin" file and not the ".bin.gz"
- For ESP32 (any variant) you need a bin file with "factory" in the name.

The next column labelled "@" should contain a 0 as you have to start writing at the start of the flash.

Thus the file you need for an ESP32-S3 with 8M flash should be something like this:
ESP_Easy_mega_20240902_max_ESP32s3_8M1M_LittleFS_CDC_ETH.factory.bin

N.B. The date can of course differ

BartSr
Normal user
Posts: 143
Joined: 27 Sep 2019, 17:45

Re: several PZEM004T to esp or just one

#20 Post by BartSr » 04 Sep 2024, 18:11

well, there is progress but nu good result yet
how to?
espforum3.jpg
espforum3.jpg (144.92 KiB) Viewed 2492 times

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

Re: several PZEM004T to esp or just one

#21 Post by Ath » 04 Sep 2024, 21:32

Hm still looking real strange, don't own a single module (I have several dozens here ;)) that cause me this kind of issues, since I started using ESPs.
A few things to check:
- If you press the boot button and click reset shortly to enable flashing, once the upload has started, release the boot button so the reset afterward, triggered by the uploader, will not keep it in flash-mode
- Have you considered replacing the USB cable that is used?
- Or try another USB port on the computer?
/Ton (PayPal.me)

BartSr
Normal user
Posts: 143
Joined: 27 Sep 2019, 17:45

Re: several PZEM004T to esp or just one

#22 Post by BartSr » 05 Sep 2024, 12:26

Ath,
I tried your suggestions. The results are in the picture.
I tried several more bin files but all giving same result. But I could not get back the action writing the dots on the screen. So in fact (imho) flash failed.
espforum4.jpg
espforum4.jpg (142.8 KiB) Viewed 2327 times

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

Re: several PZEM004T to esp or just one

#23 Post by Ath » 05 Sep 2024, 13:27

Hm, do you have a spare ESP available? As it is of course possible, this one is broken... (DOA)
/Ton (PayPal.me)

BartSr
Normal user
Posts: 143
Joined: 27 Sep 2019, 17:45

Re: several PZEM004T to esp or just one

#24 Post by BartSr » 06 Sep 2024, 11:27

Good news today.
I once tried again flashing via website TD-er.
I noticed that this time there was a com-port found with ID : USB JTAG/serial debug unit serial (COM10) whereas before it said: USB 2.0-Ser! (COM10)
So I presume there are different drivers required for this ESP32 compared to ESP8266.
I was able to flash the bin file: ESP_Easy_mega_20240822_max_ESP32s3_8M1M_LittleFS_CDC_ETH

So it seems I can now continue using the device with my applications. I think I will start with the 'project as mentioned in the subject of this thread:
"several PZEM004T to esp"

Ton and Gijs, thanks again for your patient and helpness.

-Bart

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

Re: several PZEM004T to esp or just one

#25 Post by Ath » 06 Sep 2024, 12:23

BartSr wrote: 06 Sep 2024, 11:27 Good news today.
Great! :D
BartSr wrote: 06 Sep 2024, 11:27 I noticed that this time there was a com-port found with ID : USB JTAG/serial debug unit serial (COM10) whereas before it said: USB 2.0-Ser! (COM10)
So I presume there are different drivers required for this ESP32 compared to ESP8266.
That's the difference when connecting either of the USB ports of the ESP-S3 board you own. The USB JTAG is detected for the direct USB connection to the ESP (CDC), and USB 2.0-Ser is for when connected via the UART port of the board.
/Ton (PayPal.me)

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

Re: several PZEM004T to esp or just one

#26 Post by TD-er » 06 Sep 2024, 12:52

The USB port you now used (reporting its serial port as "JTAG" in Windows Device Manager) is a simulated serial port.
So the ESP does act as an USB device to Windows then.

This also means it must do some stuff in software to emulate these ports.

If for whatever reason your board was flashed with some code which does not enable this emulated port, then you can't get the board to flash via this port... well unless you do a lot of button pushing in a specific order...

The other USB port on the ESP board is wired to an USB to serial chip.
This makes it easier to recover from such flash mishaps where the ESP may not (or no longer) do the device emulation.

For my own development I try to use those dual-USB port boards for this reason.

However this also means that if you have a board with only such emulated serial ports, you can experience quite some issues to get it to work again.

Some boards have the 2 ports labelled on the silk screen.
Like "OTG", "JT", "JTAG" or "USB" for the emulated serial ports.
And "UART", "SER" or "S0" for the USB port connected to the USB to serial chip.

And of course there are boards out there which have no marking at all and the USB to serial chip exactly in the middle of both USB ports.

To make matters worse... USB-C can be connected in both orientations of the plug.
But not all boards have 2x 5.1 kOhm resistor present on the CC pins and/or not all A/B pins wired.
Combine this with some cheap USB-C cables which also have not all pins wired in the USB-C connector and you end up in a lot of combinations where it will not work at all or not work well when the USB port is not set to deliver the needed max. current.

TL;DR
I can think of lots of causes why you had issues flashing your board.
Hopefully you understand how to successfully flash a board.
Typically:
- try the other USB port
- try rotating the USB connector
- try another USB cable (IKEA does have quite good cables for a fair price)

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests