Pages: 1 [2] 3 4 ... 7   Go Down
Author Topic: Who needs a Software Real Time Clock?  (Read 12130 times)
0 Members and 1 Guest are viewing this topic.
London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ytsirk, are you testing it using the Processing example sketch to set the clock or some other code. I wonder if there is some serial data being received by the arduino that is causing the symptoms you describe.

You could test your Arduino by running a simple sketch like this one to see if it survives beyond 30 minutes or so
Code:
int i = 0;
void setup(){
  Serial.begin(19200);
  pinMode(13,OUTPUT); // we flash the LED each second
}

void  loop(){
   delay(1000);
   Serial.print(i++,DEC);
}

edit: I have been running the playground example sketch for just over an hour without problem on my board.  Please let me know if the sketch in this post runs ok or not on your board.
« Last Edit: August 14, 2008, 11:05:12 am by mem » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That code worked for well over a half an hour without a hitch and I haven't had any trouble with any other code running on it before.   Your question about serial data had me thinking so I tried a modified version of the playground code to try to eliminate that possibility.  
I came up with this:
Code:
#include <DateTime.h>
#include <DateTimeStrings.h>

void setup(){
  Serial.begin(19200);
}

void  loop(){  
 DateTime.sync(1218757280);   // Sync DateTime clock to the time received on the serial port
 while (1){
  if(DateTime.available()) { // update clocks if time has been synced
    unsigned long 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 an app listening on the serial port
    Serial.println(DateTime.now());      
  }
 }
}

void digitalClockDisplay(){
  // digital clock display of current 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 colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits,DEC);  
}

Unfortunately I got the same problem, a freeze, and then a bit later a seemingly random date and time started up again.  If you had it running with no problems then I'm wondering if it might be a hardware issue of some sort.

edit:  I'm starting to wonder if it is indeed a random date and time it restarts at: with this code it always seems to jump to October 3rd when it starts up again... hmm.
« Last Edit: August 14, 2008, 08:26:38 pm by ytsirk » Logged

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

Is the time after restart always exactly the same to the second ?  Not sure what that means but it may help us track things down.

It may be worth adding a print statement in setup to see if it  resets after freezing (although I don't think it has)

Also adding a few lines to the sketch you posted above will tell us if its freezing while waiting for the seconds to change:

    unsigned long prevtime = DateTime.now();
    while( prevtime == DateTime.now() )  // wait for the second to rollover
    {        // the following lines to be added to your test sketch
        Serial.print(millis(),DEC);
        delay(500); // this reduces the number of serial message sent  
    }


if the millis value doesn't change when it freezes, we can look for something that may be blocking interrupts.

FYI, the playground sketch has been running continuously now on my board for 12 hours without problem.
« Last Edit: August 14, 2008, 10:07:42 pm by mem » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 47
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There seems to be three issues being discussed here:

1) the need for a date, hour, minute and second time keeping feature.
2) the synchronization of this feature with the outside world.
3) should this feature be basic to the arduino?

I would suggest time is fundamental to our every day life; hence, flows over into the devices we build with the arduino.

As for synchronization, the network people have studied this problem to dead about 20+ years ago.  NTP or Network Time Protocol resulted and is extremely accurate to milliseconds.  Arduino is testing an ethernet stack, thus, access to NTP will follow.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 47
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Another alternative for time syncronization other than a RTC chip is via a GPS chip which produces NMEA output.

The NMEA 0183 data stream consists of a series of "sentences" delimited by a newline character. Each sentence begins with a six character identifier, the first character of which is always "$". The NMEA 0183 standard defines dozens of sentences, but only a fraction apply directly to GPS devices. The most useful sentences include:

