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

Thread: TimeRTCSet Example Program - failing with this pictured setup

  1. #1
    Senior Member Davidelvig's Avatar
    Join Date
    Aug 2015
    Location
    Wisconsin
    Posts
    280

    TimeRTCSet Example Program - failing with this pictured setup

    Learning the Realtime Clock.
    Running the unmodified TimeRTCSet Example Program on a Teensy 3.2...
    This is the output:
    Click image for larger version. 

Name:	TimeRTCSet output.png 
Views:	5 
Size:	35.5 KB 
ID:	20828
    Here's Coin Cell setup
    Click image for larger version. 

Name:	TimeRTCSet-LiPo Connection.jpg 
Views:	4 
Size:	125.7 KB 
ID:	20829
    And here's the crystal (32.7680, 12.5pF) - Digikey 300-1002-ND
    Click image for larger version. 

Name:	TimeRTCSet-Crystal Connection.jpg 
Views:	5 
Size:	189.4 KB 
ID:	20830

    I'd welcome a pointer to a fix.

    Thanks!

    OSX: 10.14.6
    Arduino: 1.18.12
    Teensyduino: 1.51

    TimeRTCSet example sketch follows.
    Code:
    /*
     * TimeRTCSet.pde
     * example code illustrating Time library with Real Time Clock.
     *
     * RTC clock is set in response to serial port time message 
     * A Processing example sketch to set the time is included in the download
     * On Linux, you can use "date +T%s > /dev/ttyACM0" (UTC time zone)
     */
    
    #include <TimeLib.h>
    #include <Wire.h>
    #include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t
    
    
    void setup()  {
      Serial.begin(9600);
      while (!Serial) ; // Needed for Leonardo only
      setSyncProvider(RTC.get);   // the function to get the time from the RTC
      if (timeStatus() != timeSet) 
         Serial.println("Unable to sync with the RTC");
      else
         Serial.println("RTC has set the system time");      
    }
    
    void loop()
    {
      if (Serial.available()) {
        
        time_t t = processSyncMessage();
        if (t != 0) {
          RTC.set(t);   // set the RTC and the system time to the received value
          setTime(t);          
        }
      }
      digitalClockDisplay();  
      delay(1000);
    }
    
    void digitalClockDisplay(){
      // digital clock display of the time
      Serial.print(hour());
      printDigits(minute());
      printDigits(second());
      Serial.print(" ");
      Serial.print(day());
      Serial.print(" ");
      Serial.print(month());
      Serial.print(" ");
      Serial.print(year()); 
      Serial.println(); 
    }
    
    void printDigits(int digits){
      // utility function for digital clock display: prints preceding colon and leading 0
      Serial.print(":");
      if(digits < 10)
        Serial.print('0');
      Serial.print(digits);
    }
    
    /*  code to process time sync messages from the serial port   */
    #define TIME_HEADER  "T"   // Header tag for serial time sync message
    
    unsigned long processSyncMessage() {
      unsigned long pctime = 0L;
      const unsigned long DEFAULT_TIME = 1357041600; // Jan 1 2013 
    
      if(Serial.find(TIME_HEADER)) {
         pctime = Serial.parseInt();
         return pctime;
         if( pctime < DEFAULT_TIME) { // check the value is a valid time (greater than Jan 1 2013)
           pctime = 0L; // return 0 to indicate that the time is not valid
         }
      }
      return pctime;
    }

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,270
    It's trying to talk to a DS1307 chip, which you don't have. Do not use DS1307RTC.h.

    Follow the example from File > Examples > Time > TimeTeensy3.

    In particular, you need this in setup:

    Code:
      // set the Time library to use Teensy 3.0's RTC to keep time
      setSyncProvider(getTeensy3Time);

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

    and to set the time, you need this:

    Code:
          Teensy3Clock.set(t); // set the RTC
          setTime(t);

  3. #3
    Senior Member Davidelvig's Avatar
    Join Date
    Aug 2015
    Location
    Wisconsin
    Posts
    280
    Well, now that's better!
    Thanks, Paul!

    I'll move on to testing time-setting and power off use cases.

Posting Permissions

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