Hi all,
I have been spending a lot time browsing this forum while working on my school project, it has been very helpful thus far and thank you all for that!! I have been unable to find a solution to my current problem though.
I want to create a new file every month for logging data using an RTC. I am aware that the SD.open function only accepts character arrays, the following code is a result of my research to solve the problem, however, it still doesn't work. The only thing I can get to work is when I physically type in a desired file name with quotes i.e. ... SD.open("FILE NAME.TXT" , FILE_WRIGHT); I don't understand why SD.open won't accept a char variable as an argument, or in this instance at least.
Here is the function I have written to try and accomplish this, any help is greatly appreciated!!!
void create_file()
{
DateTime now = rtc.now();
t_year = now.year();
t_month = now.month();
if(t_month != time_month_past) file_flag = 0;
if(file_flag == 0)
{
file_flag = 1;
String temp;
temp.reserve(25);
temp = String("Data-");
temp += String(t_month);
temp += String("-");
temp += String(t_year);
temp += String(".txt");
char filename[temp.length()+1];
temp.toCharArray(filename, sizeof(filename));
// Open/create the log file
dataFile = SD.open(filename, FILE_WRITE);
if (! dataFile)
{
// Wait forever, cant write data
while (1) ;
}
}
time_month_past = t_month;
}
Hardware:
Arduino Leonardo
Adafruit Assembled Data Logger (Adafruit Assembled Data Logging shield for Arduino : ID 1141 : $13.95 : Adafruit Industries, Unique & fun DIY electronics and kits)