My clock freezes


I watch in my project with a clock that the ad occasionally - I mean every few days - freezes and either does nothing more or displays the ad over a few hours correctly again.
The symptom shows, even if I do not change values via Blynk.

Is someone ready to look at the code?
https://go.particle.io/shared_apps/5a6354f61be13a8698000122

Thx!

What have you tried already?

1 Like

I would look at the random element you use to decide when to sync to cloud time. Can you set that to a known time and see if the bug happens at that time?

I would also comment out the Blynk stuff and try that version to separate the problem into parts.

3 Likes

I will test it and watch it - thanks!

// Pick a random time to synchronize the time from the cloud
// time_sync_time = random(0, 2399);

// https://docs.particle.io/reference/firmware/photon/#particle-synctimedone-
Particle.syncTime(); 
waitFor(Particle.syncTimeDone, 5000); // works with v0.6.1 with Photon & Electron

Your random number generator will generate a lot of “times” that are not valid (the 99 part), and thus Particle.syncTime() will never run. Sync’ing at midnight, or every millis() of 86400 would be fine as well. But also your the_time = Time.hour()*100+Time.minute(); is not an atomic operation, so it could generate an invalid time due to rollover. You can fix many ways, but a simple one is to read the minute first, hour second, minute again, if minute is the same… continue, if not, read the hour again and continue. Look in your libraries for while loops that can get stuck and add timeouts. Good luck!

3 Likes

I invited Garrett - hope he can help me :sunglasses:

Garrett I see the following points:
a.) I would like to have a leading 0 at midnight “0:04” instead of "_: _4"
b.) the freezing of the photon disturbs me and the time is connected - so it is not a reliable companion in everyday life.
c.) otherwise it would still be great to have a Blync integration: I tried to adjust the time zone, the brightness of the display and the blinking colon

Although the original code does not use Blync, my photon hangs after 2-3 days and freezes the time. Sometimes it syncs after 3-4 hours and runs for some time, sometimes a restart is necessary.

If you are building a string then you can use the format string "%02d:%02d"

What's the current state of your code - Photons don't usually freeze without your code causing it :wink:

1 Like

Yes, the problem is in front of the keyboard :wink:

Garretts Original Code: https://go.particle.io/shared_apps/5ae21b259e4fda7dcb0006fa
and my version with a little bit changes (Blync-Integration): https://go.particle.io/shared_apps/5aa2d142a9641220c300155e

Both versions are basically the same and cause difficulties. I could not completely follow the suggestions so far and have therefore flashed the original version.

In order to have a leading zero you just change this

    // Display the time in 24 hour format
    if(TWENTYFOUR_HOUR==1) {
        matrix.print(the_time);

        if (Time.hour() < 10)          // leading zero?
          matrix.writeDigitalNum(0, 0);
        
        if (Time.hour() == 0) 
           matrix.writeDigitNum(1, 0); // = first value = number of digit - in this case = second digit, starts with 0 to 4; second value = value to display
       
        if (Time.minute() <= 9)
           matrix.writeDigitNum(3, 0); // = first value = number of digit - in this case = third digit, starts with 0 to 4; second value = value to display
 
        colonDisplay(colon_display, false);

    // We have to do some mangling to do 12-hour time
    } else {
        // Calculate 12-hour time
        uint16_t new_time = the_time;
        if(new_time>=1200)
            new_time = new_time-1200;

        matrix.print(new_time);

        if (new_time < 1000)          // leading zero?
          matrix.writeDigitalNum(0, 0);

        // Show PM dot
        if(the_time>=1200)
            colonDisplay(colon_display, true);
        else
            colonDisplay(colon_display, false);
    }

However, I think the 12-hour display isn’t quite right for the times 12:00 to 12:59 am/pm as they would be printed as 00:00 to 00:59 am/pm which isn’t the common way of displaying these times.

2 Likes

Got an error ScruffR during flashing:
mybigclock_original.ino:69:18: error: ‘class Adafruit_7segment’ has no member named 'writeDigitalNum’
mybigclock_original.ino:89:18: error: ‘class Adafruit_7segment’ has no member named ‘writeDigitalNum’

Adafruit_7segment matrix = Adafruit_7segment(); is defined at start.

The option with 24 hour format is my favorite version.

Sorry, this was a typo, but minimal investigation of that message may have revealed the error.

Your original code was already using the function I intendet to use but just wrote slightly different.

        if (Time.hour() < 10)          // leading zero?
          matrix.writeDigitalNum(0, 0); // <-- error here
        
        if (Time.hour() == 0) 
           matrix.writeDigitNum(1, 0); // <-- working here

(spot the difference)

1 Like

The “al” found :wink: and flashed on v080rc8. I’ll wait until midnight and hope that this will also get the hangers under control. Already my thanks!

Works:

Update: 28.08.2018
the freezing of the display has been attributed to a jittering contact of the jumper cables to the photon. It struck me as odd that despite the freezing, the photon was quite responsive. So I wobbled on the DIY box and lo and behold, the display came back and updated. This could be reproduced several times and so I’ll probably solder the jumpers on the Photon.