Time and TimeAlarms Libraries – Ask here for help or suggestions

I got the same errors here with arduino 18, 22 and 1.01. and different Time lib versions.

/usr/share/arduino/libraries/Time/DateStrings.cpp:18:18: error: variable 'monthStr1' must be const in order to be put into read-only section by means of 'attribute((progmem))'

The fix for my debian system was:

go back to gcc-avr version 4.3.5-1 * and
go back to avr-libc version 1.6.8-2 *

Now everything compiles just fine

  • i updated to gcc-avr 4.7.0-2 and avr-libc 1.8.0-2 which broke compiling TIME libs.

Having fun again
Jan

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: Arduino Playground - 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.

Hello everybody!

In my project I needed to set the ds1307rtc from individual input something that the ds1307 included with time lack.

So I want to shear the updated file that include now the function:

void set(int hour, int min, int sec, int day, int month, int year);

year input can be either in 4 or 2 digit format.

You can download it from my project's sourceforge page:

http://sourceforge.net/projects/computerizedtel/files/DS1307RTCNEW.rar/download

Enjoy

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.

There are two libraries folders - one in your sketch folder and one in the folder where you installed the Arduino IDE. Which one did you copy the Time library to? The one in the Arduino IDE folder is NOT the proper place for user-downloaded libraries.

The BYTE message indicates that the library that contains it has not been updated for 1.0+.

How to update it has been covered many times, many ways, many places.

Pauls: Please indicate at least one or two of the places where update instructions are given. I'm new to this and so don't know where to look. Thanks !!

I'm new to this and so don't know where to look.

There is a search field on every single page. You could type your exact error message into that field and see what comes up.

Is anyone maintaining the time and timealarms libraries? If so, can a version updated to support 1.0.1 be made available? I've searched and can't find it, so if this is already done, please direct me to the latest location. I have modified the version accessible from on the playground page to work wtih 1.0.1 for my own use, but it would cause a lot less confusion if there were an updated version available. If this were done, PAULS wouldn't have to tell quite so many people how to use the search function... :slight_smile:

Quarencia:
Is anyone maintaining the time and timealarms libraries? If so, can a version updated to support 1.0.1 be made available?

Good question, I would hope so.

I've searched and can't find it, so if this is already done, please direct me to the latest location. I have modified the version accessible from on the playground page to work wtih 1.0.1 for my own use, but it would cause a lot less confusion if there were an updated version available.

What mods did you make? The only change to the libraries that I found was necessary was that TimeAlarms.cpp needed the following. Strange because the Time and DS1307RTC libraries were updated for 1.0. Several of the examples have other version-related issues, though.

#if ARDUINO >= 100
#include <Arduino.h> 
#else
#include <WProgram.h> 
#endif

If this were done, PAULS wouldn't have to tell quite so many people how to use the search function... :slight_smile:

Indeed :wink:

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){      
    sysTime++;
    prevMillis += 1000;	
#ifdef TIME_DRIFT_INFO
    sysUnsyncedTime++; // this can be compared to the synced time to measure long term drift     
#endif	
  }
  ...

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;
#ifdef TIME_DRIFT_INFO
	  sysUnsyncedTime += diffSecs // this can be compared to the synced time to measure long term drift     
#endif	
	} else {
	  sysTime -= diffSecs;
	  prevMillis -= diffMillis;
#ifdef TIME_DRIFT_INFO
	  sysUnsyncedTime -= diffSecs; // this can be compared to the synced time to measure long term drift     
#endif
	}
  }
  ...

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

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.

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.

-Ty

This is still an issue. I've some patched code that works 1/2 of the time.. I would sure like to see a Test sketch that works...
@Mem: Great Book, Was Extremely helpful... and I re-read it frequently Thank You Sir.

I took your GPS time sketch and married it to a GPS and a GLCD separately both work but:
This one fails to transfer data from the gps routines to the clock I am very tired... of looking at it, There are some debug things and the separators need to be fixed but
I have a gps unit working with a sketch I put together from harts suggestions and a graphics LCD but there were several compelling reasons to use your sketch so...
MORE at Bottom

/*
 * TimeGPS_Round1.ino
 * example code illustrating time synced from a GPS
 * 
 */

#include <Time.h>
#include <TinyGPS.h>
// GPS Library is the work of Mikal Hart
#include <UTFT.h>
extern uint8_t SmallFont[];
UTFT myGLCD(ITDB32S,38,39,40,41);   // Mega2560

TinyGPS gps; 

const int offset = -7;   // offset hours from gps time (UTC)
time_t prevDisplay = 0; // when the digital clock was displayed

