Hi,
during an experiment I've found that my Arduino MEGA ADK get frozen after 4 String concatenation inside the loop function. This happens after one loop execution.
I'm compiling the code on Arduino IDE 1.0 on Windows 7 64bit.
Here the sample code:
void setup() {
Serial.begin(9600);
Serial.println("Ready");
}void loop() {
Serial.println("Creating myString");String myString = String("abcdefg");
myString += ",";
myString += String(123);
myString += String(123);Serial.print("myString: ");
Serial.println(myString);Serial.println("done!");
delay(1000);
}
Here's the output:
Ready
Creating myString
myString: abcdefg,123123
done!
Creating myString
What I don't understand is why this happens after one loop execution.
Other observations:
Replacing the String initialization with this one (removed the g char):
String myString = String("abcdef");
the program run fine.
If I allocate a second myString2 variable (initialized like before with "abcdef"), it works fine:
void setup() {
Serial.begin(9600);
Serial.println("Ready");
}
void loop() {
Serial.println("Creating myString");
String myString = String("abcdef");
myString += ",";
myString += String(123);
myString += String(123);
Serial.print("myString: ");
Serial.println(myString);
Serial.println("done!");
String myString2 = String("abcdef");
myString2 += ",";
myString2 += String(123);
myString2 += String(123);
Serial.print("myString2: ");
Serial.println(myString2);
Serial.println("done!");
delay(1000);
}
So a memory size problem can be excluded, right?