-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple PZEMS cannot be used using same library #29
Comments
Hello, thank you very much for sharing this library with us. It would be very important if we were able to create a library and be able to use multiple PZEM on the same network. thank you. |
PZEM004Tv30* pzem[] = { for (size_t i = 0; i < 3; i++){ or add uint8_t addr PZEM004Tv30::PZEM004Tv30(uint8_t receivePin, uint8_t transmitPin, uint8_t addr) |
Hi @efakostya, In my case I already have the hardware ready, and the communication of the PZEM's are in parallel, I cannot change the pins. |
I managed to read several sensors connected in parallel to the same software serial port, following the instructions here. The approach is to create two instances with different names, same port, and different address (of course, you have to program different addresses in each sensor, using the Windows software provided by the manufacturer, as I did, or the appropriate functions in this library, as explained here):
The output is like this:
As you can see, this way of doing it has a problem if the number of sensors is higher, as you have to repeat a lot of code for each one. To avoid it, a possibility would be a modification in the library so the address could be passed as an argument (see here), but that's beyond my capabilities... So I tried a second approach where the different instances of PZEM004Tv30 are created as an array. I wasn't sure this was going to work but, fortunately, it did! Now the code is shorter and easy to escalate to more sensors:
And it's output:
The errors for sensor No 3 are due to the fact I haven't connected it yet ;-) Hope it helps! |
Hi @morganflint, Thank you! Do me a lot! Congratulations !!! |
Thanks @morganflint. Do you guys think the instructions should be placed somewhere more visible since this is a recurring issue people are coming across. If anyone has time and strength to describe this in the wiki or something, feel free to do so! |
Dear good day,
Appreciate your efforts, can you please update the library to use ip function to add multiple pzem v3 devices in the same code.
Thanks
The text was updated successfully, but these errors were encountered: