Hi, I am using an ARDUINO Nano 328p 5V, a DS3231 as a RTC and the micro sd module. I'm wondering if it's possible to set the date of the file. Ex: Today it's 03/06/2020 so in the sd module the file would be: 03/06/2020.txt and if it's 04/06/2020, a new file.
Thanks.
I don't think you really need it but anyway:
#include <SD.h>
#include <SPI.h>
#include <DS3231.h>
File myFile;
DS3231 rtc(SDA, SCL);
int pinCS = 10;
void setup() {
Serial.begin(9600);
pinMode(pinCS, OUTPUT);
// SD Card Initialization
if (SD.begin())
{
Serial.println("SD card is ready to use.");
} else
{
Serial.println("SD card initialization failed");
return;
}
rtc.begin();
}
void loop() {
Serial.print(rtc.getTimeStr());
Serial.print(",");
Serial.println(int(rtc.getTemp()));
myFile = SD.open("test.txt", FILE_WRITE);
if (myFile) {
myFile.print(rtc.getTimeStr());
myFile.print(",");
myFile.println(int(rtc.getTemp()));
myFile.close(); // close the file
}
// if the file didn't open, print an error:
else {
Serial.println("error opening test.txt");
}
delay(3000);
}