Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: Teensy 3.5 RTC problem

  1. #1
    Junior Member
    Join Date
    Jul 2020
    Posts
    2

    Teensy 3.5 RTC problem

    Hi
    I try to write a control program with a time code
    i want to write in the file and on screen the date and time (dd/mm/yyyy hh/mm/ss)
    i write this simple program:

    #include <TimeLib.h>

    // Variable Declaretion -----------------------------------------------------------

    //Time And Date Variables ---------------------------------------------------------

    String DandT;
    int Sec;
    int Mint;
    int Hr;
    int Dy;
    int Mnth;
    int Yr;
    String SSec;
    String SMint;
    String SHr;
    String SDy;
    String SMnth;
    String SYr;

    //----------------------------------------------------------------------------------


    void setup() {

    Serial.begin(9600);

    // Clock Setup Only For The First Time ---------------------------------------------
    setTime(22, 34, 25, 29, 3, 1982);
    //----------------------------------------------------------------------------------

    }




    void loop() {

    // SetUp Time String For Display --------------------------------------------------
    Sec=int(second());
    Mint=int(minute());
    Hr=int(hour());
    Dy=int(day());
    Mnth=int(month());
    Yr=int(year());

    if (Sec<10){
    SSec="0"+String(Sec);
    }else{
    SSec=String(Sec);
    }
    if (Mint<10){
    SMint="0"+String(Mint);
    }else{
    SMint=String(Mint);
    }
    if (Hr<10){
    SHr="0"+String(Hr);
    }else{
    SHr=String(Hr);
    }
    if (Dy<10){
    SDy="0"+String(Dy);
    }else{
    SDy=String(Dy);
    }
    if (Mnth<10){
    SMnth="0"+String(Mnth);
    }else{
    SMnth=String(Mnth);
    }
    SYr=String(Yr);


    DandT=(SDy+"/"+SMnth+"/"+SYr+" "+SHr+":"+SMint+":"+SSec);

    //------------------------------------------------------------------------------------


    Serial.println (DandT);



    delay (500);


    }

    time_t getTeensy3Time()
    {
    return Teensy3Clock.get();
    }



    A 3V battery is connected to the Vb pin and to the GND

    but when i delete the set time line it is always go back to 1.1.1970

    why?
    how can i keep the time from restarted again every time?

    thank you

  2. #2
    Senior Member
    Join Date
    May 2017
    Posts
    106
    Hello,

    you don't sync your timeLib with RTC of teensy, so TimeLib starts with zero UNIX time (1.1.1970).
    TimeLIB and RTC are two independend objects.

    To unterstand have look there https://forum.pjrc.com/threads/47988...?highlight=RTC , especialy posts of Paul Stofffregen there.
    Check also https://www.pjrc.com/teensy/td_libs_Time.html

  3. #3
    Junior Member
    Join Date
    Jul 2020
    Posts
    2
    Hi
    Thanks for the answering
    But I still do not understand/able to sync them to work properly
    When I run the teensy3 example the rtc is sync with my computer and run OK, i connect the battery and just can not syc it back
    (probably a noob problem)

    thanks for any one that solve this problem

  4. #4
    Senior Member
    Join Date
    May 2017
    Posts
    106
    You should post your source code and your serial monitor output here.
    Then its much easier to help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •