
GNSS Alarm Clock
KrHaaland/GNSS_Alarm_Clock
GNSS-synchronized alarm clock — custom SAMD51J20A board with nPM1300 Li-ion power (USB-C), offline timezone+DST from coordinates, LVGL 9 on a 428x142 TFT, WAV alarm tunes over USB, battery-backed RTC

GNSS-synchronized alarm clock — custom SAMD51J20A board with nPM1300 Li-ion power (USB-C), offline timezone+DST from coordinates, LVGL 9 on a 428x142 TFT, WAV alarm tunes over USB, battery-backed RTC
Samd51 gps alarm clock is an open-source printed circuit board by KrHaaland, from the KrHaaland/GNSS_Alarm_Clock repository on GitHub. It is a 2-layer board of 80 × 50 mm with 162 parts on 145 nets, routed with 1,089 tracks and 152 vias.
It is built around the ATSAMD51J19A-AUT-EFP, L86-M33 and IRLML6344TRPBF, with the 24LC512-I/P, LIS3DH and RV-3028-C7 among its other parts. Its parts include 62 resistors, 35 diodes, 26 capacitors, 14 ICs and 5 connectors. It belongs with the lEDs and displays and radio and wireless boards and the SAM D and SAM boards of this library.
Firmware for the custom SAMD51 alarm-clock board (Adafruit Metro M4
compatible), designed in HARDWARE/ (KiCad). Two board revisions share one
firmware:
HARDWARE_V2.md and ADR-0014/0015.
Default build: metro_m4_j20.HARDWARE_OLD/). Build: adafruit_metro_m4. The firmware detects the
PMIC at runtime and degrades gracefully either way.Time is set automatically from GNSS, the timezone (with DST) is derived offline from the GNSS coordinates and saved to flash so it stays correct indoors, and alarms drive an LED light-show + a tune through a class-D amp. The UI is LVGL on a 428×142 color TFT driven by four buttons.

Current state: firmware is feature-complete and running on hardware — display, GNSS time/timezone, alarms, audio, tunes-over-USB, settings, modes (speedometer/altimeter/USB-gamepad) and the RV-3028 RTC (hand-fitted; it was missing from the prototype) all work. See
STATUS.mdandHARDWARE_REVIEW.md.
millis()-anchored UTC counter
disciplined by GNSS (re-syncs hourly / on ≥2 s drift) and backed by the
RV-3028-C7 RTC (I²C 0x52), whose VBACKUP sits on the battery (v2; the
v1 prototype used the supercap rail) so it holds time through power loss. On boot the clock starts from the RTC
immediately and refines from GNSS when a fix is available. A cold-start guard
rejects the L86's free-running "year-2080" date so garbage can't be written
into the backup RTC.tools/gen_tz_polys.py (tunable resolution/flash budget; enclaves ordered
first), refinable by hand in tools/tz_polygon_editor.html (map GUI:
draw/edit vertices, probe a point, export the header). Two resolutions,
picked by flash size: v2/J20 gets the fine map
(src/TimezonePolyDataFine.h, ~1–2 km borders, 404 zones / 56k vertices,
~250 KB), v1/J19 the coarse one (src/TimezonePolyData.h, ~57 KB). Anything not inside a polygon or box falls back
to a whole-hour longitude estimate, so every coordinate resolves. Maps
the GNSS position to a
POSIX TZ string with DST rules (e.g. Oslo →
CET-1CEST,M3.5.0,M10.5.0/3). The result is persisted to internal flash,
so local time (including DST changes) stays correct after reboot even with no
fix indoors. A DST-aware POSIX evaluator (Timezone.*, host-unit-tested)
computes the offset. Manual zone override is available in the menu.[Back/Menu] [Prev/–] [Next/+] [OK]. Screens:
clock, menu, alarm-edit, time & zone, display, tunes, system-info,
sky view (GSV polar plot + SNR bars — indoor antenna-placement aid),
ringing. A true-black theme keeps the panel dark. Optional starry night:
twinkling stars behind the clock digits between 22:00 and 06:00.TUNES) —
drag & drop .wav files (PCM, 8/16-bit, mono/stereo, 8–48 kHz).Grabbed from the live firmware over USB serial (tools/screenshot.py).
![]() | ![]() |
| Clock face — battery gauge, charge bolt, alarm bell | Starry night (22:00–06:00) |
![]() | ![]() |
| First boot, no RTC/GNSS time yet | Sky view — GSV polar plot + SNR bars |
![]() | ![]() |
| Main menu | …scrolled |
![]() | ![]() |
| Speedometer mode (GNSS) | Altimeter mode (GNSS) |
![]() | ![]() |
| Game mode — USB HID gamepad | The 3D-printed enclosure |
The panel is an NV3007 color TFT (Newvision), native 142×428 bar type,
driven landscape 428×142. Driver: src/DisplayNV3007.cpp.
(The v1 prototype's ST7789 284×76 driver is kept in-tree — pick the panel via
DISPLAY SELECT in platformio.ini.)
0xFF 0xA5 unlocks the extended register page
(power/gamma/gate-driver/source-timing dump); without it the address engine
wraps writes linearly across the glass. 0xFF 0x00 returns to the DCS page.
Sequence cross-verified against five independent drivers (Arduino_GFX, LVGL
lv_nv3007, vendor reference, STM32 + esp_lcd ports).MADCTL 0xA0, flipped 180° to match the enclosure mounting) puts the
inset on RASET: NV_Y_OFFSET 12 (unflipped 0x60 → 14). Inversion OFF.DISPLAY_SELFTEST bring-up
pattern test (colors/border/origin) as before.src/font_clock_100.c, 18 chars) — replacing the full 48 px font actually
shrank flash by 67 KB (ADR-0011).The board has two candidate "EEPROMs" for tunes: the 24LC512 (64 KB, I²C) and a QSPI serial flash. The firmware uses the QSPI flash (exposed as the USB drive): far larger, faster, on the standard Metro M4 QSPI pins, and it enables the drag-and-drop workflow.
Settings are packed into the RV-3028 RTC's 43-byte user EEPROM. Chosen because it survives firmware reflashes (the old internal-flash emulation sat inside the app image and was wiped on every update), takes ~100k writes/byte, and frees the 24LC512 to be dropped from the hardware-v2 BOM (it still ACKs at 0x50 on v1 boards, unused). Verified on hardware: settings survive both power cycles and reflashes.
Space is won by not storing derived data: TZ strings re-derive at boot from the stored position (or the manual GMT-ladder index), and alarm tune filenames are stored as 16-bit FNV-1a hashes re-matched against the TUNES directory (missing file → builtin melody). Multi-byte fields are little-endian.
| Addr | Size | Field |
|---|---|---|
0x00 | 2 | Magic 'G' 'C' |
0x02 | 1 | Pack-format version (4) — older blocks (v1–v3) migrate in place at boot, nothing is reset |
0x03 | 1 | Flags: b0 tzAuto, b1 tapSnooze, b2 use24h, b3 havePosition, b4–5 mode, b6 starryNight |
0x04 | 2 | Latitude, centidegrees (i16) |
0x06 | 2 | Longitude, centidegrees (i16) |
0x08 | 1 | Manual zone index into TZ_TABLE (0xFF = none/auto) |
0x09 | 1 | Volume (0–10) |
0x0A | 1 | Snooze minutes |
0x0B | 1 | Buzzer escalation after N min (0 = off) |
0x0C | 1 | Brightness |
0x0D | 2 | Dim timeout, seconds (u16) |
0x0F | 1 | Dim brightness |
0x10 | 3 | Snooze counter, all time (u24, caps at 16.7 M) |
0x13 | 2 | Snooze counter, this week (u16) |
0x15 | 2 | Week start, local epoch-day − 18262 (u16, base 2020-01-01) |
0x17 | 7 | Alarm 1: flags (b0 enabled, b1–2 ramp Off/15/30/60 s, b3–4 random ±0/1/5/9 min, b5 lights-OFF — inverted so old blocks read as on), hour, minute, daysMask, melodyId, tuneHash (u16) |
0x1E | 7 | Alarm 2: same layout |
0x25 | 1 | Checksum (block sums to 0xFF) — written last, so a torn write invalidates the image |
0x26 | 5 | Free / future |
RV-3028 EEPROM quirks (bench-found, handled in
RtcRV3028.cpp): the chip NACKs all I²C while its EEPROM engine runs — both during the power-on auto-refresh (>100 ms) and in short windows after each programmed byte. The driver therefore treats failed STATUS reads as "still busy" (300 ms deadline), retries each byte transaction up to 5×, and read-back verifies every written byte.
Flash BOM note: the schematic specifies a 4 MB Macronix MX25L3233F, but assembled boards carry a 16 MB Winbond W25Q128 (JEDEC 0xEF4018). The driver auto-detects the real chip via the library's default device list, so the true size is used for the USB drive.
| Function | MCU pin | Arduino pin |
|---|---|---|
| Display CS / DC / RST / BL | PA18 / PA17 / PA16 / PA19 | D10 / D12 / D13 / D11 |
| Display SPI (SERCOM2) | PA12 MOSI, PA13 SCK | MOSI/SCK |
| GNSS L86 UART (SERCOM3) | PA22 TX → L86, PA23 RX ← L86 | Serial1 |
| GNSS FORCE_ON / RESET_N | PB00 / PB31 | direct port |
| I²C @100 kHz: RTC 0x52, amp 0x58, accel 0x18, EEPROM 0x50 | PB02 SDA, PB03 SCL | SDA/SCL |
| Buttons SW1..SW4 (L→R, active low) | PB14, PB13, PB12, PB15 | D5, D4, D7, D6 |
| LED gates: left / bottom / right | PA21 / PA20 / PA06 | D8 / D9 / A2 |
| Audio DAC → TPA2016 | PA02 (DAC0) | A0 |
| Amp ~SD (HIGH = on) | PB17 | D2 |
| Power buzzer gate (J5) | PB16 | D3 |
| Supercap CAPGOOD (LTC3226) | PA04 | A3 |
| LIS3DH INT1 (polled, unused) | PB08 | A4 |
| 24LC512 WP | PB01 | direct port |
| QSPI flash | PA08–11, PB10, PB11 | QSPI |
pio run # build (default env: adafruit_metro_m4)
pio test -e native # host-side unit tests (timezone/DST engine)The prototype has a SAMD51J19A (512 KB flash, ~95% full); the next revision
uses a SAMD51J20A (1 MB flash, ~48% — same pinout). Pick the build in
platformio.ini (default_envs) or per-invocation:
| env | MCU | notes |
|---|---|---|
adafruit_metro_m4 | J19A 512 KB | default (current prototype) |
metro_m4_j20 | J20A 1 MB | boards/samd51j20a_metro.json + ld/samd51j20a_*.ld |
sim / sim_j20 | either | + serial GNSS simulator (-DGNSS_SIM) |
pio run -e metro_m4_j20 # J20 build; flash .pio/build/metro_m4_j20/firmware.bin @0x4000J20 + stock bootloader: the Metro M4 UF2 bootloader is built for the J19A and reads the "stay in bootloader" magic at its RAM top (0x2002FFFC); a J20 app writes it at 0x2003FFFC, so the 1200-baud touch used to land straight back in the app.
tools/patch_tinyusb_power.pypatches the core'sinitiateReset()to write both addresses — USB uploads now work on the J20 with the stock bootloader.
Two flashing paths:
A) USB (normal, no tools): pio run -e metro_m4_j20 -t upload —
1200-baud touch into the bootloader, bossac writes + verifies at 0x4000
(~4 s). Manual alternative: double-tap RESET to mount the METROM4BOOT
drive and drag firmware.uf2 onto it.
B) SWD via Atmel-ICE (used in development):
# build first, then flash the .bin at 0x4000 (offset preserves the bootloader)
openocd -c "adapter driver cmsis-dap" -c "transport select swd" \
-c "adapter speed 2000" -f target/atsame5x.cfg \
-c "init" -c "reset halt" \
-c "flash write_image erase .pio/build/adafruit_metro_m4/firmware.bin 0x00004000 bin" \
-c "reset run" -c "shutdown"⚠️ Never flash the
.elfover SWD. Its LOAD segment sits at address0x0and will overwrite the UF2 bootloader at flash start, bricking drag-and-drop programming (recovery = re-flash the bootloader). Always flash the.binat0x4000. The bootloader region is additionally guarded by the BOOTPROT fuse (16 KB) since a brownout-induced wild NVMCTRL write once zeroed the bootloader's vector table (seedocs/sessions/); clear it withatsame5 bootloader 0before intentional bootloader updates, restore withatsame5 bootloader 16384.
pio device monitor -b 115200 opens the USB-CDC console. Sending ~ on
the console streams the next rendered frame as a screenshot —
python3 tools/screenshot.py grabs it and writes a PNG (used for the
documentation images; works on the live device, any screen).
The app enumerates as 1209:0001 — "K. Haaland / GNSS Alarm Clock".
VID 0x1209 belongs to pid.codes (free USB IDs for
open-source hardware); 0x0001 is their official test PID, fine for
personal use — register a permanent PID via a pid.codes PR (requires a public,
OSI-licensed repo) before distributing hardware. Identity lives in
boards/samd51j19a_kh.json / boards/samd51j20a_metro.json. Bootloader mode
(double-tap reset) still enumerates as Adafruit 239A until a custom
uf2-samdx1 is built.
env:sim)To test the timezone/clock pipeline on-device without a real fix, build the
sim env — identical firmware plus -DGNSS_SIM (the L86 init is skipped and a
serial console feeds position/time):
pio run -e sim -t upload # or SWD-flash .pio/build/sim/firmware.bin @0x4000
pio device monitor -b 115200Then type commands into the monitor:
pos 59.91 10.75 set a fix; resolves + applies the timezone
tz -33.87 151.2 query a zone (Jan/Jul offset + DST), no state change
utc 2026 7 13 12 0 0 set the UTC clock so local time shows on the display
status print fix / UTC / local time / zone
nofix drop the simulated fixpos also updates the on-screen clock's zone immediately, so you can watch the
display follow you around the globe. The sim code compiles to nothing in the
normal build — zero production-flash cost.
| File | Responsibility |
|---|---|
src/main.cpp | Boot order, super-loop, alarm ↔ UI ↔ button routing, I²C @100 kHz |
src/ClockKeeper.* | UTC anchor, GNSS→RTC discipline, local time / DST |
src/Timezone.* | Coord→zone polygons+boxes + POSIX TZ/DST evaluator (host-testable) |
src/TimezonePolyData.h | Polygon zone data: tools/gen_tz_polys.py (world set) / tools/tz_polygon_editor.html (hand edits) |
src/Gnss.* | L86 NMEA via TinyGPS++, PMTK config, position/speed/altitude |
src/RtcRV3028.* | RV-3028-C7 driver wrapper (backup switchover, UTC, PORF) |
src/AlarmManager.* | Trigger scan, ringing/snooze/escalation state machine |
src/AudioEngine.* | TC2 ISR → DAC0 playback, WAV streaming, melodies, buzzer |
src/TuneStorage.* | QSPI flash, FAT12 volume, USB mass storage |
src/DisplayST7789.* | ST7789 driver + LVGL 9 flush (RGB565), bring-up self-test |
src/Ui.* | LVGL screens: clock, menu, alarm edit, zone, display, tunes, info, sky view, battery, lights, ringing |
src/PmicNPM1300.* | nPM1300: CC-based input limit, charger, IBAT/SoC, ship mode, IRQ (v2) |
src/Buttons.* / src/Leds.* | Debounced input, LED section patterns |
src/AmpTPA2016.* / src/AccelLIS3DH.* | Amp gain/enable, double-tap-to-snooze |
src/Settings.* | Persistent settings packed into the RTC's user EEPROM (v4, 38 B) |
src/SimConsole.* | Serial "virtual GPS" console — env:sim only (-DGNSS_SIM) |
DISPLAY_SELFTEST in DisplayST7789.cpp — on-glass
pattern test (RGB fills, edge border) instead of LVGL.I2C_SCAN in main.cpp — loops scanning the I²C bus and
prints ACKing addresses over USB serial (used to diagnose the RTC).See STATUS.md for the full list. Highlights:
CAPGOOD polarity assumed HIGH = charged (LTC3226 open-drain + pullup).HARDWARE_REVIEW.md
(LM3671 VIN/SW, L86 V_BCKP cold-start, D3 diode, C30, crystal caps, …).| Qty | Value | Footprint | References |
|---|---|---|---|
| 34 | 80Ω | Resistor_SMD:R_0805_2012Metric | R20, R21, R22, R23, R24, R25, R26, R27, R28, R29, R30, R31, R32, R33, R34, R35 +18 |
| 34 | OR-PL020W | Kicad8_multilib:OR-PL020W | LED1, LED2, LED10, LED11, LED12, LED13, LED14, LED15, LED16, LED17, LED18, LED19, LED20, LED21, LED22, LED23 +18 |
| 12 | 10uF | Capacitor_SMD:C_0805_2012Metric | C6, C7, C8, C9, C10, C11, C16, C17, C19, C20, C21, C28 |
| 8 | 10kΩ | Resistor_SMD:R_0805_2012Metric | R18, R55, R57, R58, R60, R63, R65, R68 |
| 5 | , , , , | ||
| 5 | 1M | Resistor_SMD:R_0805_2012Metric | R1, R8, R9, R10, R11 |
| 5 | TS-1187A-B-A-B | Kicad8_multilib:TS-1187A-B-A-B | RESET, SW1, SW2, SW3, SW4 |
| 4 | 470Ω | Resistor_SMD:R_0805_2012Metric | R15, R54, R56, R59 |
| 4 | C_Polarized | Capacitor_THT:CP_Radial_D6.3mm_P2.50mm | C12, C13, C14, C15 |
| 4 | IRLML6344TRPBF | Kicad8_multilib:IRLML6344 | U10, U11, U12, U13 |
| 3 | 1uF | Capacitor_SMD:C_0805_2012Metric | C2, C26, C30 |
| 2 | 10pF | Capacitor_SMD:C_0805_2012Metric | C24, C25 |
| 2 | 4.7K | Resistor_SMD:R_0805_2012Metric | R6, R7 |
| 2 | 5100Ω | Resistor_SMD:R_0805_2012Metric | R2, R3 |
| 2 | B2B-PH-K-S | Kicad8_multilib:B2B-PH-K-S | J5, J6 |
| 1 | 0Ω | Resistor_SMD:R_1206_3216Metric_Pad1.30x1.75mm_HandSolder | R64 |
| 1 | 100KΩ | Resistor_SMD:R_0805_2012Metric | R67 |
| 1 | 100k | Resistor_SMD:R_0805_2012Metric | R13 |
| 1 | 100nF | Capacitor_SMD:C_0805_2012Metric | C27 |
| 1 | 10uH | Inductor_SMD:L_1008_2520Metric | L4 |
| 1 | 10μF | Capacitor_SMD:C_0805_2012Metric | C29 |
| 1 | 1MΩ | Resistor_SMD:R_0805_2012Metric | R61 |
| 1 | 1kΩ | Resistor_SMD:R_0805_2012Metric | R66 |
| 1 | 2.2uF | Capacitor_SMD:C_0805_2012Metric | C22 |
| 1 | 2.2uH | Kicad8_multilib:VLCF4020T-2R2N1R7 | L1 |
| 1 | 220uF | Capacitor_SMD:CP_Elec_6.3x5.7 | C18 |
| 1 | 24LC512 | Kicad8_multilib:SOIC-8_3.9x4.9mm_P1.27mm | U6 |
| 1 | 300kΩ | Resistor_SMD:R_0805_2012Metric | R62 |
| 1 | 32.768 | Kicad8_multilib:Q13FC13500005 | X1 |
| 1 | 33kΩ | Resistor_SMD:R_0805_2012Metric | R14 |
| 1 | 4.7uF | Capacitor_SMD:C_0805_2012Metric | C23 |
| 1 | ATSAMD51J19A-AUT | Kicad8_multilib:ATSAMD51J19_TQFP | U18 |
| 1 | B7B-XH-A | Kicad8_multilib:B7B-XH-A | J3 |
| 1 | Conn_ARM_JTAG_SWD_10 | Connector_PinHeader_1.27mm:PinHeader_2x05_P1.27mm_Vertical | J2 |
| 1 | L86-M33 | Kicad8_multilib:L86-M33 | U4 |
| 1 | LIS3DH | Package_LGA:LGA-16_3x3mm_P0.5mm_LayoutBorder3x5y | U7 |
| 1 | LM3671MFX-3.3/NOPB | Kicad8_multilib:LM3671MFX-3.3 | U14 |
| 1 | LOGO | Kicad8_multilib:Silkscreen_ufo | G*** |
| 1 | LOGO | Kicad8_multilib:Silkscreen_sleeping_guy_26x20mm | G*** |
| 1 | LTC3226EUD-PBF | Kicad8_multilib:LTC3226 | U15 |
| 1 | MX25L3233FM1 | Package_SO:SOP-8_3.9x4.9mm_P1.27mm | U8 |
| 1 | PRTR5V0U2X_C2827688 | Kicad8_multilib:PRTR5V0U2X | U2 |
| 1 | RV-3028-C7 | Kicad8_multilib:RV-3028-C7 | U5 |
| 1 | TPA2016D2RTJR | Kicad8_multilib:TPA2016D2 | U1 |
| 1 | US1M | Diode_SMD:D_SMA | D3 |
| 1 | USB4110GFA | Kicad8_multilib:USB4110-GF-A | J1 |
The 157 most common of 162 parts.

KrHaaland/GNSS_Alarm_Clock
GNSS-synchronized alarm clock — custom SAMD51J20A board with nPM1300 Li-ion power (USB-C), offline timezone+DST from coordinates, LVGL 9 on a 428x142 TFT, WAV alarm tunes over USB, battery-backed RTC




ZigEmbeddedGroup/sycl-badge
The badge for the SYCL conference! https://zigembeddedgroup.github.io/sycl-badge/


miekush/sopracciglio-rp2040
Raspberry Pi RP2040 based Sopracciglio Board for use with 2026 Open Sauce Badge

nico25112005/Nerf-ATG-Electronics
This repository contains the electronic design files for a custom printed circuit board (PCB) developed to enhance Nerf LaserOps blasters.

It measures 80 × 50 mm and has 2 copper layers, 1.6 mm thick.
162 parts, built around the ATSAMD51J19A-AUT-EFP, L86-M33, IRLML6344TRPBF and 24LC512-I/P. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.
From the KrHaaland/GNSS_Alarm_Clock repository on GitHub, at the commit this page was made from: the board is HARDWARE_OLD/samd51_gps_alarm_clock.kicad_pcb and its schematic HARDWARE/GNSS_Alarm_Clock.kicad_sch. PCBKit opens the board in the browser, with nothing to install.
Its repository states no licence, so its author keeps all rights: ask KrHaaland before reusing the design.