My total sketch size is about 28000 bytes and has been working fine for many days. When I add a few String operations and String.toCharArray to the code, it freaks out, where "freaks out" = the Arduino keeps resetting itself and seems to get reset either at the string appending operation or the toCharArray operation.
Here's an excert from the code,
int Year = 11; // The Real-time clock writes to variable Year, as a two-digit int.
void setup() {
Serial.begin(9600);
Serial.println("Debug");
}
void loop() {
String LogFileString = "BTU-20";
String Extension = ".csv";
char LogFileChar[13]; // This will become BTU-2011.csv as a character array
String YearString = String(Year); // Convert 2-digit integer year to string
LogFileString += YearString;
LogFileString += Extension;
LogFileString.toCharArray(LogFileChar,13);
// Convert the string to a character array, BTU-2011.csv
// Character arrays are required by SD.open, i.e.
// File dataFile = SD.open(LogFileChar, FILE_WRITE);
Serial.println(LogFileChar);
delay(1000);
}
The odd thing is that when I run this sketch by itself, it prints the expected response, BTU-2011.csv. In my 28000 byte code, when I comment out the 3 lines that are the string operators and the toCharArray, my code works as expected. Anybody have any idea what's going on?
I am trying to create a logfile name for SD.open based on the real-time clock year. SD.open insists on having a character array, but I don't want to use a constant like "BTU-2011.csv".
I began efforts to do this another way, as follows,
int Year = 11; // The Real-time clock writes to variable, Year, as a two-digit int.
void setup() {
Serial.begin(9600);
Serial.println("Debug");
}
void loop() {
int Year = 11;
char YearChar[3];
int right_digit;
int left_digit;
left_digit = Year / 10;
right_digit = Year % 10;
YearChar[0] = left_digit;
YearChar[1] = right_digit;
Serial.println(YearChar);
}
but became discouraged when Serial.println(YearChar) printed:
bh
(space)bh
I'd then need to figure out how to append character arrays. At any rate, the first method above seemed like the most straight-forward approach, but I'm stumped.