projects:lawrencelightsheightmeasurer

North Pole Height Display — Software Spec (draft)

ESP32-WROOM-32 (board: ESP32 Dev Module), TFmini Plus, 146-pixel 5V strip, Bluetooth Classic serial.

Item Value
TFmini green (sensor TX) IO16 (Serial2 RX)
TFmini white (sensor RX) IO17 (Serial2 TX)
TFmini baud 115200 (sensor default)
Pixel data IO18 → level shifter → 300–500 Ω → DIN
Pixel count 146
Power 12A 5V supply, all grounds common; program with VBUS disconnected

Defaults live at the top of the code. Every value can also be changed over Bluetooth (after unlock) and is saved to flash, so field adjustments survive the nightly power-off without reflashing.

Setting Default Notes
SENSOR_HEIGHT_CM (measure in field) Lens to ground. Fallback and clamp for the auto-learned ground distance.
GROUND_CLAMP_CM 30 Learned ground distance may differ from SENSOR_HEIGHT_CM by at most this.
MIN_TRIGGER_HEIGHT_CM 70 Set with toddlers in mind.
MIN_FLUX 100 Below this (or dist = 0) a reading is “unknown”, not “gone”.
PRESENCE_STABLE_MS 500 Height must hold this long to trigger.
ABSENT_MARGIN_CM 15 Reading within this of ground = nobody there.
HOLD_AFTER_LEAVE_MS 1000 Show continues this long after the person steps away.
REMEASURE_DELTA_CM 10 Height change that counts as a different person.
REMEASURE_STABLE_MS 500 New height must hold this long before restarting.
FIRST_VIEW_LED 0 Raw index of lowest visible LED.
LAST_VIEW_LED 145 Raw index of highest visible LED.
CAL_LOW_LED / CAL_LOW_CM 20 / 30.48 Raw LED index lined up with the 1 ft mark. Placeholder index so bench testing works; set in field.
CAL_HIGH_LED / CAL_HIGH_CM 130 / 182.88 Raw LED index lined up with the 6 ft mark. Placeholder index; set in field.
SIM_AT_BOOT false Compile-time only. true boots straight into simulation for bench work.
BRIGHTNESS_MAX 128 (of 255) Global cap.
DAZZLE_MS 3000 Also the measurement window.
RISE_SPEED (tune) LEDs/s Ease-out: fast start, slows near the top.
DRAIN_SPEED (tune) LEDs/s Slower than the rise.
IDLE_FADE_IN_MS 1000 Idle fades in after the outro.
BT_NAME NorthPoleLidar
BT_PASSWORD ll
  • Linear interpolation between the two calibration points; covers LED spacing, strip start offset and stretch in one step.
  • Strip direction is derived from the calibration points: if CAL_HIGH_LED < CAL_LOW_LED, the strip is reversed. Open item: confirm this replaces a separate reverse flag (two settings that could disagree).
  • All animations work in “visible position” (0 = lowest visible LED), mapped to raw indices through FIRST_VIEW_LED / LAST_VIEW_LED and the direction.
  • Height at or above the height of the top visible LED → “off the charts”.
  • BOOT — load settings from flash, start sensor and Bluetooth, start idle.
  • IDLE — attract animation. Continuously learn ground distance (median of readings with nobody present, clamped by GROUND_CLAMP_CM). Trigger when height ≥ MIN_TRIGGER_HEIGHT_CM holds for PRESENCE_STABLE_MS → DAZZLE.
  • DAZZLE — random dazzle animation for DAZZLE_MS. Collect every valid sample; height = median. Abort to IDLE if the person leaves.
  • RISE — column grows from the bottom to the measured height with ease-out; gold star at the top. Off-the-charts variant if height ≥ top visible LED.
  • SHOW — random show mode, loops until the person leaves.
    • Height shifts by REMEASURE_DELTA_CM for REMEASURE_STABLE_MS → back to DAZZLE (different person).
    • Absent for HOLD_AFTER_LEAVE_MS → OUTRO.
  • OUTRO — random outro animation → IDLE (idle fades in, never a cut).
  • FAULT — no frames from the sensor for ~1 s: idle animation only, report over Bluetooth, keep retrying; return to IDLE when frames resume.

Height = ground distance − measured distance. Absent = reading within ABSENT_MARGIN_CM of ground. Unknown readings (low flux, dist 0) never count as absent.

Palette: Christmas red, green, white, gold. Gamma-corrected fades. All non-blocking (no delay()), so the sensor is read every frame.

  • Slow red/green wave drifting up the pole. (More variants can be added and picked at random.)
  • Candy cane — red/white bands scrolling up.
  • Comets — bright heads with fading tails shooting up, overlapping.
  • Twinkle — random pixels flash white/gold and fade.
  • Scanner — single bright bar sweeping up and down, speeding up.
  • Theater chase — red/green marquee.
  • Fill-and-drain — green fills and drains repeatedly.
  • Crawlers — red fill, green pulses travel up to the star and repeat.
  • Candy cane fill — red/white stripes scrolling slowly upward inside the filled column.
  • Breathing — green fill pulsing, red waves moving up through it.
  • In all modes: gold star blinks/sparkles at the measured height; LEDs above the height are off or a very dim twinkle.
  • Whole column overflows, sparkles bursting at the top.
  • Drain — column drains down, slower and eased; the star falls last as a falling star with a short tail.
  • Dissolve — lit pixels twinkle out one by one, top down.

Both channels are identical: all status output goes to both, and every command is accepted from either. USB serial (115200) needs no unlock — physical access to the board is treated as trusted. Bluetooth still requires unlock ll for config, sim, demo and play commands.

  • State changes.
  • Each measurement: height in cm and ft/in, sample count, spread, which dazzle/show was picked.
  • Learned ground distance, faults, boot info, visitor counts.
Command Unlock needed Action
help no List commands.
status no Current state, last reading, ground distance, counts.
unlock <pw> — Unlock config until the client disconnects.
get no List all settings.
set <key> <value> yes Apply immediately and save to flash.
defaults yes Restore code defaults.
led <n> / led off yes Light one raw LED (for calibration). Suspends the normal show until led off.
count no Season total and tonight's count.
count reset yes Zero the season total.
reboot yes Restart.
sim on / sim off yes Ignore the TFmini; use simulated readings. Never saved to flash, so a reboot always returns to the real sensor (unless SIM_AT_BOOT is set in code).
sim height <cm> yes Simulated person of that height steps in. Sent again with a different height during SHOW = sibling swap.
sim leave yes Simulated person steps away (reading returns to ground).
sim noise <cm> yes Add random jitter to simulated readings, to exercise the median, remeasure and hold logic. 0 = off.
sim dropout <on/off> yes Random low-flux “unknown” readings mixed in.
sim fault yes Simulated sensor loss → FAULT state. sim height or sim leave ends it.
demo on / demo off yes Loop the full cycle automatically: random height in, step out, wait, repeat. Exercises every state and random pick hands-free.
play <type> <name> yes Run one animation by name, outside the state machine, looping until play stop. Types: idle, dazzle, show, outro, offcharts. show/outro use the last simulated height (or 120cm).
play list no List animation names by type.
next <type> <name> yes Force the next random pick for that type (one time), so a specific animation can be tested inside the real flow.
  • Simulation replaces only the sensor input; everything downstream (presence, median, remeasure, hold, state machine, animations) runs unchanged, so bench behavior matches the field.
  • Simulated measurements and demo cycles do not increment the visitor count.
  • Status output tags simulated readings ([SIM]) so logs can't be confused with real ones.
  • Counted when a measurement completes (not on abort).
  • Season total saved to flash on every measurement; tonight's count in RAM only.
  • Flash wear: ESP32 NVS is wear-leveled and uses 32-byte entries, 126 per 4KB page, so one sector erase per ~126 writes (Espressif NVS docs). A few hundred measurements a night over a season is a few hundred erases spread across the NVS pages.
  • Task watchdog reboots on a hung loop.
  • Cold boot every evening (external timer); boot must be quick and need no Bluetooth interaction.
  • projects/lawrencelightsheightmeasurer.txt
  • Last modified: 2026/11/10 23:07
  • by John Harrison