Go Down

Topic: Time and TimeAlarms Libraries – Ask here for help or suggestions (Read 78 times) previous topic - next topic


A couple of folks earlier in the thread were wondering why the TimeGPS example didn't seem to be doing anything - I was too, until I spent a little while looking at it this evening. I've written it up over on my blog, but the basic problem is that the sketch invokes the sync provider function before any data has actually been received from the GPS, so there's never going to a suitable date/time at that point. However, because TinyGPS returns a value and the sketch doesn't validate it, it thinks that zero is a valid date value and that gets mapped to 31/12/1999. Job jobbed, date set, nothing more to do here then. Except that this means you don't see anything in the Serial Monitor window except "Waiting for GPS time ...".

I've added in some validation checks to the sketch and updated it to reference the SoftwareSerial libbrary instead of NewSoftSerial and it now works as expected. If anyone is maintaining the Time library and its examples, feel free to roll the code into the download version.

Cheers, Stu


I've been having problems using Time library with watchdog timer. What I see is that at seemingly random times the Arduino gets reset.

I now believe its down to the following code in Time.cpp:

time_t now(){
  while( millis() - prevMillis >= 1000){     
    prevMillis += 1000;   
    sysUnsyncedTime++; // this can be compared to the synced time to measure long term drift     

in that if the clock drift is negative, the while loop can be quite expensive.
I've replaced it with:

time_t now(){
  unsigned long nowMillis = millis();
  unsigned long diffMillis = 0;
  if (nowMillis > prevMillis) diffMillis = nowMillis - prevMillis;
  else diffMillis = prevMillis - nowMillis;
  unsigned long diffSecs = diffMillis / 1000;
  if (0 != diffSecs)
   if (nowMillis > prevMillis) {
     sysTime += diffSecs;
     prevMillis += diffMillis;
     sysUnsyncedTime += diffSecs // this can be compared to the synced time to measure long term drift     
   } else {
     sysTime -= diffSecs;
     prevMillis -= diffMillis;
     sysUnsyncedTime -= diffSecs; // this can be compared to the synced time to measure long term drift     

is this library maintained? Do you agree with this is an issue and with the fix?


Did you ever get to resolve the issue? I'm having the same issue and have no clue how to fix it  :~


Looks like 'charlya' had a go at fixing it. open up the library file ( Time.cpp ) and find the function 'now()', comment out the first 7 lines ( first code snippet ) and copy in the longer second code.


Hello, I'm trying to find out why the Examples in the Time library won't compile. 

I recently downloaded Ardiuno 1.0.1, then followed the directions on the Arduino playground - Time libary page at:  http://arduino.cc/playground/Code/Time

First, I downloaded the time.zip file, then extracted the folders within it.  This yielded one folder named "Time" as well as three folders within this top level "Time" folder.  These three folders were named "DS1307RTC", "Time", and "TimeAlarms" . 

Then I copied the "Time" library into the Arduino "libraries" folder, then started Arduino.exe, and selected TimeSerial.pde from the Examples list.  This sketch loaded and I pressed "Verify" and received the error message : "The 'BYTE' keyword is no longer supported.  "  All of the example sketches failed to compile but had different error messages. 

I think I did everything correct, and did it both for the top level "Time" folder and also for the "Time" folder contained within the top level folder.  Neither one worked. 

Unless I'm doing something wrong, there must be something wrong with the folder structure of the library, but, if so, I am surprised this error is not already well known. 

I'm not very experienced with Arduino, so that's why it is confusing. 

Thanks in advance for any information about this problem.   

I don't know if this is the right way to do it, but I switched 'BYTE' with 'byte(0)' and now it works for me.


Go Up