void setup()
{
  myGLCD.InitLCD();  // '0' is default landscape '1' is portrait
  myGLCD.setFont(SmallFont);
  //myGLCD.clrScr();

  //Serial1.begin(9600);  // 9600 baud for Skylabs SKM53
  Serial1.begin(4800);  // 4800 baud for U-Blox_6-1
  myGLCD.print("Waiting for GPS time ... ",8,0);
  setSyncProvider(gpsTimeSync);
  myGLCD.clrScr();
}

void loop()
{
  while (Serial1.available()) 
  {
    gps.encode(Serial1.read()); // process gps messages
    // Debug Messages
    myGLCD.print("Waiting for GPS time ... ",CENTER,120);  [color=red]// This works[/color]
    myGLCD.printNumI(hour(),64,24,2,'0'); // Prints 2 digit hour with leading 0
  //myGLCD.print(":",76 ,24); // separator not really rerquired
  myGLCD.printNumI(minute(),84,24,2,'0');
    myGLCD.printNumI(second(),104,24,2,'0');
   // End of Debug messages
  }
  if(timeStatus()!= timeNotSet) 
  
  {
    if( now() != prevDisplay) //update the display only if the time has changed
    {
     myGLCD.print("Waiting for GPS time ... ",CENTER,110);  [color=orange]//This doesn't it never gets here[/color]   
      prevDisplay = now();
      digitalClockDisplay();  
    }
  }	 
}

void digitalClockDisplay(){
  // digital clock display of the time

  myGLCD.setColor(255,255,0);
  myGLCD.print("Date :",8 ,8);
  myGLCD.printNumI(month(),64,8,2,'0'); // Prints 2 digit month with leading 0
  myGLCD.print("/",80 ,8);  // 
  myGLCD.printNumI(day(),88,8,2,'0');  // Prints 2 digit day with leading 0
  myGLCD.print("/20",104,8);
  myGLCD.printNumI(year(),112,8); 
  myGLCD.print("Time :",8 ,24);
  myGLCD.printNumI(hour(),64,24,2,'0'); // Prints 2 digit hour with leading 0
  //myGLCD.print(":",76 ,24); // separator not really rerquired
  myGLCD.printNumI(minute(),84,24,2,'0');
  // myGLCD.print(":",94 ,24);
  myGLCD.printNumI(second(),104,24,2,'0');
}
/* NOT REQUIRED, UTFT LIB DOES THIS NICELY
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);
}
*/
time_t gpsTimeSync(){
 
  //  returns time if avail from gps, else returns 0
  unsigned long fix_age = 0 ;
  gps.get_datetime(NULL,NULL, &fix_age);
  //unsigned long time_since_last_fix;  // *****COMMENTING OUT THIS*****  [b]Yeah I know this is stupid... but when I did it I was too @ 4:00 AM <BG>[/b]
 // if(fix_age < 1000)   //  *****AND THIS*****
    return gpsTimeToArduinoTime(); // return time only if updated recently by gps  
 // return 0;  // *****FIXED THE ISSUE... Why is an issue??*****
}

time_t gpsTimeToArduinoTime()
{
  myGLCD.print("Waiting for GPS time ... ",CENTER,90);
  // returns time_t from gps date and time with the given offset hours
  tmElements_t tm;
  int year;
  gps.crack_datetime(&year, &tm.Month, &tm.Day, &tm.Hour, &tm.Minute, &tm.Second, NULL, NULL);
  tm.Year = year - 1970; 
  time_t time = makeTime(tm);
  
  return time + (offset * SECS_PER_HOUR);
}

