USB vs I2C

Hi guys
I am trying to control 3 Mega 2560 from my PC
What is the better way to do that?
1- Connecting the 3 Mega to my PC using 3 PC USB ports
2- Connecting the 3 through I2C with UNO as a Master

depends completely on your project - in concreto should the megas comunicate to each other or only to PC?

only to pc

Hi,

Sounds like you are asking the wrong question. You have a project or problem and you have decided that 3 megas is the solution. But you are already finding problems with that solution. Take a step back and describe the original project or problem in real-world terms. Try not to assume any part of the solution yet.

Paul

Yes, you are right
My main project is to control impulse relays by sending data from my USB to the mega boards. When I connect leds to the outputs, everything works fine but when I connect the relay board, after 40-50 attempts, an error occurred:
java.io.IOException: Input/output error in writeArray
at gnu.io.RXTXPort.writeArray(Native Method)
at gnu.io.RXTXPort$SerialOutputStream.write(RXTXPort.java:1124)
at processing.app.Serial.write(Serial.java:517)
at processing.app.Serial.write(Serial.java:540)

I thought that the I2C will stop this error but NO, the error is here one more time, oufffff

Patrick-:
I thought that the I2C will stop this error but NO, the error is here one more time, oufffff

And - why would you think that?

And - why would you think that?

when everything works fine and I remove the USB cable without closing the serial monitor, I get the same error so i thought that the problem is generated somewhere in the USB port and the solution is by sending data via I2c

Well, unplugging an (USB...) cable can produce garbage data. You can ignore such error messages if you know that it is related to unplugging. Or close the Serial Monitor prior to unplugging...

Well now, if you disconnect a USB cable to which a program is attached, you will tend to crash the program unless it is specifically written to detect closure of the virtual serial port, so that is pretty straightforward.

Unless you pay the most critical attention to ground returns, shielding, cable routing and supply decoupling, crashing programs (which may well include the USB drivers) by actuating relays or other electromagnets is a particularly common problem described here. There is no reason to imagine that I2C communication would not be even more sensitive.