mandulaj / PZEM-004T-v30

Arduino library for the Updated PZEM-004T v3.0 Power and Energy meter
MIT License
266 stars 115 forks source link

Help: Address Problem #76

Closed shiftux closed 3 years ago

shiftux commented 3 years ago

Hi First off, thanks for writing this library! - Makes life so much easier!

I'm struggling with the very first interfacing of the PZEM-004T-100A(V3.0) via my ESP32 devkit V1. I was using the (unmodified) example code in PZEM-004T-v30/examples/PZEMHardSerial/PZEMHardSerial.ino to test readouts of the device. However, all I am getting is:

Custom Address:0
Error reading voltage

As a fix I was trying to use PZEM-004T-v30/examples/PZEMChangeAddress/PZEMChangeAddress.ino, but this seems to fail as well:

Previous address:   0x0
Setting address to: 0x55
Error setting address.

I will note that at first, I was trying to use the older library. I'm hoping this didn't somehow mess up the addressing of the device. However, I tried it with another PZEM (on which I had not used the old lib) and the behavior is the same. This makes me think I am doing something wrong, but I can't figure out what it is...

I've attached a pic detailing my wiring setup. And my platformio.ini file looks like below.

Help is much appreciated! Thanks!

[env:esp32doit-devkit-v1]
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
monitor_speed = 115200
monitor_filters = direct, esp32_exception_decoder
lib_deps = 
    knolleary/PubSubClient@^2.8
    /Users/shiftux/Documents/Arduino/libraries/PZEM004Tv30/src/
    EspSoftwareSerial

WhatsApp Image 2021-09-24 at 08 29 51

mandulaj commented 3 years ago

Hi, it seem that the problem is most likely in your wiring. From the picture it is slightly unclear where you have connected the all the wires. Make sure that the 5V (Yellow wire) is connected to the 5V pin, Ground (Black) to a ground pin and the RX/TX (White and Red) to the TX/RX pin of the ESP32. By default those are the GPIO17 and GPIO16 respectively. https://circuits4you.com/wp-content/uploads/2018/12/ESP32-Pinout.jpg. Also try swapping the RX and TX around, just in case.

You should see the RX and TX LEDs flashing on the PZEM module. Also make sure the module is hooked up to the AC. The chip is actually powered by the AC, not the 5V!

shiftux commented 3 years ago

ah wow! - the AC current has to be connected...! - did not get that! i feel silly! 🙈 Thanks for the quick reply!

shiftux commented 3 years ago

the strange thing about it is that you actually see one of the 2 lights flashing, even without the AC. so I never really thought it was not powered...

mandulaj commented 3 years ago

Yes, I agree it is slightly confusing. The board is split up into a high voltage (AC 240V) and low voltage (5V) section. These sections are powered independently but are bridged by the white Optocouplers so no electrical power is flowing between them (this is good for safety).

The PZEM chip and the TX optocoupler is powerd by the AC section while the RX optocoupler and both the RX and TX indication LEDs are powered by the 5V line so it is expected that only RX line flashes when the AC isn't connected because that is your ESP trying to send data to the PZEM chip but not getting any reply.

Yarce008 commented 2 years ago

Hello, I have had the same problems as you, I have used the same code ... you already have the solution

Yarce008 commented 2 years ago

Hi First off, thanks for writing this library! - Makes life so much easier!

I'm struggling with the very first interfacing of the PZEM-004T-100A(V3.0) via my ESP32 devkit V1. I was using the (unmodified) example code in PZEM-004T-v30/examples/PZEMHardSerial/PZEMHardSerial.ino to test readouts of the device. However, all I am getting is:

Custom Address:0
Error reading voltage

As a fix I was trying to use PZEM-004T-v30/examples/PZEMChangeAddress/PZEMChangeAddress.ino, but this seems to fail as well:

Previous address:   0x0
Setting address to: 0x55
Error setting address.

I will note that at first, I was trying to use the older library. I'm hoping this didn't somehow mess up the addressing of the device. However, I tried it with another PZEM (on which I had not used the old lib) and the behavior is the same. This makes me think I am doing something wrong, but I can't figure out what it is...

I've attached a pic detailing my wiring setup. And my platformio.ini file looks like below.

Help is much appreciated! Thanks!

[env:esp32doit-devkit-v1]
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
monitor_speed = 115200
monitor_filters = direct, esp32_exception_decoder
lib_deps = 
    knolleary/PubSubClient@^2.8
    /Users/shiftux/Documents/Arduino/libraries/PZEM004Tv30/src/
    EspSoftwareSerial

WhatsApp Image 2021-09-24 at 08 29 51

Hello, I have had the same problems as you, I have used the same code ... you already have the solution

mandulaj commented 2 years ago

Hey @Yarce008 Could you be more specific in describing your issue? What is the exact problem? Have you tried any of the suggested solutions (swapping RX/TX, connecting the module to AC, etc.) I can't really help you otherwise.

Yarce008 commented 2 years ago

Hey @Yarce008 Could you be more specific in describing your issue? What is the exact problem? Have you tried any of the suggested solutions (swapping RX/TX, connecting the module to AC, etc.) I can't really help you otherwise.

hello, cordial greeting, thanks for answering...see how I'm Spanish-speaking, I have to use a translator...but I'll tell you: I have used the different codes to make the electrical measurements. I am using a PZEM -004T-100A(V3.0) AND AN ESP32 DEVI VERCION 4 It does not make me measurements and it gives me the same error as the publication I would like you to give me a hand .... I will prepare a video for you or upload some detailed photos I am still new to this