Software Date Time library, uploads, then what?

I found this: Software Date Time library in arduino playground. I downloaded it into arduino-0013 > hardware > libraries. There is a read only memo that gives directions and a sample sketch to upload to your arduino. I did all this. The verify and upload went just fine, but nothing happened.
What else needs to be done?
It can be found here:http://www.arduino.cc/playground/Code/DateTime

It seems to me that LED-13 should blink, and info should appear on the serial monitor, but none of this happens.

I would like to know how to use this software.

// DateTime.pde
// example sketch for the DateTime library

#include <DateTime.h>
#include <DateTimeStrings.h>

#define TIME_MSG_LEN 11 // time sync to PC is HEADER followed by unix time_t as ten ascii digits
#define TIME_HEADER 255 // Header tag for serial time sync message

void setup(){
Serial.begin(19200);
pinMode(13,OUTPUT); // we flash the LED each second
}

void loop(){
unsigned long prevtime;
if( getPCtime()) { // try to get time sync from pc
Serial.print("Clock synced at: ");
Serial.println(DateTime.now(),DEC);
}
if(DateTime.available()) { // update clocks if time has been synced
digitalWrite(13,LOW); // first flash the LED
prevtime = DateTime.now();
while( prevtime == DateTime.now() ) // wait for the second to rollover
;
DateTime.available(); //refresh the Date and time properties
digitalClockDisplay( ); // update digital clock

// send our time to any app at the other end of the serial port
Serial.print( TIME_HEADER,BYTE); // this is the header for the current time
Serial.println(DateTime.now());
digitalWrite(13,HIGH);
}
delay(100);
}

boolean getPCtime() {
// if time sync available from serial port, update time and return true
while(Serial.available() >= TIME_MSG_LEN ){ // time message consists of a header and ten ascii digits
if( Serial.read() == TIME_HEADER ) {
time_t pctime = 0;
for(int i=0; i < TIME_MSG_LEN -1; i++){
char c= Serial.read();
if( c >= ‘0’ && c <= ‘9’){
pctime = (10 * pctime) + (c - ‘0’) ; // convert digits to a number
}
}
DateTime.sync(pctime); // Sync Arduino clock to the time received on the serial port
return true; // return true if time message received on the serial port
}
}
return false; //if no message return false
}

void digitalClockDisplay(){
// digital clock display of current date and time
Serial.print(DateTime.Hour,DEC);
printDigits(DateTime.Minute);
printDigits(DateTime.Second);
Serial.print(" “);
Serial.print(DateTimeStrings.dayStr(DateTime.DayofWeek));
Serial.print(” “);
Serial.print(DateTimeStrings.monthStr(DateTime.Month));
Serial.print(” ");
Serial.println(DateTime.Day,DEC);
}

void printDigits(byte digits){
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if(digits < 10)
Serial.print(‘0’);
Serial.print(digits,DEC);
}

thanks

Hi pakrat, the sketch is waiting for the time to be set from the pc.

If you add the following line in setup, the clock will start from Jan 1 2009 when the sketch starts: DateTime.sync(1230768000);

MEM stated:

Hi pakrat, the sketch is waiting for the time to be set from the pc.

If you add the following line in setup, the clock will start from Jan 1 2009 when the sketch starts:
DateTime.sync(1230768000);

Thanks Mem. I got the sample sketch to operate, using the whole sketch by itself, but I’m not sure of how to use the datetime library in another sketch.
I triied using parts of the sample code in another sketch and got decimal numbers to start at zero and increase by one per second,
using this much of the sample code:

#include <DateTime.h>
#include <DateTimeStrings.h>

void setup(){
  Serial.begin(9600);
  DateTime.sync(1230768000);
}

void  loop(){
  unsigned long  prevtime; 
  prevtime = DateTime.now();
  Serial.print("Clock synced at: ");
   Serial.println(DateTime.now(),DEC);
 }

It appears to me that the whole dateTime sample code needs to be applied in whatever sketch is being used. So I tried that, but it didn’t work.

I notice that after the sketch is stopped or shut down, upon restarting the timing starts right from the beginning. It seems that this code will be useful in a chip that is in continuous use, but in a chip that will be stopped or disconnected then moved, things could get confusing, especially if used for intermittant data logging.

Thanks
Pakrat

It appears to me that the whole dateTime sample code needs to be applied in whatever sketch is being used. So I tried that, but it didn't work.

I notice that after the sketch is stopped or shut down, upon restarting the timing starts right from the beginning. It seems that this code will be useful in a chip that is in continuous use, but in a chip that will be stopped or disconnected then moved, things could get confusing, especially if used for intermittant data logging.

Thanks Pakrat

In cases where it's required that the application retain time and date when stopped or powered down and restarted, a popular solution is a RTC (real time clock) module. It uses a small battery to retain the information and is available to the Arduino program by reading when wanting the data. It's a classic trade-off choice of doing something in software only or using external hardware to make the program simpler and smaller.

Here is a typical RTC module:

http://www.sparkfun.com/commerce/advanced_search_result.php?keywords=DS1307&search_section=products

And here is some supporting software from the Arduino playground to utilize the DS1307 RTC.

http://mrdoall.dnsalias.com/wiki/index.php/RTC1307_-_Real_Time_Clock

Lefty

Thanks Lefty. I looked that up, it is a possibility.

Pakrat

As Lefty says, you probably want to use a hardware clock with battery backup if the arduino is likely to be power off. For my own clock I use the radio signal from an ‘atomic clock’ I bought from ebay. It was half the price of the Sparkfun board, but it is more complicated to integrate so perhaps go with Lefty’s solution unless you enjoy taking things apart and hacking them to re-use for other purposes

The code you posted tries to print the raw time so the output is not very user friendly. Here is a sketch that prints the hour, minutes and seconds from a clock that starts at midnight when the sketch begins.

#include <DateTime.h>

void setup(){
  Serial.begin(9600);
  DateTime.sync(1230768000);
}

void loop(){
  if(DateTime.available())  
    digitalClockDisplay( );   // update digital clock
  delay(1000);
}

void digitalClockDisplay(){
  Serial.print(DateTime.Hour,DEC);
  printDigits(DateTime.Minute);
  printDigits(DateTime.Second);
  Serial.println();
}

void printDigits(byte digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits,DEC);
}

Hi,

Thank you very much, i search one way like that to display the time !!!

thanks again !!!

aseh