This project lets you capture LED positions from a camera, adjust the layout, and export both the LED map and a 2D gap mask.
(randomly dropped lights on floor)
- Python 3.10+
- Camera accessible to the host machine
- WLED controller reachable via HTTP on your network
python -m venv .venv
.venv\\Scripts\\activate # on Windows
pip install -r requirements.txtpython server.pyOpen http://localhost:8000/ in your browser. The UI provides:
- Mapping controls (WLED host, LED count, segment, camera index, frames, brightness, skip-dim toggle)
- Timing controls (prelight/capture/postlight delays) and WLED transition (
TTin ms) - Live progress display while mapping runs
- Grid preview & camera scatter plot
- Buttons to generate/download
ledmap.jsonand2d-gaps.json(client-side download)
- Ensure the controller is reachable (open its UI, e.g.,
http://10.0.0.50/). - Use a single segment covering the entire strip (start 0, length = LED count).
- Use 1D LED layout in WLED (disable 2D matrix/panels). The mapper addresses LEDs linearly via
/winusingS/S2. - Disable any existing LED map in WLED. Existing remaps will break index-to-LED matching.
- Open
http://localhost:8000/. - In Controls, set:
- Host (e.g.,
http://10.0.0.50) - LEDs (your strip length)
- Segment (usually 0)
- Camera (index for your system)
- Frames/LED + Min Bright (detection tuning); enable Skip dim LEDs to move past LEDs that never cross the threshold
- Prelight/Capture/Postlight delays (stability tuning)
- Transition (ms) — WLED
TT, set 0 for instant changes
- Host (e.g.,
- Click Start Mapping. The backend will:
- Turn all LEDs off → light a single LED → off (repeats for each LED)
- Capture camera frames and store positions in
data/mapping.csv
- When done, Reload CSV if needed to refresh the UI camera/grid views.
- Adjust Step/Width/Height as needed.
- Click Apply to re-compute the grid and update the preview.
- Click Generate ledmap.json to download the LED map formatted for WLED (flattened
mapwithwidth/height). - Click Download 2D gaps to download a
1/-1grid mask.
Notes:
ledmap.jsonand2d-gaps.jsonare not saved on the server; they download in your browser. The raw capture stays indata/mapping.csv.- The UI toggle “Wire LEDs (in order)” draws a red line connecting LEDs 0→N in camera space for quick sanity checks.
You can run the mapping script directly:
python scripts/map_leds.py http://wled.local 150 --camera-index 1 --output data/mapping.csvAdd --skip-dim-leds to continue past LEDs that stay under the minimum brightness threshold.
and convert to JSON:
python scripts/convert_mapping.py --step 15 --include-meta- ModuleNotFoundError: fastapi - install dependencies with
pip install -r requirements.txt. - Camera not opened - verify the camera index and close other apps using it.
- WLED doesn’t light
- Confirm host/IP is reachable and WLED UI opens.
- Verify a single segment spans the entire strip.
- Test manual URLs (see above) — ensure
&SS,&S/&S2,&A, and&TTare present. - Increase Prelight/Capture/Postlight delays if your camera needs more time.
- Backend API:
server.py - Mapping logic:
scripts/map_leds.py - Conversion/trimming logic:
scripts/convert_mapping.py - Frontend UI:
ui/led_viewer.html
Contributions are welcome! Fork, branch, and open a PR.
