Issue with mutiple pzem-004 in parallel

herveb

Feb 13, 2025
2
Joined
Feb 13, 2025
Messages
2
Hello, I am not used to posting threads in forums, so forgive me and correct me if this is not the right forum or the right form.
The pzem-004 v3 is a power sensor nodule. It provides info like volt, amps, power factor, frequency....
In my house, I have a 3 phase system, therefore I use 3 of these modules.
I have used them before, both with a single module and with 3 modules (with different addresses) connected in parallel.
My success was with a pic18f26k22.
Then I needed to interface with a LCD, a spi memory, and an i2c RTC. So I switched to a chip of the same family but more peripherals: pic18f46k22. Here is my failure: when I connect all 3 pzems, I cannot query them, I timeout. If I connect 2 pzems, any 2: Phase1 and 2 or Phase 2 and 3 or Phase 1 and 3, It works like a charm. This eliminates issues like: one pzem is bad, or the connecting cables are bad. I even swapped the cables. As soon as the 3 of them are connected. It stops.
My first thought was: not enough power, so I made the PCB track to power the pzems, wider. I even connected 2 jumpers directly to the 5v and Vss (Gnd). It made no difference.
I understand that without schematics it is impossible to debug my specific problem.
So here is roughly the connection: pic18f46k22 Pin RC6 (TX1) to pzem Rx, Pin RC7 (RX1) to pzem Tx, 5v to pzem's 5v, Vss to Pzem's GND, all pzems are connected in parallel.
Should I blame the microcontroller? I never do that. I always blame myself and rightfully so.

I'm just asking for general guidance, what would you check or double check or try if this happened to you? I'm not lazy, I'm running out of ideas.

Thanks a lot
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
14,271
Joined
Nov 17, 2011
Messages
14,271
all pzems are connected in parallel.
You can't connect UARts in parallel. Uarts (Rx, Tx lines) are made for point-to-point connections, not busses.
It is a small wonder your setup works with 2 pzems. Possibly a matter of one output being able to override one other output, but not two.

option 1: use three different UARTs and accordingly pin sets for Tx and Rx on the controller
option 2: use a multiplexer to route the UART connection to one pzem at atime only
option 3: use tristate transceivers on the pzem side to deactivate the outputs of the 2 inactive sensors while communicating with the third sensor.

So here is roughly the connection:
Please supply pictures. As the saying goes: one picture is worth a thousand words. Especially in our realm.
 

herveb

Feb 13, 2025
2
Joined
Feb 13, 2025
Messages
2
Thanks for your reply. You have a compelling argument. I guess I got confused for 2 reasons:
1- the datasheet says that each slave (pzem module) can be assigned an address and every query (and reply) contains an address. What's the point of having an address if you are not on a bus or alone on the bus?
2- It worked with 3 modules in parallel in my first try with a pic18f26k22.
Maybe I got lucky (or unlucky) on my first try.
I am already working on an alternate circuit according to your comments.

Thank you for your help.
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
14,271
Joined
Nov 17, 2011
Messages
14,271
What's the point of having an address if you are not on a bus or alone on the bus?
No point there when using a point-to-point connection (pun intended).
But: You could use the UARTs to communicate via a serial bus like e.g. RS485. With multiple devices on the bus. That's where addresses do come in handy, don't they?
 

ahsrabrifat

Jan 18, 2025
76
Joined
Jan 18, 2025
Messages
76
Use an oscilloscope or logic analyzer to check if the third module is interfering with the communication.
 
Top