How to program for RTC with datalogger to collect the temperature details?

Hi there,

I want to build the Data-logger to collect the readings of Temperature Sensor. Can anyone please help me to program?

  • You can refer the example for camera where RTC is used.

    Following you can use

    RTC_TIMETYPE t;

    in main() function

    rtc_init();

       t.year = 15;

       t.mon = 9;

       t.day = 2;

       t.weekday = RTC_WEEK_WEDNESDAY;

       t.hour = 17;

       t.min = 0;

       t.second = 0;

       rtc_set_time(&t);

     this function will give to time data - rtc_get_time(&t);

    Regards,

    Shrenik

  • In reply to Shrenik:

    i didnt get the answer from above referral program, I'm just beginner so please post the program as I want.

    Thankyou for your response!

  • In reply to Krishnaraj V:

    I think you have asked for help. Don't mind but you should try first the answer given. If you are not able to do it then you can ask questions about exact problem. Give it a try and then we are happy to help.

  • In reply to Shrenik:

    Hi, here is a sample for you.

     

    #include <Arduino.h>

    #include <SD.h>

    #include <RTC.h>

    RTC_TIMETYPE t;

    void dateTime(uint16_t* date, uint16_t* time);

    void setup(){

       Serial.begin(9600);

       while(!Serial.available()); // wait to press key

       Serial.read(); //dummy

       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()){

           Serial.println("Card failed, or not present.");

           while(1);

       }

       SdFile::dateTimeCallback( &dateTime );

       File file = SD.open("sample.txt", FILE_WRITE);

       if(file){

           //Write

           Serial.println("Success to open sample.txt and write hello.");

           file.println("Hello, my SD");

           file.close();

       } else {

           Serial.println("Failed to open file.");

           while(1);

       }

    }

    void loop(){

    }

    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);

    }

  • In reply to Okamiya Yuuki:

    Thank you so much Okamiya Yuuki !

    I have one more question !

    Is there any way to write the CSV with two columns like Time(in milliseconds ) in One column and Temperature in another column?

    Please suggest me some program !!

  • In reply to Krishnaraj V:

    Ok. I will try to prepare tomorrow because it's midnight in Japan.

    Can you describe a sample in text?

  • In reply to Okamiya Yuuki:

    Really thankyou for your response!

    In my project, as the part, we have to collect the temperature readings in every 100 milliseconds using RTC and store all the details in Excel sheet (Data-logger) . I don't know how to program with RTC even I surf on it. But now I got idea from the program which you have mentioned above.

    The samples of reading given below:

    Time(ms) Temp

    100         22*C

    200         22*C

    300         22*C

    400         23*C

    500         23*C

    Actually, I got this Temperature readings in Arduino without RTC. Now I want the same along with the accurate timing details not the delay.

    I didn't get GR - Kaede Board till now. So I can't able to try with this board. I just do the program and compiling it.

  • In reply to Krishnaraj V:

    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);

    }

  • In reply to Okamiya Yuuki:

    Thank you so much Okamiya Yuuki !