I am using the Arduino library. I would like to log some data from a sensor, date-time stamp it and write it to a SD card.
To build the text file name I have tried
String dataFileName = String(String(sedClock.getTime().year(),DEC) +
String(sedClock.getTime().month(),DEC) +
String(sedClock.getTime().day(),DEC) +
String(sedClock.getTime().hour(),DEC) +
String(sedClock.getTime().minute(),DEC) +
String(sedClock.getTime().second(),DEC) + '_log.txt');
I would then like to log to that file using
pinMode(SD_PIN,OUTPUT);
dataFile = SD.open(dataFileName,FILE_WRITE);
But I get
no matching function call to SDClass::open(String&, int)
candidates are: File SDClass::open(const char*,uint_8)
But it seems that Arduino string doesn't have the equivalent of
(const char *) dataFileName.c_str()
So I can't figure out how to do the correct conversion
Any help would be greatly appreciated.
Thanks for your help. The solution was
char __dataFileName[sizeof(dataFileName)];
dataFileName.toCharArray(__dataFileName, sizeof(__dataFileName));
pinMode(SD_PIN,OUTPUT);
dataFile = SD.open(__dataFileName,FILE_WRITE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With