Go Down

Topic: storing and writing multiple files on SD card (Read 271 times) previous topic - next topic

daanslag

Hello everyone,

I'm working on a Lysimeter for a project and I need to write data to a new file every day. I now just get it that it writes everything to just one file. I also looked on other Topics but could not get it to work. The file name does not have to be anything special, just different files counting up would satisfy. I use the Deek-robot data logger shield that contains a RTC. The code that I got so far is the basic data logging code.

Code: [Select]
//#include <BlockDriver.h>
//#include <FreeStack.h>
//#include <MinimumSerial.h>
//#include <SdFat.h>
//#include <SdFatConfig.h>
//#include <SysCall.h>

#include <RTClib.h>

#include <SPI.h>

#include <Wire.h>

#include <SD.h>

//#include <Adafruit_HX8340B.h>
const int chipSelect = 10; //cs or the save select pin from the sd shield is connected to 10.
RTC_DS1307 RTC;
float celsius, fahrenheit;

File dataFile;
DateTime now;

void setup(void) {
  Serial.begin(9600);
  //setup clock
  Wire.begin();
  RTC.begin();
//check or the Real Time Clock is on
  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    // uncomment it & upload to set the time, date and start run the RTC!
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
//setup SD card


If anyone knows how to do this would be amazing!

Greetings,

Daniƫl

Nick_Pyner

#1
May 23, 2018, 06:22 pm Last Edit: May 23, 2018, 06:25 pm by Nick_Pyner
You are using a clock, so you can use the date as a filename and change at midnight.
Something like
Code: [Select]

char filename[] = "00000000.CSV";
File myFile;
Setup
   GetClock();
   getFileName();
........................................
Loop
 GetClock();
  if (today != day)//midnight?
  {
   today = day;
   getFileName();
}

................................................
void getFileName(){
sprintf(filename, "%02d%02d%02d.csv", year, month, day);
}

Go Up