{Edit //COMMENT Are the things I changed
Any Help would be appreciated I attached the file W/O the commented mods described above.
{Edit. I added the finished metrology functions to the basic timeGPS Sketch and used an Itead 3.2 GLCD because of the really nice libs that come with it.
UTFT By Henning Karlsen works well with the Itead product... At about $17.00 a copy for a 3.2" 320X240 display it's hard to beat (W/Touch & SDcard)

Bob

TimeGPS_GLCD_Round1.ino (2.9 KB)

Time_Baro_R_H__GLCD_R1_2.ino (5.64 KB)

 // return 0;  // *****FIXED THE ISSUE... Why is an issue??*****

I'm not sure what you are asking here.

Commenting both lines caused the GPS time to work... sort of it is on page 3 of this group second up from the last post. After I commented out the code It worked. It was @ 4AM for me... I didn't see that I had commented a comment.. and I then posted a request the next day and later asked you to follow up on it later. In the second attachment is the core of my measurement sketch, I'll post the full thing If it will help as I would like whatever criticism it deserves... and that I might deserve... I've thrown enough bricks to take a few...

Bob

Here is Ver 1_2 of my little sketch for a Mega2560 It used a GPS receiver, a BMP085 Barometer/thermometer, a DHT22 hygrometer and a 320X240 Itead display.
Comments are Most welcome. It's attached to the previous post. and "Presented Here":

/*
 * TimeGPS.pde
 * example code illustrating time synced from a GPS
 * Robert K.Johnson
 */
#include "DHT.h"
#include <Time.h>
#include <TinyGPS.h>
// GPS Library is the work of Mikal Hart
#include <UTFT.h>
#include <Wire.h>
#include <BMP085.h>
extern uint8_t SmallFont[];
UTFT myGLCD(ITDB32S,38,39,40,41);   // Mega2560
BMP085 dps = BMP085();      // Digital Pressure Sensor instance
TinyGPS gps; // GPS Receiver instance 
#define DHTPIN 8     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE);

long Temperature = 0, Pressure = 0, Altitude = 0, Far = 0, Pres = 0; //, Far2 = 0;    // Variable's for display and conversion
const int offset = -7;   // offset hours from gps time (UTC)
time_t prevDisplay = 0; // when the digital clock was displayed "0"

void setup()
{
  Wire.begin();    // Start Wire (IIC)
  delay(1000);    // Waait for IIC to init. 
  dht.begin();
  myGLCD.InitLCD();  // '0' is default landscape '1' is portrait
  myGLCD.setFont(SmallFont);
  //Serial1.begin(9600);  // 9600 baud for Skylabs SKM53
  Serial1.begin(4800);  // 4800 baud for U-Blox_6-1

  setSyncProvider(gpsTimeSync);
  myGLCD.clrScr();
  myGLCD.setColor( 180,0, 0);
  myGLCD.drawRect(0, 6, 150,90);
  // uncomment for different initialization settings
  //dps.init();   // QFE (Field Elevation above ground level) is set to 0 meters.
  // same as init(MODE_STANDARD, 0, true);

  //dps.init(MODE_STANDARD, 101850, false);  // 101850Pa = 1018.50hPa, false = using Pa units
  // this initialization is useful for normalizing pressure to specific datum.
  // OR setting current local hPa information from a weather station/local airport (QNH).

  dps.init(MODE_ULTRA_HIGHRES,5366, true);  // 53.66 meters, true = using meter units (176' Google Earth)
  // this initialization is useful if current altitude is known,
  // pressure will be calculated based on TruePressure and known altitude.

  // note: use zeroCal only after initialization.
  // dps.zeroCal(101800, 0);    // set zero point
}
void loop()
{
  while (Serial1.available()) 
  {
    gps.encode(Serial1.read()); // process gps messages
  }
  if(timeStatus()!= timeNotSet) 
  {     
    if( now() != prevDisplay) //update the display only if the time has changed 
    {
      prevDisplay = now();
      digitalClockDisplay();  
    }
  }	 
}

void digitalClockDisplay()
{  // digital clock display of the time
  //myGLCD.setColor(255,255,255);
  myGLCD.print("Date :",8 ,12);  // Print date label
  myGLCD.printNumI(month(),64,12,2,'0'); // Prints 2 digit month with leading 0
  myGLCD.print("/",80 ,12);  // 
  myGLCD.printNumI(day(),88,12,2,'0');  // Prints 2 digit day with leading 0
  myGLCD.print("/20",104,12);
  myGLCD.printNumI(year(),112,12); // Print the Year
  myGLCD.print("Time :",8 ,24);  // Print Time label
  myGLCD.printNumI(hourFormat12(),64,24,2,'0'); // Prints 2 digit 12 hour format with leading 0
  myGLCD.printNumI(minute(),84,24,2,'0');
  myGLCD.printNumI(second(),104,24,2,'0');
  myGLCD.print("RH % :",8 ,36);   // Print weather info labels
  //myGLCD.print(" : % RH",94 ,36);
  myGLCD.print("Baro :",8 ,48);  // Print weather info labels
  myGLCD.print(":InHg",102 ,48);
  myGLCD.print("Temp :",8 ,60);
  myGLCD.print("Temp :",8 ,72);
  myGLCD.print(":DegF",102 ,60);
  myGLCD.print(":DegC",102 ,72);

  if (isAM())
  {
    myGLCD.setColor( 0,180, 0);  //set rect line color for AM indicator color
    myGLCD.drawRect(0, 6, 150,90);
    myGLCD.setColor(255,255,255);
    myGLCD.print(":AM",120,24);
  }  
  if(isPM())
  {
    //fillScr(180,180,180);
    myGLCD.setColor( 0, 0,180);  //set rect line color for PM indicator color
    myGLCD.drawRect(0, 6, 150,90); //draw a line 4 lines away from text  ***78
    myGLCD.setColor(180,180,180);  //Set text color
    myGLCD.print(":PM",120,24);
  }
  { 
    dps.getPressure(&Pressure);    // Get Barimetric data +/- 1% accurate, in Millibars X 10
    dps.getAltitude(&Altitude);    // get Altimeter Data... Call doesn't return good data
    dps.getTemperature(&Temperature);     // Get Temperature Data +/- 1% accurate, Deg. C X 10

    Temperature = Temperature +2 ;  //Calibration factor for fine temp cal
    Far = (((Temperature  * 18) + 3200) / 10);   // Far(enheit) conversion X 10
   
    Pressure = ((2953 * Pressure) / 100000); // Comvert  Pressure in Millibars X 10 to In/Hg X 10
    Pressure = Pressure - 22 ;   // Pressure Calibration adjustment subtracts .2 In/Hg
   
    float PreS = (Pressure / 100.0);
    float TemP = (Far/10.0);
    myGLCD.printNumF(PreS,2,64 ,48);
    myGLCD.printNumF(TemP,2,64 ,60);
   // myGLCD.printNumF(t,2,64 ,90);
    float h = dht.readHumidity();
    float t = dht.readTemperature();

    // check if returns are valid, if they are NaN (not a number) then something went wrong!
    if (isnan(t) || isnan(h)) 
    {
      h = 00.0;
      myGLCD.printNumF(h,2,64 ,36);
    } 
    else 
    {
      myGLCD.printNumF(h,2,64 ,36);
     myGLCD.printNumF(t,2,64 ,72); 
    }

  }
}
time_t gpsTimeSync()  //  returns time if avail from gps, else returns 0  
{ 
  unsigned long fix_age = 0 ;
  // OK TO HERE
  gps.get_datetime(NULL,NULL, &fix_age);
  // unsigned long time_since_last_fix;  // **********COMMENTING THIS WAS DUMB...*************
  //if(fix_age < 1000)                   // ******BUT THIS******
  return gpsTimeToArduinoTime(); // return time only if updated recently by gps  
  //return 0;                            // ******AND THIS MAKES IT WORK, WHY??******
}

time_t gpsTimeToArduinoTime()  
{ // returns time_t from gps date and time with the given offset hours 
  tmElements_t tm;
  int year;
  gps.crack_datetime(&year, &tm.Month, &tm.Day, &tm.Hour, &tm.Minute, &tm.Second,NULL,NULL );
  tm.Year = year - 1970; 
  time_t time = makeTime(tm);
  return time + (offset * SECS_PER_HOUR);
}

Comments and suggestions are humbly requested. I can cut and paste fairly well. I've learned enough C and C++ from a cold start in march to get this far.

Bob

  Wire.begin();    // Start Wire (IIC)
  delay(1000);    // Waait for IIC to init.

You don't need to wait for I2C to initialize. I never do.


  myGLCD.print("Baro :",8 ,48);  // Print weather info labels
  myGLCD.print(":InHg",102 ,48);
...

You can save RAM by keeping these in Program Memory, eg.

  myGLCD.print(F("Baro :"),8 ,48);  // Print weather info labels
  myGLCD.print(F(":InHg"),102 ,48);

I'm not sure if it works here but it should.


  if (isAM())
  {
    myGLCD.setColor( 0,180, 0);  //set rect line color for AM indicator color
    myGLCD.drawRect(0, 6, 150,90);
    myGLCD.setColor(255,255,255);
    myGLCD.print(":AM",120,24);
  }  
  if(isPM())
  {
    //fillScr(180,180,180);
    myGLCD.setColor( 0, 0,180);  //set rect line color for PM indicator color
    myGLCD.drawRect(0, 6, 150,90); //draw a line 4 lines away from text  ***78
    myGLCD.setColor(180,180,180);  //Set text color
    myGLCD.print(":PM",120,24);
  }

If it isn't AM what else would it be?

How about:

  if (isAM())
    {
    myGLCD.setColor( 0,180, 0);  //set rect line color for AM indicator color
    myGLCD.drawRect(0, 6, 150,90);
    myGLCD.setColor(255,255,255);
    myGLCD.print(":AM",120,24);
    }  
  else
    {
    //fillScr(180,180,180);
    myGLCD.setColor( 0, 0,180);  //set rect line color for PM indicator color
    myGLCD.drawRect(0, 6, 150,90); //draw a line 4 lines away from text  ***78
    myGLCD.setColor(180,180,180);  //Set text color
    myGLCD.print(":PM",120,24);
    }

Is this the cause it appears to be the address to the var fix age
"gps.get_datetime(NULL,NULL, &fix_age);"
and this:
"if(fix_age < 1000)" shouldn't there be a dereference to &fix_age or do I need to go back 50 pages and read the several lessons again... I just noticed this and wondered about it as this was the beginning of my morning reading topic. Have only read the first 10 pages or so.

Bob