Hello everyone.
I am trying to store files inside a series of folders, depending on the date.
I am using a RTC, and the standard SD library.
I have previously gotten the program to set the file name to the date, and I can figure out how to make my folders with the date, but I can not seem to figure out how to store my data logger file inside said folder.
Anyone have any suggestions?
Thank you.
#include <stdarg.h>
#include <Wire.h>
#include "RTClib.h"
#include <SD.h>
File root;
RTC_DS1307 RTC;
void setup()
{
//RTC.adjust(DateTime(__DATE__, __TIME__)); //sets RTC time to PC time at compiling.
Serial.begin(9600);
Serial.print("Initializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
pinMode(10, OUTPUT);
if (!SD.begin(8)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
File logfile;
Wire.begin();
RTC.begin();
Serial.println("done!");
DateTime now = RTC.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
// create a new file
char foldername[] = "03/03";
foldername[0] = now.month()/10 + '0'; //To get 1st digit from month()
foldername[1] = now.month()%10 + '0'; //To get 2nd digit from month()
foldername[3] = now.day()/10 + '0'; //To get 1st digit from day()
foldername[4] = now.day()%10 + '0'; //To get 2nd digit from day()
char filename[] = "0003AGM.CSV";
filename[0] = now.hour()/10 + '0'; //To get 1st digit from hour()
filename[1] = now.hour()%10 + '0'; //To get 2nd digit from hour()
filename[2] = now.minute()/10 + '0'; //To get 1st digit from minute()
filename[3] = now.minute()%10 + '0'; //To get 2nd digit from minute()
Serial.println(foldername);
Serial.println(filename);
SD.mkdir(foldername);
if (! SD.exists(filename)) {
// only open a new file if it doesn't exist
logfile = SD.open("foldername/filename", FILE_WRITE);
logfile.print("test");
logfile.flush();
}