$GPAAM - Waypoint Arrival Alarm
$GPBOD - Bearing, Origin to Destination
$GPBWW - Bearing, Waypoint to Waypoint
$GPGGA - Global Positioning System Fix Data
$GPGLL - Geographic Position, Latitude/Longitude
$GPGSA - GPS DOP and Active Satellites
$GPGST - GPS Pseudorange Noise Statistics
$GPGSV - GPS Satellites in View
$GPHDG - Heading, Deviation & Variation
$GPHDT - Heading, True
$GPRMB - Recommended Minimum Navigation Information
$GPRMC - Recommended Minimum Specific GPS/TRANSIT Data
$GPRTE - Routes
$GPVTG - Track Made Good and Ground Speed
$GPWCV - Waypoint Closure Velocity
$GPWNC - Distance, Waypoint to Waypoint
$GPWPL - Waypoint Location
$GPXTE - Cross-Track Error, Measured
$GPXTR - Cross-Track Error, Dead Reckoning
$GPZDA - UTC Date/Time and Local Time Zone Offset
$GPZFO - UTC and Time from Origin Waypoint
$GPZTG - UTC and Time to Destination Waypoint
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I want to use this library but it doesn't compile as the download is missing files.
Specifically DateTimeStrings.h
Anyone?
Logged

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

Just refreshed the zip with the missing file. try it now
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How long until the download is refreshed? I am still getting the old library. Thanks
Logged

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

Quote
How long until the download is refreshed? I am still getting the old library. Thanks
I tried it right after I uploaded it and got the latest version with DateTimestrings.h.
Try it again, but here is the content for DateTimeStrings.h if you are still having trouble:
Code:
#ifndef DateTimeStrings_h
#define DateTimeStrings_h

#include <inttypes.h>
#include <DateTime.h>

#define dt_MAX_STRING_LEN 9 // length of longest string (excluding terminating null)

class DateTimeStringsClass
{
private:
      char buffer[dt_MAX_STRING_LEN+1];
public:
      DateTimeStringsClass();
      char* monthStr(byte month);
      char* dayStr(byte day);
};

extern DateTimeStringsClass DateTimeStrings;  // make an instance for the user

#endif /* DateTimeString_h */
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I cannot get this to work at all using the example sketch provide, word for word out of the zip or on the code page.

Uploading it and monitoring the serial window just gives me a blank screen?
Logged

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

Hi DeanoAus, how are you setting the time on the Arduino?

The date and time needs to be set when the sketch starts, this can be through a synchronization message from on external time source such as a computer connected via the serial port.

The  zip file update for 0012 that was in the playground did not contain the Processing sketch to set the clock. I have just uploaded  a new zip that has the example sketches. You won't see the time in the display until the clock is set so try it with the processing sketch

Good luck
« Last Edit: October 22, 2008, 08:00:24 am by mem » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

EDIT : Found the file, ta.
« Last Edit: October 23, 2008, 06:34:25 am by DeanoAus » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm still getting the version with the missing  DateTimeStrings.h and readme file when i dl from the link on Arduino Playground.  Is the file located somewhere else?

This looks great, and i'd really like to try it out.

thanks.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In your example in the Playground, is there a way to preset the time in the code before compile time and not do an external synchronization of any kind?
Logged

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

Badodds, I have refreshed the uploaded in the playground

Hotcarrier, you can set the time to a hard coded value using DateTime.sync()

Below is the example  sketch that sets the time to midnight Jan 1 1970. You can use an online unix  time calculator like this one to get any specific time: http://www.onlineconversion.com/unix_time.htm
Code:

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

#define START_TIME 0  // set this to the Unix start time you want (0 is midnight Jan1 1970 UTC)

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

void  loop(){
  unsigned long  prevtime;
  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
    digitalWrite(13,HIGH);
  }
  delay(100);
}

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

and here is a sketch that sends the time to the serial port when a button is pressed
Code:
#include <DateTime.h>
#include <DateTimeStrings.h>

#define START_TIME 0  // set this to the Unix start time you want (0 is midnight Jan1 1970 UTC)
#define BUTTON     2  // pressing button on pin 2 sends the time to the serial port

void setup(){
  Serial.begin(19200);
  DateTime.sync(START_TIME);
}

void  loop(){
  unsigned long  prevtime;
  if(digitalRead(2) == LOW ){
     if(DateTime.available())
        digitalClockDisplay( );   // update digital clock
  }
  delay(100);  
}

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);
}
« Last Edit: November 08, 2008, 04:46:45 am by mem » Logged

Pages: 1 [2] 3 4 ... 7   Go Up
Jump to: