mandulaj / PZEM-004T-v30

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

Compatibility with Nodemcu ESP32 board? #26

Closed Dhruv3872 closed 3 years ago

Dhruv3872 commented 4 years ago

I have used the library to work with Arduino UNO and it works fine. With my Nodemcu-32S board, I am not able to get anything on the serial monitor when I run "PZEMHardSerial" example with "&Serial" instead of "&Serial3". Is your library compatible with Nodemcu-32S module? If not, is there a way to make it compatible?

Thanks.

mandulaj commented 4 years ago

Hi @Dhruv3872, I have the library running on an ESP32 with hardware serial no problem. Have you tried any of the common issue solutions:

thanawat14 commented 4 years ago

@mandulaj I have the same problem.. "Error reading ..." I use &Serial2 and connect Tx/Rx to 16,17 pin of esp32. I'm quite sure I connect to Tx-Rx correctly but result is the same.. Btw, what i can see is only Rx led is blinking.

k-davydov commented 4 years ago

@mandulaj I have the same problem.. "Error reading ..." I use &Serial2 and connect Tx/Rx to 16,17 pin of esp32. I'm quite sure I connect to Tx-Rx correctly but result is the same.. Btw, what i can see is only Rx led is blinking.

I'm getting exactly the same results with my pzem-004t from ali and esp32. RX on Pzem flashes during poll, but TX does not. Thus "error reading voltage/current/etc." goes from esp32 to usb-serial. I tried different serial connection, hardware on pins GPIO1+GPIO3, GPIO16+GPIO17 and serial on different other pins. Still no luck. By any chance, didn't you manage to solve it somehow?

upd: I've just fixed it. It wasn't working because i hadn't connected AC power. Now works fine.

mandulaj commented 3 years ago

Yeah this is a very common problem. It is already in the Readme however if you have any ideas how to make it more clear, let me know. I am closing this issue for now.

Jemeeeeer commented 3 months ago

Hi, my pzem004t datasheet tells me that the command format for reading the sensor values is different from the sendcmd8 in your library. is it the explanation why i get nan values in my serial monitor?

mandulaj commented 3 months ago

@Jemeeeeer This library is for the PZEM004T v3.0. If you have the PZEM004T, this library will not work and you should use https://github.com/olehs/PZEM004T instead.

Jemeeeeer commented 3 months ago

Im using PZEM004t-100A(V3). Im using RX (3) and TX (1). Connected to an AC load and all wires are connected properly. Even the readAddress() is not functioning. I saw in the data sheet that the command format of the master in measuring is Slave Address + 0x04 + Register Address High Byte + Register Address Low Byte + Number of Registers High Byte + Number of Registers Low Byte + CRC Check High Byte + CRC Check Low Byte. However in the library, I saw that the CRC low byte came first and CRC high byte second. does this have anything to do with it I cant read and set the address of my pzem from 0xF8 to 0xF7? It also says that the PZEM has a range of 0x00 to 0xF7 only.

mandulaj commented 3 months ago

Could you share the datasheet you have?

Jemeeeeer commented 3 months ago

Here's the datasheet: https://innovatorsguru.com/wp-content/uploads/2019/06/PZEM-004T-V3.0-Datasheet-User-Manual.pdf

mandulaj commented 3 months ago

Yep thats interesting, I can't find the datasheet I used to implement this anymore. I will have to have a closer look at this. But strange that something like that hasn't been observed earlier. Besides on my PZEMs it worked fine. Have you tried swapping the byte order?

Jemeeeeer commented 3 months ago

i have tried changing the crc byte order in your library by modifying it. it can transmit a command format however, there is no available bytes to read in the response buffer. what seems to be the problem?

mandulaj commented 3 months ago

Do both LEDs flash on the board?

Jemeeeeer commented 3 months ago

only the TX LED is blinking,

Jemeeeeer commented 3 months ago

do u have any idea why my pzem004tv30 rxx pin not blinking? both of the rx and tx pins are connected to a voltage divider so to make it 3.3 V. pzem004tv30 is powered with a 5v external dc supply, while esp32 is powered with microusb connected to pc. im using pins 3, 1 for rxtx serial 0. i still dont know why it isnt receiving data.

Jemeeeeer commented 3 months ago

up

mandulaj commented 3 months ago

Do you have the 240V AC line attached? That is where the PZEM chip actually gets the power form. The 5V is only to power the opto-couplers.