Mit dem Programm können mit dem Arduino, dem RTC-Modul DS3231 und einem SD-Karten Adapter
Zeit und Temperatur geloggt und zur späteren Auswertung auf einer SD-Karte gespeichert werden.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
// DS3231_Time &Temperature // Copyright (C)2017 Harald Peusmann (harald [at] peusmann [dot] eu). All right reserved // web: https://wp.peusmann.eu // // Kleines Daten-log-Programm // Mit diesem Programm werden Uhrzeit und Temperatur // vom DS3231 auf eine SD-Karte geschrieben #include <DS3231.h> #include <SPI.h> #include <SD.h> #include <Wire.h> // Init the DS3231 using the hardware interface DS3231 rtc(SDA, SCL); const int chipSelect = 10; int entryId = 0; void setup() { // Setup Serial connection Serial.begin(115200); // Uncomment the next line if you are using an Arduino Leonardo //while (!Serial) {} // //Wire.begin(); Serial.print("Initializing SD card..."); // 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."); // Initialize the rtc object rtc.begin(); } void loop() { // Send current time & temperature Serial.print("Time: "); Serial.println(rtc.getTimeStr()); Serial.print("Temperature: "); Serial.print(rtc.getTemp()); Serial.println(" C"); // open the file (datalog.txt) only 8+3 file names allowed. // 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) { entryId ++; // count every loop, the output on the SD-Card looks like // 1,23:59:59,26.25 Serial.println("Write to SD-Card:"); dataFile.print(entryId); dataFile.print(","); dataFile.print(rtc.getTimeStr()); dataFile.print(","); dataFile.println(rtc.getTemp()); dataFile.close(); // print to the serial port too: Serial.print(entryId); Serial.print(","); Serial.print(rtc.getTimeStr()); Serial.print(","); Serial.println(rtc.getTemp()); Serial.println("End of Writing"); } // if the file isn't open, pop up an error: else { Serial.println("error opening datalog.txt"); } delay (30000); } |