I would like to write the time and maybe the date to my SD card everything compiles fine the the data is wrong.
here is the code:
res=file.openFile("LogData.TXT", FILEMODE_TEXT_WRITE);
file.openFile("LogData.TXT", FILEMODE_TEXT_WRITE);
if (res==NO_ERROR)
{
// RTC Time Function
DateTime now = RTC.now();
varHour = (now.Hour(), DEC);
char varHourChar[60];
String varHourStr;
varHourStr=String(varHour); //converting integer into a string
varHourStr.toCharArray(varHourChar,60); //passing the value of the string to the character array
Serial.print("Min is:");
Serial.println(varHourChar);
file.writeLn(varHourChar);
Serial.print(varHourChar);
//file.writeLn((now.minute(), DEC));
file.closeFile();
what i get is "10" in the serial window and on the sd card
this is the code for all the date and time:
// Make a string for assembling the data to log:
String dataString = "";
char *dataStringChar;
// Assemble Strings to log data
String theyear = String(now.year(), DEC); //"integer" converting integer into a string
String mon = String(now.month(), DEC); //"integer" converting integer into a string
String theday = String(now.day(), DEC); //"integer" converting integer into a string
String thehour = String(now.hour(), DEC); //"integer" converting integer into a string
String themin = String(now.minute(), DEC); //"integer" converting integer into a string
//Put all the time and date strings into one String
dataString = String ("LED On: " + theyear + "/" + mon + "/" + theday + ", " + thehour + ":" + themin + " | ");
dataString.toCharArray(dataStringChar,60); // passing the value of the string to the character array
// write the dataString to the microSD card
file.writeLn(dataStringChar);
Serial.print(dataString);
This does not work as well!
I would think that I could do something like this
file.writeLn((now.minute(), DEC));
but that gets a error:
error: initializing argument 1 of 'uint16_t tinyFAT::writeLn(char*)'
The issue seems to be here: "file.writeLn(dataString);"
// Make a string for assembling the data to log:
String dataString = "";
char *dataStringChar;
// Assemble Strings to log data
String theyear = String(now.year(), DEC); //"integer" converting integer into a string
String mon = String(now.month(), DEC); //"integer" converting integer into a string
String theday = String(now.day(), DEC); //"integer" converting integer into a string
String thehour = String(now.hour(), DEC); //"integer" converting integer into a string
String themin = String(now.minute(), DEC); //"integer" converting integer into a string
//Put all the time and date strings into one String
dataString = String ("LED OFF: " + theyear + "/" + mon + "/" + theday + ", " + thehour + ":" + themin + " | ");
// write the dataString to the microSD card
file.writeLn(dataString);
I get this error:
error: no matching function for call to 'tinyFAT::writeLn(String&)'
D:\Arduino\arduino-1.5.2\libraries\tinyFAT/tinyFAT.h:126: note: candidates are: uint16_t tinyFAT::writeLn(char*)
If I add this code to it
dataString.toCharArray(dataStringChar,120); // passing the value of the string to the character array
file.writeLn(dataStringChar);