FastLED Wasm Compiler
raw JSON → 2.0.6 verified Mon Apr 27 auth: no python
A Python library that compiles Arduino sketches using the FastLED library to WebAssembly, enabling LED animations in the browser. Current version is 2.0.6, with a recent major version bump from 1.x to 2.x. Release cadence is irregular, with active development on GitHub.
pip install fastled Common errors
error ImportError: cannot import name 'compile_wasm' from 'fastled.compiler' ↓
cause In v2.x, the import path changed. The old `fastled.compiler` module no longer exists.
fix
Use
from fastled import compile_wasm. error RuntimeError: emcc not found. Please install Emscripten and add it to PATH. ↓
cause The library requires Emscripten SDK to compile C++ to WebAssembly, but it's not installed or not in PATH.
fix
Install Emscripten:
git clone https://github.com/emscripten-core/emsdk.git then cd emsdk && ./emsdk install latest && ./emsdk activate latest && source ./emsdk_env.sh. Warnings
breaking Major version 2.0.0 introduced breaking changes: the `compile_wasm` function replaces the old `FastLEDWasm` class-based API from v1.x. Old code using `from fastled.compiler import compile_wasm` will break. ↓
fix Update imports to `from fastled import compile_wasm` and adjust function calls accordingly.
gotcha The `target` parameter must be explicitly specified when calling `compile_wasm`. Default is 'web', but omitting it may lead to unexpected output. ↓
fix Always pass `target='web'` or `target='cli'` to avoid ambiguity.
gotcha Compilation requires a C++ compiler toolchain (e.g., Emscripten) to be installed. The library does not bundle these; missing tools lead to obscure errors. ↓
fix Install Emscripten SDK (emsdk) and ensure `emcc` is in PATH. See https://emscripten.org/docs/getting_started/downloads.html
Imports
- compile_wasm wrong
from fastled.compiler import compile_wasmcorrectfrom fastled import compile_wasm - FastLEDWasm
from fastled import FastLEDWasm
Quickstart
from fastled import compile_wasm
sketch_code = '''
#include <FastLED.h>
#define NUM_LEDS 60
#define DATA_PIN 2
CRGB leds[NUM_LEDS];
void setup() { FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS); }
void loop() { fill_solid(leds, NUM_LEDS, CRGB::Red); FastLED.show(); delay(100); }
'''
wasm_bytes = compile_wasm(sketch_code, target='web')
print(f'Compiled WASM size: {len(wasm_bytes)} bytes')