Hi I'm trying to make a temperature logger though struggling to get a header automatically added to my csv files!
For some reason (beyond me!) I can log data to a csv file though can't initially add the headers.
Therm_temp_logger.ino (2.57 KB)
Hi I'm trying to make a temperature logger though struggling to get a header automatically added to my csv files!
For some reason (beyond me!) I can log data to a csv file though can't initially add the headers.
Therm_temp_logger.ino (2.57 KB)
You must write the header just after opening a NEW file
robtillaart:
You must write the header just after opening a NEW file
I thought I had done that in my sketch! Can you advise further please?
//Write Log File Header
File logFile = SD.open("LOG.csv, FILE_WRITE");
if (logFile)
{
logFile.println(", ,"); //Just a leading blank line, incase there was previous data
logFile.println("ID, Temp1");
logFile.close();
Serial.println("ID, Temp1");
}
else
{
Serial.println("buggered");
}
some hints ..
void setup()
{
Serial.begin(9600);
analogReference(EXTERNAL);
delay(10000);
Serial.println("Initializing Card");
//CS Pin is an output
pinMode(CS_pin, OUTPUT);
//Check if card ready
if(!SD.begin(CS_pin))
{
Serial.println("Card Failure");
return; ////////////////////////////// will continue with loop!
}
Serial.println("Card Ready");
//
bool newfile = SD.exists("LOG.csv"); // something like this
//Write Log File Header
File logFile = SD.open("LOG.csv, FILE_WRITE");
if (logFile)
{
if (newfile)
{
logFile.println("ID, Temp1, Temp2");
}
else
{
logFile.println(", , ");
}
logFile.close();
Serial.println("ID, Temp1");
}
else
{
Serial.println("Couldn't open log file");
}
}
robtillaart:
some hints ..
Unfortunately I'm still receiving:-
Initializing Card
Card Ready
Couldn't open log file
1, 22
2, 22
3, 22
replace
File logFile = SD.open("LOG.csv, FILE_WRITE");
with
File logFile = SD.open("LOG.csv", FILE_WRITE);
robtillaart:
replace
File logFile = SD.open("LOG.csv, FILE_WRITE");with
File logFile = SD.open("LOG.csv", FILE_WRITE);
God how simple a mistake! Thanks, your a life saver! If only I could of asked you that 4 hours ago lol
I didn't see it in the first quick look either