Last active
March 8, 2024 19:40
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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