Stuck in Uploading to I/O Board with Mega 2560

I am currently running into a condition where my sketch will not complete uploading to my Arduino. The upload never seems to complete (even after 30min or so).

There are 4 commented lines in the attached code that appear to cause the problem. Removing the comments will cause the trouble readily. With those lines commented (and it appears to be the if specifically) the sketch uploads just fine.

int CurrentMin = 1345;
int Alarm1 = 1355;
boolean Alarm1Triggered = false;

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

void loop() {
  delay( 5000 );
  CurrentMin = CurrentMin + 1; 
  Serial.println( CurrentMin );
  Serial.println( Alarm1 );
  if ( Alarm1Triggered == false ) {
//    if ( CurrentMin == Alarm1 ) {
//      Alarm1Triggered = true;
//      Serial.println( "Alarm has gone off!!!" );
//    }
  }
}

Please note that this sketch is just a sample to demonstrate the problem and is actually a very simplified subset of a bigger sketch. I am basically a beginner with the Arduino so maybe I missed something simple.

So can someone tell me what I am doing wrong?

You can try tu update your software. or recup an more old version. have you rightly selected your board?

I just tried uploading the code to a Duemilanove, after uncommenting the lines. It uploaded with no problems. It even works.

The numbers that are printed should have some identifiers in front of them, to define what they are, but that is all that I see is wrong.

I am using Arduino IDE 0022, so I already have the latest. I have my board selected correctly (Arduino Mega 2560) from the Tools - Board selection.

It is very odd. If I comment them everything uploads fine but with them uncommented it does not work. I tried adding the identifiers but that did not affect it at all. I wonder why it works differently on an Duemilanove (ie: it works). Are you using Windows or a different OS?

What is most frustrating is that without those lines it works fine. I have a whole webserver input/output sketch I have made that works fine and can be uploaded without trouble but I really want to have an alarm timer built in and this if statement is making that look doubtful.

I'm using Windows 7, 64 bit.

The identifiers a trivial. Whenever I print a number, I always print some identifier in front of it, so I can tell what the number means. I prefer that other people do that, too. If you don't want/need to, that's fine.

The only other thing I can think of that might explain the difference is that maybe one of the variable names is some sort of reserved keyword on the Mega, but that's really a stretch. You could try changing them to see if it makes any difference.

Perhaps someone else with a Mega 1280 or Mega 2560 could try uploading the sample, to see whether it uploads.

Ok. So no difference in OS (I am using Windows 7, 64bit also). I renamed all the variables and did a search on the site for any matches to those names (no hits for exact matches). Still failing.

I think if someone has a Mega 2560 to check this on it might be useful. I would not think it is a flaw with the bootloader... BUT I was in software QA and I still have that wonderful computer aura of what can go wrong around me at times.

Here is the latest "failing" code. Note: Problem is not commented at this time. If someone DOES have a Mega and has the problem, comment out the if statement for the IncrementingInteger == AlarmTriggerInteger and see if it still fails.

int IncrementingInteger = 1345;
int AlarmTriggerInteger = 1355;
boolean BooleanAlarmTriggered = false;

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

void loop() {
  delay( 5000 );
  IncrementingInteger = IncrementingInteger + 1;
  Serial.print( "Incrementing integer: " );
  Serial.println( IncrementingInteger );
  Serial.print( "Alarm trigger integer:" );
  Serial.println( AlarmTriggerInteger );
  if ( BooleanAlarmTriggered == false ) {
    if ( IncrementingInteger == AlarmTriggerInteger ) {
      BooleanAlarmTriggered = true;
      Serial.println( "Alarm has gone off!!!" );
    }
  }
}

Hi, I've tried your code on my 2560 and I get a 'avrdude: stk500_2_ReceiveMessage(): timeout' error. This is on OSX with version 22 of the arduino IDE.

If I delete one of the exclamation marks it works. Seems that the compiler doesn't like strings containing more than 2 exclamation marks in a row!!!

Hope that helps.

That was it?! I just tried it and sure enough it works just fine. I would say this is a definite bug for the 2560. Might be something in the bootloader. Fairly minor problem overall but who would think of it? I will check the problem lists to see if there is anything about this yet. If not I will submit it. Thanks very much for the help.

Hello,

I had a similar problem and found this thread. After removing the exclamation marks in my code uploading works again.

I also tried your code. With the exclamation marks it won't finish uploading. Always displaying the following:

avrdude: stk500_2_ReceiveMessage(): timeout

Without the exclamation marks uploading works.

I'm using an Mega 2560 with an EthernetShield. And Ubuntu 10.04 with Arduino 0021 64bit.

I meant to say IDE instead of compiler, but the same error on three different systems points to a bug specifically with the Mega. As you say, definatly a wierd one!

I created this thread in the Bugs & Suggestions category:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1294536128/0#0

I will edit it to add the point about you trying with Ubuntu and using 0021. I do not know if anything would result from it but it does not hurt to include all the details.

Does anyone reading this have an Uno they could try this out on? I am curious about whether it is a Mega 2560 problem or both of the new Arduinos being affected.

just tried it on a UNO
works fine
uploaded ok and serial monitor is showing

Alaarm trigger integer xxx
Incrementing integer xxx
Alarm has gone off!!!

Excellent, thanks for the input about the Uno. So as much as can reasonably be tested this is a Mega 2560 specific problem.

Did anyone try with longer strings??? replacing the exclamation mark with another character and trying again?

It might be something else than an exclamation mark...

I tried with a variety of strings including many that are longer (since I have many debug strings built in as I learn) but I have not tried other specialty characters. Something to check... I will come back with some results.

Edit - Tried with sets of the following characters and all succeeded:
` ~ @ # $ % ^ & * ( ) - _ = + [ { ] } | ; : ' , < . > / ?

Obviously using the following will not work (and yes I tried to prove it):
\ "
And the infamous !