Quantcast
Channel:
Viewing all articles
Browse latest Browse all 59170

Forum Post: RE: How to program for RTC with datalogger to collect the temperature details?

$
0
0
Hi, I have made a sample for logging A0 pin, the log is saved in SD 100ms interval.   The current library of RTC doesn't have 100ms interval interrupt, only 1sec alarm interrupt. (File result) Time(ms) Temp 100 366 200 428 300 465 400 494 (Sample code) /* GR-KAEDE Sketch Template Version: V1.13 */ #include Arduino.h #include "SD.h" #include "RTC.h" RTC_TIMETYPE t; void dateTime(uint16_t* date, uint16_t* time); void setup() {    pinMode(PIN_LED0, OUTPUT); // for SD access    pinMode(PIN_LED1, OUTPUT); // for File access    pinMode(PIN_LED2, OUTPUT); // for File write access    pinMode(PIN_LED3, OUTPUT);    Serial.begin(9600);    rtc_init();    t.year = 15;    t.mon = 9;    t.day = 25;    t.weekday = RTC_WEEK_WEDNESDAY;    t.hour = 0;    t.min = 1;    t.second = 0;    rtc_set_time(&t);    if (!SD.begin()) {        while (1)            ; // error    } else {        digitalWrite(PIN_LED0, HIGH); // Success to access SD.    }    SdFile::dateTimeCallback(&dateTime);    if (SD.exists("sample.txt")) {        SD.remove("sample.txt");    }    File file = SD.open("sample.txt", FILE_WRITE);    if (file) {        //Write        file.println("Time(ms)\tTemp");        file.close();        digitalWrite(PIN_LED1, HIGH); // Success to open file.    } else {        while (1)            ;    } } void loop() {    static unsigned long currenttime, oldtime = 0;    static unsigned long starttime = millis();    currenttime = millis() - starttime;    if ((currenttime - oldtime) = 100) {        digitalWrite(PIN_LED2, HIGH); // blink LED        File file = SD.open("sample.txt", FILE_WRITE);        file.print(currenttime);        file.print("\t");        file.println(analogRead(A0));        file.close();        digitalWrite(PIN_LED2, LOW);        oldtime = currenttime;    } } void dateTime(uint16_t* date, uint16_t* time) {    rtc_get_time(&t);    *date = FAT_DATE(t.year + 2000, t.mon, t.day);    *time = FAT_TIME(t.hour, t.min, t.second); }

Viewing all articles
Browse latest Browse all 59170

Trending Articles