Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Marzogh/8dc8011934eecf47e154 to your computer and use it in GitHub Desktop.
Save Marzogh/8dc8011934eecf47e154 to your computer and use it in GitHub Desktop.
This code allows you to add the date and time to your SD card log files generated by an Arduino.
#include <SD.h>
File file;
const uint8_t CS = 10; // SD chip select
// YOUR SKETCH SHOULD UPDATE THESE SIX VALUES
// EACH TIME BEFORE CREATING YOUR SD CARD FILE
unsigned int year = 2015;
byte month = 6;
byte day = 18;
byte hour = 7;
byte minute = 8;
byte second = 9;
void dateTime(uint16_t* date, uint16_t* time)
{
*date = FAT_DATE(year, month, day);
*time = FAT_TIME(hour, minute, second);
}
void setup()
{
Serial.begin(9600);
// THIS LINE SETS YOUR SKETCH TO SAVE YOUR
// TIME AND DATE INTO ANY FILE YOU CREATE.
SdFile::dateTimeCallback(dateTime);
if (!SD.begin(CS))
{
Serial.println("SD.begin failed");
while(1);
}
file = SD.open("TEST_IT.TXT", FILE_WRITE);
file.close();
Serial.println("Done");
}
void loop() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment