Hi all.
got the sketch from: SD Card Library, file date & time fields question - #4 by cattledog
and it passed compiling for Arduino UNO.
got compiling ERROR: 'FAT_DATE' was not declared in this scope for ESP32 Dev Module.
How to fix please?
Thanks
Adam
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <RTClib.h>
File file; // test file
const uint8_t SD_CS = 10; // SD chip select
RTC_DS1307 RTC; // define the Real Time Clock object
char timestamp[30];
//------------------------------------------------------------------------------
// call back for file timestamps
void dateTime(uint16_t* date, uint16_t* time) {
DateTime now = RTC.now();
sprintf(timestamp, "%02d:%02d:%02d %2d/%2d/%2d \n", now.hour(),now.minute(),now.second(),now.month(),now.day(),now.year()-2000);
Serial.println("yy");
Serial.println(timestamp);
// return date using FAT_DATE macro to format fields
*date = FAT_DATE(now.year(), now.month(), now.day());
// return time using FAT_TIME macro to format fields
*time = FAT_TIME(now.hour(), now.minute(), now.second());
}
//------------------------------------------------------------------------------
void setup() {
Serial.begin(9600);
Wire.begin();
if (!RTC.begin()) {
Serial.println("RTC failed");
while(1);
};
// set date time callback function
SdFile::dateTimeCallback(dateTime);
DateTime now = RTC.now();
sprintf(timestamp, "%02d:%02d:%02d %2d/%2d/%2d \n", now.hour(),now.minute(),now.second(),now.month(),now.day(),now.year()-2000);
Serial.println("xx");
Serial.println(timestamp);
if (!SD.begin(SD_CS)) {
Serial.println("SD.begin failed");
while(1);
}
file = SD.open("TEST_SD.TXT", FILE_WRITE);
file.println("Testing 1,2,3...");
delay(5000);
file.close();
Serial.println("Done");
}
//------------------------------------------------------------------------------
void loop() {}
ERROR:
Arduino: 1.8.19 (Windows 7), Board: "ESP32 Dev Module, Disabled, Disabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, Core 1, Core 1, None, Disabled"
C:\Users\HUA.DELLV-PC\Documents\Arduino\sketch_nov04c\sketch_nov04c.ino: In function 'void dateTime(uint16_t*, uint16_t*)':
sketch_nov04c:20:10: error: 'FAT_DATE' was not declared in this scope
*date = FAT_DATE(now.year(), now.month(), now.day());
^~~~~~~~
sketch_nov04c:23:10: error: 'FAT_TIME' was not declared in this scope
*time = FAT_TIME(now.hour(), now.minute(), now.second());
^~~~~~~~
C:\Users\HUA.DELLV-PC\Documents\Arduino\sketch_nov04c\sketch_nov04c.ino:23:10: note: suggested alternative: 'LC_TIME'
*time = FAT_TIME(now.hour(), now.minute(), now.second());
^~~~~~~~
LC_TIME
C:\Users\HUA.DELLV-PC\Documents\Arduino\sketch_nov04c\sketch_nov04c.ino: In function 'void setup()':
sketch_nov04c:35:2: error: 'SdFile' has not been declared
SdFile::dateTimeCallback(dateTime);
^~~~~~
exit status 1
'FAT_DATE' was not declared in this scope
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.