Arduino mega to Arduino mega Serial communication problem


I have a system whereby two Arduino megas communicate via Serial0 (0,1 pins). One is the master the other is the slave.

If both units are connected to the PC via USB, everything works fine. However when I connect up both units to a 12V PSU via the dc plugs and not to USB, both Arduinos no longer communicate to each other. All other code functions still work fine except receiving data. I am using the Serial. Print() function.

Any help would be appreciated.

Thanks in advance.

Serial0 is connected to the on-board serial-USB chip (ATMEGA16 I think). If you try to use pins 0 & 1 to communicate with other hardware, then you will most likely end up fighting with the ATMEGA16.

What happens if you were to use Serial1 (pins 18 & 19) on both boards instead?


Serial1 is already connected to sensors and are working fine. Do I need to have 5V input via the USB socket to have Serial0 working then? This can be done as the Arduino is not powering any external devices only itself.

I believe that the MEGA16 is powered from the same +5V as the MEGA2560 so as long as you have power to the board from some source, then Serial0 will be "active". I just checked the schematic and it shows a couple of 1K resistors in the Tx & Rx lines to the MEGA16. I don't know if that means that an external device connected to pins 0 & 1 will be able to override the signals from the MEGA16 or not.

If the USB cable is not connected, a connection can be established on the serial pins TX0 and RX0 from another device. The Mega16 works only as USB -> TTL converter.

This is not what I am seeing. With both devices connected to the PC everything works fine.

With both devices not connected to PC, only to each other via Rx0, Tx0 and GND, all code works except for communication on the Serial0 line. This does nothing as far as I can see.

Unless I misread the schematic, even with the USB cable disconnected, the Mega16 is still powered up. In which case the Mega16 serial Tx pin will be being driven rather than floating.