Datasheet

Now the code starts to talk to the SD card, it tries to initialize the card and find a
FAT16/FAT32 partition.
Next it will try to make a logfile. We do a little tricky thing here, we basically want the files to
be called something like LOGGERnn.csv where nn is a number. By starting out trying to
create LOGGER00.CSV and incrementing every time when the file already exists, until we
get to LOGGER99.csv, we basically make a new file every time the Arduino starts up
To create a file, we use some Unix style command flags which you can see in the
logfile.open() procedure. FILE_WRITE means to create the file and write data to it.
Assuming we managed to create a file successfully, we print out the name to the Serial port.
OK we're wrapping up here. Now we kick off the RTC by initializing the Wire library and
poking the RTC to see if its alive.
Then we print the header. The header is the first line of the file and helps your spreadsheet
or math program identify whats coming up next. The data is in CSV (comma separated
value) format so the header is too: "millis,time,light,temp" the first item millis is
milliseconds since the Arduino started, time is the time and date from the RTC, light is the
Wire.begin();
if (!RTC.begin()) {
logfile.println("RTC failed");
#if ECHO_TO_SERIAL
Serial.println("RTC failed");
#endif //ECHO_TO_SERIAL
}
logfile.println("millis,time,light,temp");
#if ECHO_TO_SERIAL
Serial.println("millis,time,light,temp");
#if ECHO_TO_SERIAL// attempt to write out the header to the file
if (logfile.writeError || !logfile.sync()) {
error("write header");
}
pinMode(redLEDpin, OUTPUT);
pinMode(greenLEDpin, OUTPUT);
// If you want to set the aref to something other than 5v
//analogReference(EXTERNAL);
}
© Adafruit Industries https://learn.adafruit.com/adafruit-data-logger-shield Page 62 of 68