letscontrolit / ESPEasy

Easy MultiSensor device based on ESP8266/ESP32
http://www.espeasy.com
Other
3.22k stars 2.2k forks source link

[ESP32] Improve HW Multiplexing feature for energy plugin 102 - PZEM-004Tv30-Multiple [TESTING] #3701

Open jmexposi opened 2 years ago

jmexposi commented 2 years ago

Checklist

I have...

Steps already tried...

Summarize of the problem/feature request

I need (if it's possible) to use hardware multiplexing feature with Tca9548a to split 11 PZEM energy sensors & 2 BME280 temp sensors. Seems that multiplexing feature isn't implemented yet for PZEM.

Steps to reproduce

  1. Setup in harware section: activate the multiplexing functionality : Tca9548a
  2. Install plugin BME280 and setup in channel 1 of Tca9548a : works fine
  3. Install plugin PZEM-004T : and "plug" it into channel 0. I2c config schema changes but the options are different and it's not possible to select multiplexer channel 0. I can't configure device and doesn't works.

System configuration

Hardware: ESp32 Tca9548a multiplexer PZEM-004T energy meter

ESP Easy settings/screenshots:

hardware devices device_pzem

TD-er commented 2 years ago

I don't understand the problem here. The PZEM does need an UART port. What you have selected is the option (as I think we also discussed on the forum) of an I2C to UART chip. The I2C multiplexer is meant for I2C devices which cannot be set to another I2C address or to create extra isolated I2C busses for example to mix 5V and 3v3 I2C devices or combine devices that don't support higher I2C clock frequencies.

Right now, we do support an abstraction layer for UARTs so all plugins that need an UART can switch between SW serial/HW serial and I2C to UART chips. The I2C to UART chip does support upto 16 I2C addresses, so in theory that may add 32 UART ports. I have a board I made myself which does have 3 of these chips on board adding 6 UART ports and that's working fine. It does of course share the I2C bus, so for rather 'chatty' devices you may run into practical bandwidth issues. On 400 kHz I2C clock I guess the upper limit is roughly 100 - 150 kbps continuous. (bursts can be higher due to 64 byte FIFO buffers in the chips per UART)

To summarize, I don't think this is really an issue.

jmexposi commented 2 years ago

Ok understood. Following your suggestion, I have separated the I2C channel to pins 32 and 33 to use it with the BME280 and for now I will try to use the 3 HwSerial channels to control the PZEMs (mapping Hw1 to avoid conflicts) and in the future try to include UART bridge as you recommended.

In any case, if possible, this could be considered as an improvement to be able to control multiple devices separating them by different channels using a single channel of the controller.

TD-er commented 2 years ago

In any case, if possible, this could be considered as an improvement to be able to control multiple devices separating them by different channels using a single channel of the controller.

That's already possible, as you can select the channel (A/B), and the I2C address when chosing an I2C uart port. And since you add it per task, it should already be separated.

But just for the PZEM, I find it rather strange it apparently cannot use several on the same UART port, as that's typically one of the benefits of using RTU Modbus.

TD-er commented 2 years ago

See PR: #3807

I think this should perhaps also be fixed by that PR. What happened was that the ESP32 serial port may become unavailable after end() was called followed by a begin(). This is exactly what may happen on PLUGIN_INIT, thus when saving settings, but also when using multiple instances of a plugin using the same UART port, like when using Modbus RTU.

Can you try this fix?

jmexposi commented 2 years ago

Hi, Of course: I will prepare a test environment and I report results as much as possible. (I may ask you how to integrate the modification you have made into the project: but let me look at it first.)

Of topic: (sorry for no details but I'm working at this moment) for my project I will decide to programming into an arduino sketch to learn basically and works!!! (12 pzem modules in ESP32 HW) without use of multiplexing hardware. (On the other hand, I have bought a module to multiplex 8 channels in UART mode, -1 UART source 8 UART destinations- which I will test later) I use 3 HWSerial (SWSerial doesn't works if you want to use +channel in ESP32) mapping them to avoid conflicts. Originary I used the modbus library to manage a modbus sensor array but the Author of PZEM library has included functionality to deal with modbus and I no longer need it. At this moment I'm trying various brokers to send sensor data and made my reports.

El jue, 14 oct 2021 a las 8:28, TD-er @.***>) escribió:

See PR: #3807 https://github.com/letscontrolit/ESPEasy/pull/3807

I think this should perhaps also be fixed by that PR. What happened was that the ESP32 serial port may become unavailable after end() was called followed by a begin(). This is exactly what may happen on PLUGIN_INIT, thus when saving settings, but also when using multiple instances of a plugin using the same UART port, like when using Modbus RTU.

Can you try this fix?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/letscontrolit/ESPEasy/issues/3701#issuecomment-943009552, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKPTKACQC2OOIYP4LBJ2IKDUGZ2BHANCNFSM5ADURAFA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

TD-er commented 2 years ago

There is also support for the NXP SC16IS752 UART bridge. These can be used on various I2C addresses and offer 2 UART busses per chip. So if you eventually decide to not connect the PZEM modules to the same serial port, you can also look into the I2C bridge option.

