Mega 2560 randomly hanging

Obviously, uploading a sketch.
I also have multiple issues like that.
I have a feeling there is some 'gray area' somehow related to MEGA bootloader.
Sketch is complicated enough, with Adafruit datalogger shioeld, LCD shield and QuadRAM shield.
It might be working perfectly well for days, than something happens and you cannot upload anymore.
Sometimes uploading another simple sketch helps, sometimes it does not.
My common impression is that Arduino MEGA 2560 is very unstable board, hardly useful for anything more complicated than blinking LEDs :frowning:
BTW, Ard DUE is even worse.

The arduino mega boards use a bootloader that has a 'special but never used' feature that if it sees three !!! characters in a row in the data being sent to the board during a upload operation, the bootloader enters a 'monitor' mode waiting for user commands from the PC that will never come. So while it may not be your problem specifically, but it has trapped a lot of other people, so check to see if you have any !!! strings in the sketch code and change them.

Lefty

Interesting. What exactly 3 characters? Any link to more detailed info on this?

Stan09:
Interesting. What exactly 3 characters? Any link to more detailed info on this?

The ! ASCII character, as in 0x21. So three 0x21 bytes sent in a row anywhere in the upload data stream locks up the bootloader waiting for user monitor commands from the PC which will never come. As far as more detailed info, there has been a lot posted in the forum over the years sense the original mega1280 board was released, but I'm not aware of any 'official' document posted on the arduino web site. There is mostly likely a old and mouldy bug report in the arduino developers bug reporting archive list wherever one finds that.

The source code for the mega bootloader is included in the IDE software distribution if you want to seek it out and read about this wonderful feature included in the mega bootloader code.

Lefty

retrolefty:
The ! ASCII character, as in 0x21. So three 0x21 bytes sent in a row anywhere in the upload data stream locks up the bootloader waiting for user monitor commands from the PC which will never come.

Just as an update, the latest Mega2560 bootloader is supposed to have fixed this particular problem. But that is no use to you if have a Mega with the old bootloader installed (unless you want to reflash the bootloader with the newer one.)

However, the latest version seems to have some new issues of its own. Refer this thread:

http://arduino.cc/forum/index.php/topic,136233.0.html

if it sees three !!! characters in a row

...

What exactly 3 characters?

Three !!! characters. Wasn't that part clear?

I'm sorry if I seemed a bit short. I meant, the character '!', three times. As in: !!!

I have the latest bootloader for the Mega2560, the one that fixes the watchdog problems. It also does not have the problems reported in the above thread. Running the test sketch:

void setup(){
  Serial.begin(9600);
}

void loop(){
  Serial.println("Hello world");
  delay(1000);
}

It commences executing immediately.

This file, I think:

Just confirmed it handles the "!!!" problem, it doesn't have a watchdog timer issue, and it doesn't have the problem with the 10-second wait. So, good to go!

pico:
However, the latest version seems to have some new issues of its own. Refer this thread:

That thread doesn't actually say he has "the latest version".

No, but I do have the latest version of the bootloader, and can report the problem occurs for that version interacting with IDE version 1.0.2 under Win XP sp 3.

Which version of OS and IDE are you using to test the bootloader interaction with?

My test was on 1.0.1 and Mac OS/X.

Have you access to 1.0.2 version?

It would be interesting to find out whether this problem was introduced in 1.0.2 generally, or just in Windows 1.0.2.

I tried it on 1.0.2 on the Mac and it worked OK (no delay to speak of).

I tried then with 1.0.3 (the latest right now) on Windows XP and it still worked OK. Maybe a slight delay of around a second.

I will DL 1.0.3 and test with that. (I didn't realize 1.0.3 was out already.)

I'm getting ~5-6 seconds delay on all baud rate settings I've tested in the 1.0.2 Serial monitor except 57600 (which starts as expected. This is the case regardless of the baud rate setting in Serial.begin() in the sketch.)

If you have another device, like a Uno, I would try the same sketch on that. That would tend to rule out either the board, or the serial monitor interface. It's also possible the software on the USB interface processor is different.

I've tried the same sketch on an Uno, Leo, Mega1280, but the only one that has the delay is the Mega2560 (which I only noticed recently, after I'd reflashed the latest bootloader.) And the delay is only with the IDE Serial monitor, there is no delay under Putty, etc.

I tested the Mega2560 w/ 1.0.3 under Windows, and same result -- about a 8-9sec delay between the reset and the sketch start (I was timing a bit more carefully), except when the serial monitor window is set to 57600, in which case ther is no noticeable delay.

I also tested it under 0023, and same result, so that means it's consistent with 0023,1.0.2 and 1.0.3.

So the interaction problem seems to have been introduced with the new version of the Mega2560 bootloader, rather than in any recent version of the IDE itself (and as noted previously, the interaction only occurs with the IDE, as the delay isn't observable running Putty, etc.)

Update:

No observable delay with Mega2560 bootloader testing with 1.0.1 or 1.5.1r2 under Win 7 (64 bit).