Pages: [1]   Go Down
Author Topic: time and date library  (Read 598 times)
0 Members and 1 Guest are viewing this topic.
ottawa, canada
Offline Offline
God Member
*****
Karma: 6
Posts: 990
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm trying to use the time and date library and i'm getting odd results - probably something i don't understand.  I can use the setTime with a single argument of seconds since 1970 but when i try to use it with multiple arguments [setTime(hr,min,sec,day,month,yr)] I get anomalous results.

The following is adapted from the serial example - it should show the same time twice(I thought) but no such luck. I tried it on arduino 21 just in case but no change.
Code:
/*
 * TimeSerial.pde
 * you can send the number on the next line to set the clock to noon Jan 1 2010
 1262347200 
 */
 
#include <Time.h> 

void setup()  {
  Serial.begin(115200);
  Serial.println("Testing Time Setting Functions");
  setTime(1262347200); // seconds since jan 1 1970
  digitalClockDisplay(); 
  setTime(12,0,0,1,1,2010); // another way to set the time setTime(hr,min,sec,day,month,yr)
  digitalClockDisplay();   
}

void loop(){   
}

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

the results are
Code:
Testing Time Setting Functions
12:00:00 1 1 2010
22:22:56 31 10 2020
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Arduino 21 on a Duemilanove:
Testing Time Setting Functions
12:00:00 1 1 2010
12:00:00 1 1 2010
Logged

ottawa, canada
Offline Offline
God Member
*****
Karma: 6
Posts: 990
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Arduino 21 on a Duemilanove:
Testing Time Setting Functions
12:00:00 1 1 2010
12:00:00 1 1 2010

huh!  Thanks so much for trying it paul.  did you download the library recently?  I notice it's got fixes as of july.

running off to get my due...
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
did you download the library recently?
Half an hour ago...
Logged

ottawa, canada
Offline Offline
God Member
*****
Karma: 6
Posts: 990
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok, this is the oddest darned thing.  using a diecimila/168 i get correct results, my RBBB with 328 gives incorrect results!

I'll move some processors around and see what's up.

Thanks again paul.

btw is your duemilanove a 168 or a 328.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A 328.

I downloaded 0022, and compiled and tested on a Mega2560. Same (good) results.
« Last Edit: July 12, 2011, 06:29:09 pm by PaulS » Logged

ottawa, canada
Offline Offline
God Member
*****
Karma: 6
Posts: 990
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok, took me a while to get a fresh 328 burned but the issue is the particular chip i was using.  i suspect maybe a bad memory patch that only showed up with a more complex program. huh!
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6250
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

...  I notice it's got fixes as of july.

Good to hear you found the problem.
FYI, the recent fix was only to correct the little used  convenience macro : daysToTime_t
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I want to display date and time on 16*4 lcd . i download DateTime.h library. but code was not complied. reply please
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6250
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I want to display date and time on 16*4 lcd . i download DateTime.h library. but code was not complied. reply please
The  DateTime library in the playground is obsolete and was replaced by newer code four years ago. There is a note on the web page for the old DateTime code that provides the link to the latest version:   http://playground.arduino.cc/Code/Time.

A little time searching in this forum or with google should turn up a number of examples of LCD clocks built using the Time library.
here is one example: http://blog.workingsi.com/2011/02/arduino-lcd-countdown-clock.html
 
Logged

Pages: [1]   Go Up
Jump to: