Datalogger code help

Hey so I have the code and everything finished for my project the issue is my datalogger writes into the CSV. file as the time stamp and then returns the line under it as the data collected for that time. This makes it very hard to export the data to excel. How do I send the time stamp to a 2nd column so it correlates to the corresponding data point? TIA

void initializeCard(void)
{
Serial.print(F("Initializing SD card..."));

// Is there even a card?
if (!digitalRead(cardDetect))
{
Serial.println(F("No card detected. Waiting for card."));
while (!digitalRead(cardDetect));
delay(250); // 'Debounce insertion'
}

// Card seems to exist. begin() returns failure
// even if it worked if it's not the first call.
if (!SD.begin(chipSelect) && !alreadyBegan) // begin uses half-speed...
{
Serial.println(F("Initialization failed!"));
initializeCard(); // Possible infinite retry loop is as valid as anything
}
else
{
alreadyBegan = true;
}
Serial.println(F("Initialization done."));

Serial.print(fileEC);
if (SD.exists(fileEC))
{
Serial.println(F(" exists."));
}
else
{
Serial.println(F(" doesn't exist."));
}

Serial.print(fileDO);
if (SD.exists(fileDO))
{
Serial.println(F(" exists."));
}
else
{
Serial.println(F(" doesn't exist. "));
}

Serial.print(fileTEMP);
if (SD.exists(fileTEMP))
{
Serial.println(F(" exists."));
}
else
{
Serial.println(F(" doesn't exist."));
}
Serial.println(F(" CARD INITIALIZATION DONE "));
}

void tim()
{
DateTime now = rtc.now(); //get the current date-time
uint32_t ts = now.getEpoch();

// if (old_ts == 0 || old_ts != ts) {
// old_ts = ts;
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.date(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.print(' ');
Serial.print(weekDay[now.dayOfWeek()]);

Serial.println();

fd.print(now.year(), DEC);
fd.print('/');
fd.print(now.month(), DEC);
fd.print('/');
fd.print(now.date(), DEC);
fd.print(' ');
fd.print(now.hour(), DEC);
fd.print(':');
fd.print(now.minute(), DEC);
fd.print(':');
fd.print(now.second(), DEC);
fd.print(' ');
fd.print(weekDay[now.dayOfWeek()]);

fd.println();
}

Don't end the timestamp print with println(), just print() and the next thing sent will be on the same line.

1 Like

Okay will that then allow me to export the data to excel and the time stamp will be in 1 column and the data in another?

Thanks!

Try printing a comma in between the timestamp and the data point. That should make Excel put the data in a separate column.

print() the timestamp
print() a comma (",")
println() the data point // print the data point and advance to next line

1 Like

I'm not sure I'm understanding you, can you show it to me via my code?

see at the end:

A comma should tell Excel to advance to the next column and a line feed to advance to the next row.

1 Like

Okay that works for one sensor but I am running three sensors off this board at once so when I add that line for all 3 their data gets all mixed up. I have each sensors data going to a separate csv file. When I implemented your suggestion the data from other sensors was coming into every document

Your posted code only shows printing the date and time to serial and one file. How am I to know what you are doing without seeing the full and complete code?

[quote="chandler54412, post:7, topic:849151"]
the data from other sensors was coming into every document[/quote]
I don't know what that means. Show an example of what is being printed. Show an example of what is being saved to the file(s). Show what it is supposed to look like.

[quote="chandler54412, post:7, topic:849151"]
have each sensors data going to a separate csv file
[/quote]That sounds like a really bad idea and may be better solved in Excel than Arduino.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.