Datasheet
logfile.print(now.year(), DEC);
logfile.print("/");
logfile.print(now.month(), DEC);
logfile.print("/");
logfile.print(now.day(), DEC);
logfile.print(" ");
logfile.print(now.hour(), DEC);
logfile.print(":");
logfile.print(now.minute(), DEC);
logfile.print(":");
logfile.print(now.second(), DEC);
#if ECHO_TO_SERIAL
Serial.print(now.get()); // seconds since 2000
Serial.print(", ");
Serial.print(now.year(), DEC);
Serial.print("/");
Serial.print(now.month(), DEC);
Serial.print("/");
Serial.print(now.day(), DEC);
Serial.print(" ");
Serial.print(now.hour(), DEC);
Serial.print(":");
Serial.print(now.minute(), DEC);
Serial.print(":");
Serial.print(now.second(), DEC);
#endif //ECHO_TO_SERIAL
The first important thing is the delay() call, this is what makes the Arduino wait around until
its time to take another reading. If you recall we #defined the delay between readings to be
1000 millseconds (1 second). By having more delay between readings we can use less
power and not fill the card as fast. Its basically a tradeoff how often you want to read data
but for basic long term logging, taking data every second or so will result in plenty of data!
Then we turn the green LED on, this is useful to tell us that yes we're reading/writing data
now.
Next we call millis() to get the 'time since arduino turned on' and log that to the card. It can
be handy to have - especially if you end up not using the RTC.
Then the familiar RTC.now() call to get a snapshot of the time. Once we have that, we write
a timestamp (seconods since 2000) as well as the date in YY/MM/DD HH:MM:SS time
format which can easily be recognized by a spreadsheet. We have both because the nice
thing about a timestamp is that its going to montonically increase and the nice thing about
printed out date is its human readable
Log sensor data
© Adafruit Industries https://learn.adafruit.com/adafruit-data-logger-shield Page 81 of 85