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:
#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.