I need to send manual serial input to 4 Arduino Uno separately and also receive and log data received from all of them in a single file. I can plug in 4 Arduino Uno as my laptop has four USB ports. But Arduino IDE is limited to communicating with one single Arduino Uno on a single port at a time.
You may connect MEGA with PC and then use its UART1, UART2, UART3, and SUART (Software UART Port) to communicate with respective SUART Ports of UNO-1 to UNO-4. The alternative is to use I2C Bus or even SPI Port.
Any terminal program will work to communicate over a COM port on your PC. There are many freeware programs available. I am not aware of one that will simultaneously send data to multiple ports or receive on multiple ports to place it all into one file.
You might use a Mega2560 as an aggregator for the four Unos, and write the data to an SD card. You haven't said much about what happens with the data (realtime analysis vs look-at-it-later, for example), so this might or might not be a useful suggestion.
C
I want to simultaneously charge/discharge 16 batteries. With voltage/current sensor can be configured only with 4 unique I2C address. Also each UNO runs out of I/O pin with charge, discharge relays and temperature measurements. So I will create 4 blocks, each block capable of charging/discharging 4 batteries.
Using MEGA sounds like a solution, will MEGA collect data from each of UART1, UART2, UART3 and SUART and send it combined to PC? Will it also be able to send instruction to each UART/SUART respectively? Can you please direct me to relevant materials? I can learn it by myself.
I2C bus is out of question as there are sensors. These sensors can have only 4 unique I2C bus and that is the first reason for using 4 UNO.
How can it be done over SPI? Can you please direct me to relevant materials?
Yes, the Mega could do the mux and aggregation. Pretty simple, really. Would allow you to write 1 application to run on the 4 Unos, and 1 application to do the data shuffling. Nice separation of purposes.
But I would suggest instead you look at:
With that you can do what you need with a single Nano or Uno - maybe put an SD card on one Uno, and go to it.
C
One more detail - how far apart are your sensor locations? If the batteries are all co-located, I2C is okay; if scattered across a large room, or a building, then you'll want a more robust communication layer; at that point, I'd fall back to, your 4 Unos on an RS485 string with a final node that gathers data and either writes it to SD, or sends it to the PC. This, by the way, will scale better if you expect your installation will grow.
C
Then the I2C multiplexer would seem to be a no-brainer. That, with a Nano/Uno to send your data to the PC, is pretty straightforward. On the PC end, you now need a simple serial terminal program to push your data to a file on the machine. Set your software up with two modes, because you'll want to debug a lot of it via Serial Monitor, then flip to a 'normal' mode to start sending data.
Or, as I said, use a Uno and add an SD card shield, store your data, and swap out the SD cards periodically.
Yes, an LCD display on the I2C buss will also allow you to display progress, status, etc.
All of this could be accomplished on a Nano, though if you get fancy with the LCD, you may wish you had more memory to work with.
C