Pages: [1]   Go Down
Author Topic: Date as file name  (Read 585 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everyone!

I'm working on a datalogging project with Arduino Uno R3, and I wanted to know if there's a way to save files with the date and time, so it would create different files, anyone could give me any pointers on this?
Thank you for reading!
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13477
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you want a date you need an RTC (Real Time Clock).  This shield has all you need - http://www.ladyada.net/make/logshield/ - including some examples and tutorial.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, I'll check the tutorial, right now I'm using a chronodot, maybe there's something useful in the link.
Logged

Dee Why NSW
Offline Offline
Edison Member
*
Karma: 47
Posts: 2170
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try this with a DS1307

Code:
// This is  17 396

#include <SD.h>
#include "RTClib.h"
#include <Wire.h>
#include <string.h>

RTC_DS1307 RTC;
char filename[] = "00000000.CSV";
File myFile;

void setup()
{
Serial.begin(9600);
Wire.begin(); //Important for RTClib.h
RTC.begin();

if (! RTC.isrunning()) {

Serial.println("RTC is NOT running!");
return;
}

Serial.print("Initializing SD card...");

pinMode(10, OUTPUT);

if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
}

void loop()
{

getFileName();
createFileName();
delay(3000);
}

void getFileName(){

DateTime now = RTC.now();

filename[0] = (now.year()/1000)%10 + '0'; //To get 1st digit from year()
filename[1] = (now.year()/100)%10 + '0'; //To get 2nd digit from year()
filename[2] = (now.year()/10)%10 + '0'; //To get 3rd digit from year()
filename[3] = now.year()%10 + '0'; //To get 4th digit from year()
filename[4] = now.month()/10 + '0'; //To get 1st digit from month()
filename[5] = now.month()%10 + '0'; //To get 2nd digit from month()
filename[6] = now.day()/10 + '0'; //To get 1st digit from day()
filename[7] = now.day()%10 + '0'; //To get 2nd digit from day()

}

void createFileName(){
myFile = SD.open(filename, FILE_WRITE);
myFile.close();
}
Logged

Pages: [1]   Go Up
Jump to: