Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

95 Commits

Folders and files

Repository files navigation

galactic-clock

A weather and air-quality clock for the Pico W and its 53x11 LED matrix, written in MicroPython for the board. The rendering is pure, deterministic functions, so a host simulator can drive the exact same code the board runs — reproducing the matrix pixel-for-pixel. The GIF below is bit-identical to the hardware.

Display loop demo

Rendered by the host sim from the real main.py — regenerate with python3 sim/run_main.py --seconds 24 --delay 0.12 --preseed-co2 53 --gif docs/demo-rotation.gif (--preseed-co2 fills the CO2 history so the GIF's strip isn't empty; micropython-check verifies the tracked GIF against this exact command; needs Pillow).

The dashboard: local time always on the left, one widget at a time on the right, rotating every 8 s with a vertical roll:

  • clock — 5x7 digits in fixed slots, so the colon holds one column, blinking two-dot colon; RTC synced via NTP (EU DST computed in pure integer math in src/tz.py — MicroPython has no tzdata); shown only when the RTC is trustworthy (NTP-synced, or already reading >= 2026 after a soft reset) — otherwise the slot shows no ntp
  • weather widget — animated 10x11 icon + current temperature from open-meteo (no API key); icons are hand-drawn pixel art per WMO code with day/night variants (twinkling sun/moon, drifting fog bands, falling rain/snow, flashing storm bolt)
  • hi/lo widget — today's high/low with up/down arrows
  • CO2 widget — ppm from an optional SCD41 sensor on the STEMMA QT connector, color-coded green/amber/red by indoor air quality; readings stay untrusted for ~3 min after boot (the sensor's startup settling)

Buttons: A toggles the matrix rain mode — anti-aliased drops with fading trails; column-by-column speed/brightness tiers and occasional rests make the density and tempo visibly breathe, and the rendering is deterministic, so sim and board match frame for frame. One press plays it full-screen for two minutes (a second press stops it early), then the dashboard resumes. With a trusted RTC the clock shows through the rain; without one, the rain runs alone.

Matrix rain demo

The rain-clock episode, rendered by python3 sim/sim.py play --screen rainclock --delay 0.12 --gif docs/demo-matrix.gif (the episode length rides the render constants, so --frames doesn't apply); sim/check_demo_gif.py (CI) enforces that both GIFs match the code.

Hardware & host setup

  • Pimoroni Galactic Unicorn (Pico W); optional SCD41 CO2 sensor (STEMMA QT, SDA=4/SCL=5)
  • Windows 11 host + WSL2 (Ubuntu-24.04) — GitHub: abalawender/galactic-clock
  • Board shared with the WSL side over USB via usbipd: usbipd.exe; mpremote (apt install micropython-mpremote)
  • Pillow — only needed for --gif output in the sim (everything else is stdlib)
  • Firmware: MicroPython v1.29.0 board build pico_w_galactic-v1.29.0-micropython.uf2 from https://github.com/pimoroni/unicorn/releases/tag/v1.29.0 (local copy in firmware/, gitignored — flashing notes in docs/flashing.md)

Connect

# find the board's bus id (env-specific; changes with the port):
usbipd list                           # e.g. 2-4  Pico W (pico_w_galactic)
# once, as admin on Windows (bus id from the list):
usbipd bind --busid <busid>
# from WSL:
usbipd.exe attach --wsl --busid <busid>   # -> /dev/ttyACM0
mpremote exec "import os; print(os.uname().version)"

Board configuration (secrets.py)

The board reads /secrets.py at boot. It is gitignored and lives only on the board flash — never commit it, never print it, never copy it back off the board. To create it, copy the committed template secrets.example.py — each variable is documented inline there (WiFi, location, TZ, optional SCD41_ALTITUDE_M) — and fill in real values:

cp secrets.example.py secrets.py     # fill in real values
mpremote cp secrets.py :secrets.py   # host -> board only
rm secrets.py                        # board holds the only copy

Board API

from galactic import GalacticUnicorn
from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN
gu = GalacticUnicorn()                       # 53x11
d = PicoGraphics(display=DISPLAY_GALACTIC_UNICORN)
d.set_pen(d.create_pen(255, 60, 0))
d.pixel(26, 5)
gu.update(d)

Simulate on the host

See exactly what the 53x11 matrix will show — without touching the board. sim/sim.py runs the same src/render.py as the board, with a faithful re-implementation of the PicoGraphics bitmap6 font (sim/font6_data.py), so layouts match the device pixel-for-pixel. The sim never reads secrets.py; weather values are CLI args (--code/--temp/--hi/--lo/--night).

python3 sim/sim.py print  --screen weather --code 61 --temp 21 --frames 8
                              # plain ASCII frames on stdout
python3 sim/sim.py play   --screen weather --code 61 --temp 21   # animate in terminal
python3 sim/sim.py play   --screen weather --code 0 --night      # moon + stars
python3 sim/sim.py play   --screen icons --frames 8              # contact sheet: all icons
python3 sim/sim.py play   --screen hilo --hi 25 --lo 18
python3 sim/sim.py play   --screen matrix --frames 60         # code rain

See it in motion — render any screen, or the whole dashboard loop of the real main.py (fully mocked: WiFi/NTP/open-meteo/SCD41), to an animated GIF (needs Pillow; GIFs are gitignored):

python3 sim/run_main.py --seconds 24 --gif /tmp/rotation.gif   # dashboard, widgets rolling
python3 sim/sim.py play --screen matrix --frames 60 --gif /tmp/matrix.gif
python3 sim/sim.py play --screen icons --frames 8 --gif /tmp/icons.gif
python3 sim/sim.py play --screen weather --code 61 --temp 21 --frames 12 --gif /tmp/rain.gif

For PR reviews, before/after GIFs of every changed screen (base ref vs PR head) are rendered automatically:

python3 sim/before_after.py --ref origin/micropython --out /tmp/pr
                              # writes /tmp/pr_<screen>_{before,after,compare}.gif
                              # screens pixel-identical to the base produce no GIFs

Development

  • Tests (host-only, no board): python3 -m unittest discover -s tests -v — rendered-bitmap property checks, golden ASCII dumps, EU DST rules, and a fully mocked run of the real main.py
  • Preview every display change in sim/ before deploying (above)
  • Deploy: scripts/deploy.sh — attaches the board first if /dev/ttyACM0 is missing (see Connect above), uploads the modules on its manifest (main.py + the src/ services), then resets the board
  • PRs to micropython that touch main.py/src//sim//tests/ run the tests and post before/after GIFs inline on the PR — see .github/workflows/pr-sim.yml
  • micropython-check (.github/workflows/micropython-check.yml) runs on PRs to micropython and on pushes to it: tests + a check that the tracked demo GIF above matches the code (sim/check_demo_gif.py). It is a required status check under the micropython ruleset (rebase-only merges, one approving review, resolved threads). If you change rendering, regenerate docs/demo-rotation.gif in the same PR (command above the GIF)

Layout

  • AGENTS.md — ramp-up essentials: golden rules, workflow, layout
  • main.py — board entry point: WiFi/NTP/open-meteo/SCD41 + dashboard loop (thin)
  • src/render.py — core drawing (clock, CO2, hi/lo, boot); pure functions, no board imports
  • src/weather.py — animated weather icon art; src/matrix.py — matrix rain and the rain-clock overlay; src/scenes.py — dashboard composition and widgets
  • src/co2.py — SCD41 sampling with warmup gating and the history ring buffer
  • src/ntp.py — periodic RTC re-sync while the clock runs
  • src/tz.py — EU DST offset in pure integer math (MicroPython has no tzdata)
  • sim/ — host simulator: sim.py (play/print/GIF), font6_data.py (real bitmap6 font metrics), run_main.py (mocked full run of main.py), before_after.py (PR review GIFs), gif.py (Pillow writer)
  • tests/ — unittest suite (bitmaps, golden ASCII, tz rules, mocked main loop)
  • scripts/ — attach.sh, deploy.sh (uploads the board sources, resets board)
  • skills/ — agent skills: board access via mpremote (attach/recovery, REPL rules, flash files) in mpremote; the Galactic Unicorn board itself (LED matrix display snippets, frozen galactic synth API) in unicorn
  • docs/ — flashing notes, hardware resource inventory (hardware.md) + the tracked README demo GIF; firmware/ — local uf2 copy (gitignored)

License & contributing

MIT — see LICENSE. Contributions (mostly AI agents) follow AGENTS.md: branch off micropython with small atomic commits, and CI will run the tests and post before/after GIF previews inline on the PR.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Used by

Contributors

Languages