The Self-Learning Clock Is an Ultra-Low-Power ePaper Timepiece That Improves with Age
Powered by an Espressif ESP32-S3, this clock runs from the microcontroller's internal oscillator — calibrating over time to boost accuracy.
Maker Andrea Favero has built an Espressif ESP32-powered desk clock with a difference: it "learns" as it runs, calculating its own internal clock drift and compensating accordingly — an effort, its creator explains, to push the limits of a microcontroller-powered timepiece without the use of an external real-time clock (RTC) component.
"Traditional NTP [Network Time Protocol]-based clocks frequently check in with time servers, which drains power and relies on a continuous network connection. Their accuracy drifts until the next sync," Favero explains. "The Self-Learning Clock (SLC) takes a different approach: it observes its own timing errors and builds a software correction model for its internal oscillator's drift. By applying this adaptive correction, it achieves excellent short-term accuracy and minimal long-term drift (the last gets fully compensated at NTP syncs)."
Traditionally, the first step in building a clock is selecting a time source. An off-the-shelf wall clock will use a quartz crystal mechanism; a microcontroller-based clock will usually require an external real-time clock (RTC) chip, designed specifically for accurate timekeeping. It's possible to build a clock using only the microcontroller's internal oscillator, though — but as this is built to keep the microcontroller ticking through instructions rather than keeping precise time, you'll quickly see the reported time and real time diverge.
The Self-Learning Clock aims to fix that — without an RTC. Like many "smart" clocks, it's based around an Espressif ESP32-S3 microcontroller and picks up its initial time setting over NTP via on-board Wi-Fi connectivity, querying a remote server. Built with a low power draw in mind, though, it does this relatively infrequently — relying, instead of constant updates, on a deterministic self-calibration system. "It's not artificial intelligence," Favero explains of the "learning" in the project's title, "but a straightforward mathematical analysis."
This analysis sees the microcontroller — which comes with an extra 8MB of pseudo-static RAM (PSRAM), Favero having struggled to squeeze the required code into the ESP32's on-chip SRAM — compare its internal timekeeping with the NTP-reported time, adjusting for discovered drift automatically. The longer it runs, the more it "learns" — and the smaller the error between internally-tracked time and actual time.
This, Favero says, allows for less-frequent NTP updates and more time in deep-sleep, with the microcontroller waking for less than a second every minute. Combined with the use of an ePaper display, which requires power only when changing states, that allows for a long run-time on battery power alone.
The project is documented in full, complete with a bill of materials, on Instructables; source code and 3D print files for the clock housing are available on GitHub under the permissive MIT license.