mathieucarbou / MycilaPZEM004Tv3

Arduino / ESP32 library for the PZEM-004T v3 Power and Energy monitor
https://oss.carbou.me/MycilaPZEM004Tv3/
MIT License
0 stars 0 forks source link

Doesn't read the meaning. #3

Closed todosko closed 3 months ago

todosko commented 3 months ago

Here's a simple example with your library:

include

include

define ADDRESS1 0x0A

Mycila::PZEM phase1; void setup() { Serial.begin(115200); while (!Serial) continue; phase1.begin(&Serial1, 27, 14, ADDRESS1, true); } void loop() { delay(2000); if (phase1.isEnabled()) { Serial.print("Address = "); Serial.println(phase1.readAddress(), HEX); Serial.print("Voltage = "); Serial.println(phase1.getVoltage()); } } Result: Address = 0 Voltage = 0.00 Is something not working here?!

The same connection diagram, but an example with the library https://github.com/mandulaj/PZEM-004T-v30:

include

include

define ADDRESS1 0x0A

PZEM004Tv30 phase1(Serial1, 27, 14, ADDRESS1); void setup() { Serial.begin(115200); while (!Serial) continue; } void loop() { delay(2000); Serial.print("Address = "); Serial.println(phase1.readAddress(), HEX); Serial.print("Voltage = "); Serial.println(phase1.voltage()); } Result: Address = A Voltage = 236.50 And it works here! What's wrong???

todosko commented 3 months ago

Yes, I forgot to say - I’m checking it on ESP32.

mathieucarbou commented 3 months ago

I will verify... I've reworked the async layer recently to support multiple PEM in async mode... Maybe that... Could you please add these flags and report the Serial output ?

-D CONFIG_ARDUHAL_LOG_COLORS -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG

Thank you.

todosko commented 3 months ago

Ok, I understand what's going on! You have changed the order of Tx and Rx. Although you write "* - PZEM004Tv3 connected to Serial1 (RX=27, TX=14)", but unlike the library https://github.com/mandulaj/PZEM-004T-v30 "PZEM004Tv30 phase1(Serial1, 27, 14, ADDRESS1);" you need to write "phase1.begin(&Serial1, 14, 27, ADDRESS1, true);" !!! And since you are referring to the "mandulaj" library, I advise you to return the RX, TX order the same as for "mandulaj". So that people don't get confused...

mathieucarbou commented 3 months ago

Ok, I understand what's going on! You have changed the order of Tx and Rx.

No I didn't.

Although you write "* - PZEM004Tv3 connected to Serial1 (RX=27, TX=14)",

Which is correct based on the documented header

but unlike the library https://github.com/mandulaj/PZEM-004T-v30 "PZEM004Tv30 phase1(Serial1, 27, 14, ADDRESS1);" you need to write "phase1.begin(&Serial1, 14, 27, ADDRESS1, true);" !!!

No, that is how you would like it to be, but not as documented in the header

And since you are referring to the "mandulaj" library, I advise you to return the RX, TX order the same as for "mandulaj". So that people don't get confused...

This is not a fork, this is another repo. The ref is FYI.

I get your point though that this is confusing in regards to what people are used to so. I am going to release a new major with a breaking change.

mathieucarbou commented 3 months ago

fixed in v2.0.0 ;-)

todosko commented 3 months ago

Thanks for good job. I will use your library in the future.  

Олег Тодосько тел. +79139215136 Отправлено из Почты Mail.ru