I have a Mega 2560 that has been working fine as I develop my code. I want it to run stand-alone, while we occasionally connect to it via the main Serial port to check diagnostics that it spits out. I don’t want it to reboot when I connect, so I cut the RST-EN line, and now it doesn’t reset, as desired. However, I’m having trouble uploading new code.
The forums say to press the reset button just before or after hitting the upload button in the Arduino IDE, but it’s not working for me. Is there documentation on the exact order of operations? I’ve tried pressing and releasing it before and just after hitting upload, and even keeping it pressed while I hit upload and releasing a second afterwards. I’m sure the communications are fine because I successfully upload if I short the RST-EN lines together, but I’d much prefer to use reset (partly because I want to reset from software using the watchdog timer). The reset button does make the program restart, so it works, too. Any suggestions are appreciated.
BTW, the first thing my setup code does is Serial.begin(9600), but I assume the bootloader would check for an upload before running setup.
If you don't want the Mega to reset when serial connects, connect a 470nF ceramic capacitor from reset pin to GND, remove when you want to program the Mega.
I use a single pole double throw slide switch to enable / disable.
One possible option is to use one of the other UART ports for the diagnostics output? The Mega 2560 has 4 of them. To connect to USB on a PC or laptop would require one of those usb-to-serial adapters, e.g. like the FTDI board.
I guess the switch solution avoids that requirement and is probably simpler to implement.
Yes, but the boot-loader only runs when the MCU restarts. The restart is triggered by the DTR signal from the UART whenever a serial connection is made. The MCU then runs the boot-loader which first checks for an upload as you mention. If there is none after a specified time it just runs the sketch. So if the DTR signal is disconnected, then a board reset cannot be triggered via usb/serial and the boot-loader will not run unless you hit that reset button. Timing that manually is a bit of a fiddle, but usually does work after a few attempts.