Hello Everyone, I'm new to arduino, this is my first post, so please help if anything goes wrong.
I am currently working on a project that requires this RTC and SDCard module. I want this SDCard to create a new log file when the day changes. (1 file 1 day). but i can not figured it out.
this is my simple sketch
#include<stdlib.h>
#include <SPI.h>
#include "Wire.h" // I2C
#include <SD.h>
#include "RTClib.h"
RTC_DS1307 RTC;
char daysOfTheWeek[7][12] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
const int chipSelect = 53;
void setup()
{
Serial.begin(9600);
while (!Serial) {
}
if (!SD.begin(chipSelect)) {
Serial.println("Error!\t");
return;
}
RTC.begin();
RTC.adjust(DateTime(__DATE__, __TIME__));
}
void loop()
{
DateTime now = RTC.now(); // get time from RTC
int time = now.second();
delay(2000);
File dataFile = SD.open("datalog.txt", FILE_WRITE);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (dataFile) {
dataFile.print(daysOfTheWeek[now.dayOfTheWeek()]);
dataFile.print(now.day(), DEC);
dataFile.print('/');
dataFile.print(now.month(), DEC);
dataFile.print('/');
dataFile.print(now.year(), DEC);
dataFile.print(" , ");
dataFile.print(now.hour(), DEC);
dataFile.print(':');
dataFile.print(now.minute(), DEC);
dataFile.print(' ');
dataFile.close();
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(now.day(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.year(), DEC);
Serial.print(" , ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.println(now.minute(), DEC);
}
else {
Serial.println("Error");
}
}
Thank You,
i really appreciate any advice