i have an arduino , and im using it to log my PV system
Every 5 minutes i open the file, save data and close it again
every day i will create a new file
when starting the arduino it will check if SD card is OK, like this
void SetupSD()
{
// make sure that the default chip select pin of SPI is set to
// output, even if you don't use it:
// On the Mega, the hardware SS pin, 53, is not used to select either the W5100 or the SD card, but it must be kept as an output or the SPI interface won't work.
pinMode(10, OUTPUT);
pinMode(53, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(4))
{
SD_OK = false; //sd CARD NOT ok
}
else
{
SdFile::dateTimeCallback(dateTime); // set callback for SD file date
SD_OK = true; //sd CARD ok
}
}
what does this do??????
SdFile::dateTimeCallback(dateTime);
does it set the time when i file is written on SD card???
i googled and found also this text
Once you're done with writing files clean up with a call like this:
SdFile::dateTimeCallbackCancel();
Your code is incomplete, nothing is clear. It isn't even clear that you might have a problem.
I have never seen that command before. It could be something that was used in an older IDE and is now superceded, but it sounds like something particular to the clock library and used for data/time stamping the data entry. This presupposes you are using a clock library.
is for adding a callback function (dateTime) that sdfat library will call when it updates the file so the timestamp will be updated.
note that you must actually have the function named dateTime for this to work.
A dateTime function using Time RTC library would be
void dateTime(uint16_t* date, uint16_t* time) {
time_t t = now();
// return date using FAT_DATE macro to format fields
*date = FAT_DATE(year(t), month(t),day(t));
// return time using FAT_TIME macro to format fields
*time = FAT_TIME(hour(t), minute(t), second(t));
}
I used to have this in my code but since removed it since it really serves no purpose for me other than consume cpu cycles.
Yes in have
void dateTime(uint16_t* date, uint16_t* time)
{
// return date using FAT_DATE macro to format fields
*date = FAT_DATE(year(), month(), day());
// return time using FAT_TIME macro to format fields
*time = FAT_TIME(hour(), minute(), second());
}
in my program
so it is actually used for the time and date when file is saved last saved , what you see normally in the directory.. but this is done only when SD card is initialisated at powerup .. it is still not clear if it is neaded ..
also in the examples of the arduino , this code is not added
I see that the OP is using the SD library. I didn't see any documentation of this library using datetimecallback. I am trying to find out myself a way to add time stamp to files I opened with SD library. Is this the solution, defining a datetime function?