I'm making a data logger and stocking information in a SD card, I have a RTC module to know when I got the examples but there's an issue: I can't get the correct date when I save the .txt file.
Inside the file, the date & time are correct, but when I check the saving date from the file, it appears to be saved at 1:00:00 01/01/2000
Any suggestions?
You could use the date as the filename. I find it convenient to start a new file at midnight, and there is no need to record the date on the file. No need to use SDFat either.
Nick_Pyner Thanks for the advice but I need to get the date right.
PaulS Once I add the SdFat library to Arduino and run the examples there's an error message: "sketch_may04a.ino:6:21: fatal error: FatFile.h: No such file or directory" And I've already tried four times.
guerrero-1106:
Once I add the SdFat library to Arduino and run the examples there's an error message: "sketch_may04a.ino:6:21: fatal error: FatFile.h: No such file or directory" And I've already tried four times.
Strange...
Where do you downloaded the library?
Looks like something in the library's folder structure is not right...
If you don’t wish to use SDFat, you can get timestamps for the file modification dates using SD.h and the dateTimeCallback function and the FAT_DATE and FAT_TIME macros.
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <RTClib.h>
File file; // test file
const uint8_t SD_CS = 10; // SD chip select
RTC_DS1307 RTC; // define the Real Time Clock object
//------------------------------------------------------------------------------
// call back for file timestamps
void dateTime(uint16_t* date, uint16_t* time) {
DateTime now = RTC.now();
// return date using FAT_DATE macro to format fields
*date = FAT_DATE(now.year(), now.month(), now.day());
// return time using FAT_TIME macro to format fields
*time = FAT_TIME(now.hour(), now.minute(), now.second());
}
//------------------------------------------------------------------------------
void setup() {
Serial.begin(9600);
Wire.begin();
if (!RTC.begin()) {
Serial.println("RTC failed");
while(1);
}
// set date time callback function
SdFile::dateTimeCallback(dateTime);
if (!SD.begin(SD_CS)) {
Serial.println("SD.begin failed");
while(1);
}
file = SD.open("TEST4_SD.TXT", FILE_WRITE);
file.println("Testing 1,2,3...");
file.close();
Serial.println("Done");
}
//------------------------------------------------------------------------------
void loop() {}
Thanks all for your help, but I can't get to work neither the RTClib.h nor the SDFat.h and I don´t know why. By the moment I'm using DS1307RTC.h and TimeLib.h
PaulS How do I hardly run them?
Cattledog thanks for the code but as I said, the RTClib.h is not working for me.
It is not rocket science. Compare the ratio of questions we have asked to answers you have supplied. Notice that the ratio is greater than one. When it gets down to 1.0000, your code will have a much better chance of working.
Re-read ALL of the replies, and make sure that you have supplied an answer, or do so now.