mandulaj / PZEM-004T-v30

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

Add ESP32 Support #20

Closed Navok85 closed 3 years ago

Navok85 commented 4 years ago

Please add ESP32 support.

I changed line #25 in PZEM004Tv30.h file to:

#if (not defined(PZEM004_NO_SWSERIAL)) && (defined(__AVR__) || defined(ESP8266)) || defined(ESP32) which makes it works with hardwareserial e.g. serial2

But softwareserial still makes problems and didn't work with the EspSoftwareSerial.

clowrey commented 4 years ago

I don't have anything to add as far as fixing the issues - but I can say I have duplicated the same basic effect.

It works with Serial2, does not work with the EspSoftwareSerial library found here https://github.com/plerup/espsoftwareserial

This might be tricky to debug - not sure exactly where to start, my board the TTGO ESP32 TFT with LCD screen had no available extra serial as the Serial2 port is used by the built in LCD screen. I switched to a different board with the hardware serial pins 16,17 available and it works with the hardware serial example.

mudassar791 commented 4 years ago

can you upload ready made example with esp32 & esp8266 in next release?

mandulaj commented 3 years ago

I am aware of the Software Serial bug in ESP32 and I don't have a solution. However I think that since the ESP32 has 3 HW serial ports which can be configured to use any GPIO pin, there isn't really any need for a Software Serial solution.

If there is a requirement to use the Software Serial, I might consider looking into it in the future. But for now, I think its better to just not support it on the ESP32 platform.

loopyengineeringco commented 3 years ago

Yes, you no longer need to use SoftwareSerial on the ESP32, even to address multiple pzems thanks to the new updates 🎉 Just remap the HardwareSerial pins to some free unused GPIOs and it works great. Not sure if the library does this remap for you, but you can do it brute force by editing this file: C:\Users\xxxxxx\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\cores\esp32\HardwareSerial.cpp Then close & reopen Arduino & recompile Just remember you did this, otherwise you'll have fun in a few year's time when you've long forgotten 🤣

mandulaj commented 3 years ago

OK, The newest code has now been merged into master. Soon I will update the PlatformIO and Arduino Library manager library. Here is the the new way of defining HW Serial on ESP32s:

// RX=16, TX=17
PZEM004Tv30 pzem(Serial2, 16, 17);

If there isn't anything else, I will close this issue. For now I am linking #70

rohanpatil-rc commented 10 months ago

i am having issues (esp32) the code get compiled and uploaded but serial monitor reports -error reading i have tried swaping rx and tx but still not getting any outuput the pzem ttl only one led blinks
change the baud rate to 9600

i have tried some else code with ardunio the pzem is working fine showing all results.

mandulaj commented 10 months ago

@rohanpatil-rc You will have to give me more info in order to help you. Which pins are you using on the ESP32, can you share the code? Is the PZEM powered by AC? Could you share the code or library that does work? Are you sure you are using a PZEM 0004T version 3.0?

rohanpatil-rc commented 10 months ago

@rohanpatil-rc You will have to give me more info in order to help you. Which pins are you using on the ESP32, can you share the code? Is the PZEM powered by AC? Could you share the code or library that does work? Are you sure you are using a PZEM 0004T version 3.0?

i have delete my post with the code that is was having issues. it was not the code it was the gnd pin trace of esp32 that was broke its working now thanks for your library