Vetinari clock: Progress
I’ve had this idea now for ages - there was a kit that someone used to sell, long out of stock, that let you turn any normal clock into a Vetinari clock… a thing from the Discworld series where it audibly ticks erratically but still manages to keep accurate time. What I wanted to do, since discovering Espressif’s ESP8266 chipsets, is build one that speaks Wifi, syncs with NTP, and adjusts itself for daylight savings time while also being maximally irritating.
My personal project sat on hold for some time as my attention wandered… I bought a cheap clock (A$4 or so, if I recall), but turns out I’d bought one without a second-hand. I later bought another, less-cheap one (A$8). I then got stuck on how to appropriately drive it, because I know just enough electronics to doubt myself, and not enough to confidently build anything.
Fast forward to this weekend, when some lovely folks on Mastodon were talking about another project that implements an ESP8266-powered NTP clock in Arduino. That’s not exactly what I want, but crucially they’d done the hard work of solving the circuit problem. Indeed I had most of what I’d need already, I just needed four 1N4001 rectifiers and I’d be away. A quick trip up to our local Jaycar-adjacent store, and they don’t have them… they do have 1N4004 however, which from both of our poring over the spec sheets suggests they’re functionally equivalent they’re just rated to higher voltages, but for A$0.98 for four of them, I was willing to take a punt anyway.
I pushed everything into a breadboard, cracked open the clock, cut the traces and soldered some jumper wires to the coil, and put everything back together. Testing it quickly using 3.3V supply, I got 1-ish volts on the coil (a feature of the specific diodes seems to be the voltage drop across them), I just need to figure out how to flash the ESP8266 and I could start hacking shit together.
Alas, Espressif appear to have all but abandoned the older one… it’s unsupported by the ESP-IDF project, the old one needs things like Python which are outdated, and I’m running on Arch linux so I don’t have a real good way to do anything older. I tried grabbing what purported to be Docker containers of the build environments to no luck. I even tried spinning up the Arduino GUI and building the above-mentioned project, but couldn’t satisfy all the dependencies.
In the end, someone on Discord mentioned using tinygo, which worked after downgrading go and installing my own esptool, but unfortunately that does not support the wifi module so it’s no good permanently.
But I can use this completely dogshit random-ticker to prove the concept:
package main
import (
"machine"
"time"
"math/rand"
)
func main() {
r := rand.New(rand.NewSource(99))
coil1 := machine.D4
coil1.Configure(machine.PinConfig{Mode: machine.PinOutput})
coil2 := machine.D3
coil2.Configure(machine.PinConfig{Mode: machine.PinOutput})
coil1.Low()
coil2.Low()
tick_odd := 0
for {
if tick_odd == 0 {
coil1.High()
time.Sleep(time.Millisecond * 30)
coil1.Low()
tick_odd = 1
} else {
coil2.High()
time.Sleep(time.Millisecond * 30)
coil2.Low()
tick_odd = 0
}
time.Sleep(time.Millisecond * time.Duration(r.Intn(1940) + 30))
}
}
Flashing it with tinygo flash -target=nodemcu -port=/dev/ttyUSB0 and I can observe that the LED is doing the thing (for some reason the LED logic is inverted though, I had originally inverted the low/high in the code but I think this is wrong… while it does not keep the coil energized I think it needlessly sends voltages across the diodes for no good reason?), and the voltages to the coil look sensible, so… I’ll either fix it or fuck it, hook it up.
And it’s working!
Now I just need to sort out some way to write software for the ESP8266 that can use the wifi (ideally using FreeRTOS, which I enjoyed), or I may have to ditch it and use a more modern ESP32 instead.
I don’t think I’ll bother with the flash memory portion of the ESP8266 project… our power is pretty good here and I will build a “clock adjustment” feature into it. So my planned features are:
- Connect to NTP and sync time.
- (Toggleable) tick randomly but over the course of say, 2 minutes, always arrive at 120 ticks, so as not to lose time.
- During Daylight Savings adjustment, either stop ticking for one hour at 3am during Autumn changeover, or double-tick one hour over the course of three hours from 2am to 4am to advance the clock by one hour.
- In the event the clock is ever wrong, have the ability to tell it the time the clock is currently showing - this will allow it to figure out how much the clock needs to advance/retard to become accurate again.
This all sounds fairly doable by just standing on the shoulders of others.
Update: 2026-02-28: I switched things around, used the ESP32 board I had laying around, configured tinygo for it, and flashed it. I soldered things up to a protoboard and it’s all permanently in place, all it needs now is software.
But just leaving it run with the tinygo program on my bench, it’s delightfully infuriating. Incredibly annoying. It’s going to be amazing.
