/* SD card datalogger */ #include #include #include "RTClib.h" #include "Adafruit_MAX31855.h" #define DP 1 // No. decimal places for serial output RTC_DS1307 rtc; //call library for clock //assign variables for max31855 const int chipSelect = 10; const int thermoCLK = 3; const int thermoCS = 4; const int thermoDO = 5; Adafruit_MAX31855 thermocouple(thermoCLK, thermoCS, thermoDO); // initialize the thermocouple void setup() { Serial.begin(57600); // Open serial communications and wait for port to open: while (!Serial) { // wait for serial port to connect. Needed for Leonardo only ; } #ifdef AVR Wire.begin(); #else Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due #endif rtc.begin(); if (! rtc.isrunning()) { Serial.println("RTC is NOT running!"); // following line sets the RTC to the date & time this sketch was compiled rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // This line sets the RTC with an explicit date & time, for example to set // January 21, 2014 at 3am you would call: // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0)); } Serial.print("Initializing SD card..."); // make sure that the default chip select pin is set to // output, even if you don't use it: pinMode(10, OUTPUT); // see if the card is present and can be initialized: if (!SD.begin(chipSelect)) { Serial.println("Card failed, or not present"); // don't do anything more: return; } Serial.println("card initialized."); Serial.println("MAX31855 test"); // wait for MAX chip to stabilize delay(1000); } void loop(){ DateTime now = rtc.now(); //print date & time to serial 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); Serial.println(); // basic readout test, just print the current temp Serial.print("Internal Temp = "); Serial.println(thermocouple.readInternal()); float f = thermocouple.readFarenheit(); //variable to store temp if (isnan(f)) { Serial.println("Something wrong with thermocouple!"); } else { Serial.print("F = "); Serial.println(thermocouple.readFarenheit()); } // open the file. note that only one file can be open at a time, // so you have to close this one before opening another. File dataFile = SD.open("datalog.txt", FILE_WRITE); // if the file is available, write to it: if (dataFile) { DateTime now = rtc.now(); //write date & time to SD card dataFile.print(now.year(), DEC); dataFile.print('/'); dataFile.print(now.month(), DEC); dataFile.print('/'); dataFile.print(now.day(), DEC); dataFile.print(' '); dataFile.print(now.hour(), DEC); dataFile.print(':'); dataFile.print(now.minute(), DEC); dataFile.print(':'); dataFile.print(now.second(), DEC); dataFile.println(); //wirte temp to SD card dataFile.print("F = "); dataFile.println(thermocouple.readFarenheit()); dataFile.close(); // print to the serial port too: Serial.println(); } // if the file isn't open, pop up an error: else { Serial.println("error opening datalog.txt"); } delay(600000); //wait 10 minutes before next read/write }