make sure DTR is not low..
USB port typically disappears when unplugged..
curious, how you opened a non-existent port..
reset button is tied to DTR, bring DTR low/high will reset mega..
half a second it waits for sketch upload then already loaded sketch begins..
I use DTR when uploading, but that doesn't seem to solve the problem.
First of all, it seems that the problem is that the device continues to send data, and the Arduino is turned off, but it seems to be freezing because the buffer is full.
The Arduino will not function properly and can even be destroyed, if it is powered down with 5V applied (from an external source) to any of the input pins.
It that is happening with the MAX232, add a 10K resistor in series with MAX232 TX to Arduino RX connection, to limit the current flow through the input protection diode.
try using pin 18 and 19 and change Serial to Serial1..
Serial "0" is used for downloading sketches.. functions/communication/serial
kind of warn us not to use those ports and that mega has 4 in total..
use Serial for debugging when usb is plugged in and all the others for what ever..
look at how i did AckMe..
good luck.. ~q
This is why a schematic and photo of your setup is key to the answers you get.
The USB will power up the interface then put the serial Voltage onto the Arduino pins.
The easiest fix for this is to have a data only USB cable, then connect the power from the Arduino to the Max232 board, via an RC time delay. Time delay just needs to be long enough for the Arduino to start.
I have a similar problem with my 3D printer, which has a serial communication with a RasberryPi, easily solved by having the whole lot on the same supply switch, the printer firmware starts before the Pi has finished booting, thus avoiding the seial setup problem.
qubits-us Thanks for that info, nice to know for future reference.