I am currently working on a project that would require a total of 10 UART (rx and tx pins) to run 10 PZEM-004Ts for different electrical lines. I am thinking of using an atmega 2560 because it has plenty of hardware UART, and have the remaining as software UART. The problem is I do not know if the atmega 2560 could handle all the 10 UARTs nor do I think that the project is possible to make. I want to ask if anyone knows a better solution to execute the project?
Your comments is highly appreciated!!
PS. I still haven't made any circuit because i don't know if the project is even possible.
Not more than 5 (4 UARTs, and 1 SoftwareSerial). And you should also check out if we're talking about TTL serial or RS232, as they're electrically different.
You could consider another approach, like converting serials into I2C bus connections or something like that, so searching for "serial to i2c converter" you could find this for instance, but I can't tell you more than that, sorry.
If it is, then the datasheet says that the PZEM-004T is an RS485 device (section 1.8). The datasheet also says that the Modbus protocol is used (section 2.2).
If the above is correct, then you only need one UART for all 10 devices as RS485 is a bus.
The datasheet also indicates that you can change the slave address of each device - which you would need to do if you want all 10 devices to co-exist on the same RS485 bus.
This is very helpful. Thank you very much! I never knew RS485 before, and I think this is the best possible approach for my project. I looked at the datasheet and my only problem is that my current PZEM-004T does not have the said RS485 converter (shown in Picture 4.1).
Does that mean I can use a MODBUS RS485 for my current PZEM-004T? including 1 more for the microcontroller?
or should I just buy the model that is completely similar to the datasheet?
Can you provide the datasheet for the model you have?
If yours is simply a TTL serial device, then it likely doesn't have the concept of a device address.
It would certainly be a lot easier with an RS485 interface on your sensor.
You would need to decide on the cost tradeoff between your variant and an RS485 variant.
The manual I linked to says that the device has an RS485 interface but the drawings at the end of the manual appear to show a standard TTL serial interface. You should verify exactly what model you have.