I recently started using the WString.h library for string manipulation as it greatly simplifies many of the difficulties. My latest project was working perfectly until I added WString. Basically, it was going bonkers after the same number of loops. I thought I may have simply run out of space, and switched to a 328. The problem persisted! It did however, make it a few more loops so memory seemed to be the likely cause. Basically I tracked it back to something with WString, but I'm not quite sure what. I was able to make a small example sketch that locks up.
#include <WString.h>
//Program Variables
String lineBuffer = String(50);
int i = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
lineBuffer = " This_Is_A_Test!!";
lineBuffer.append(i);
lineBuffer.append("00.00 ");
Serial.println(lineBuffer.substring(1, 17));
Serial.println(lineBuffer.substring(17, 23));
delay(10);
if (i < 9)
i++;
else
i=0;
}
Obviously this should just keep printing over and over, but this is as far as it gets.
This_Is_A_Test!!
000.00
This_Is_A_Test!!
100.00
This_Is_A_Test!!
200.00
This_Is_A_Test!!
300.00
This_Is_A_Test!!
400.00
This_Is_A_Test!!
500.00
This_Is_A_Test!!
600.00
This_Is_A_Test!!
700.00
This_Is_A_Test!!
800.00
This_Is_A_Test!!
900.00
This_Is_A_Test!!
000.00
This_Is_A_Test!!
100.00
This_Is_A_Test!!
200.00
This_Is_A_Test!!
300.00
This_Is_A_Test!!
400.00
This_Is_A_Test!!
500.00
This_Is_A_Test!!
600.00
This_Is_A_Test!!
700.00
This_Is_A_Test!!
800.00
h0
This_Is_A_Test!!
hh00.0
This_Is_A_Test!!
000.00
This_Is_A_Test!!
100.00
This_Is_A_Test!!
200.00
This_Is_A_Test!!
300.00
This_Is_A_Test!!
400.00
This_Is_A_Test!!
500.00
This_Is_A_Test!!
600.00
This_Is_A_Test!!
700.00
You can also see that there is some strange characters in there.
Any help is greatly appreciated.