vortigont commented 2 years ago

@jmexposi I'm currently developing a high efficient event-driven lib to multiplex lot's of PZEM devices over a single/multiple serial line(s). You might wanna test it with your 12 pzems, would be interesting to have a feedback for such a setup. Cheers!

jmexposi commented 2 years ago

Hi, @TD-er This weekend I will prepare a test environment (SC16IS752) and I report results as much as possible. the other multiplexer that I mentioned before is: atlas scientific 8:1 Serial Port Expander (see attach)

@vortigont Ok!, it's very interesting: I will try and give you feedback.

and I attach photo of my PZEM last project update Many Tnks!!! IMG_20211014_212658_286 IMG_20211014_212441_859

BR , JMER

TD-er commented 2 years ago

Great :) Looking forward to your report.

vortigont commented 2 years ago

Wow! Mighty rig :)

vortigont commented 2 years ago

BTW, that 8:1 Serial Port Expander does not worth the efforts as it seems to me. It looks like a dumb port switch with output selector. So you can't have different uart configurations for each port and you can use only one IO port at a time. More suitable for devices that can't share serial lines and PZEM's could do this quite well via modbus addressing.

jmexposi commented 2 years ago

@TD-er sorry, for now I couldn't get the CJMCU-752 to work with the PZEM

I fetch from rep. and compile pr/3807 branch : tomorrow I will try to aply & test latest mega branch...

I applied wiring (and pullup res.) configuration as you describe in: https://github.com/TD-er/SC16IS752 (into previously attached image you can see it)

when i do an i2c scan the 752 device shows up but the LEDs (TX / RX) on the PZEM don't light.

When I try a PZEM HW config without 752 and works fine. An add later 2 BME280 Temp. Sensors in a separate i2c channel and PZEM HW and BME280 works fine. (without 752)

Any required parameter into de custom.h file for CJMCU-752?

On the other hand: I cannot see any output log from PZEM into the log page (I try all log modes) only way to see the outputs is in Devices page and metrics option. (I try a serial monitor of arduino ide and see the same)

if i check the Event output option in any device: doesn't show in the log.

In previous releases I see all of them in the log.

Tnks!

BR JMER

TD-er commented 2 years ago

How do you compile it? Every plugin in ESPEasy should now support the ESPEasySerial wrapper I wrote, so then it does not matter whether you use the NXP I2C to UART bridge, HW serial or SW serial. (well I don't have SW serial added for ESP32)

The I2C scan will not toggle anything on the UART side, as it is just tries to address the I2C device and is getting a response, nothing more. If you have the I2C selector present in the serial config, then it should be compiled just fine. Example: image

jmexposi commented 2 years ago

Hi @TD-er, I build now and test but I couldn't get the CJMCU-752 to work with the PZEM (next, I will test the 752 in a separate ino sketch file): test6_device

If I try inn HW mode without the 752 works: test4_devices

with 752 I2C Scan detects device: test6_I2C_Scan

I fetch & build latest MEGA branch: test6_fetch_mega_br test6_build

My config.h file: Custom.zip

TD-er commented 2 years ago

It looks like you have tried using the I2C config, but be aware you have an "A" channel and a "B" channel. Have you tried both?

jmexposi commented 2 years ago

Hi, Bridge doesn't work: please, see attached images for current config.

Tnks!

El mar., 19 oct. 2021 9:40, TD-er @.***> escribió:

What do you mean by "couldn't get the CJMCU-752 to work with the PZEM" ? Doesn't the I2C selection appear in the task config? Or it doesn't work with the I2C bridge?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/letscontrolit/ESPEasy/issues/3701#issuecomment-946446842, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKPTKAGNWVFSHOH7GFCD5YLUHUOH3ANCNFSM5ADURAFA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

TD-er commented 2 years ago

Yep, seen the images, but I only see a test with using "channel A" of the bridge. Have you double checked that "channel B" also doesn't work?

Do you have any other ESPEasy supported sensor using serial that you can test on the bridge chip to make sure that chip is working fine?

jmexposi commented 2 years ago

@TD-er "B" test: test7_device

I check all combinations "A" & "B" and check the wiring with a meter. I try other 752 module.

Finally I try with other ESP32 your ino examples for that module: doesn't works for me... (see images) I'm not clear with pinup config to connect with ESP32 board but I use the default I2C for ESP32-WROOM: GPIO 21 (SDA); GPIO 22 (SCL) and "reversed". Can you confirm the Pin config (SDA/SDL)?? test8_I2C_SELFTEST

test8_wiring

Tomorrow: I will try with an ESP8266 board.

Tnks!

BR JMER

TD-er commented 2 years ago

ESP32 is not critical to which pins you're using for I2C. Just make sure it isn't an input-only pin and not used for something else. See also documentation for reference. As long as you can see the I2C device, you should be fine I guess. Maybe also add some pull-up resistors on both SDA and SCL, as it is often unknown what may be placed on those boards. N.B. the same may apply to the serial line signals, so better also check those.