How m1lucken/audio-reactive-led-strip works
Project Type and Purpose
• This is a full-stack IoT/music visualization application.
• Purpose: Capture real-time audio, process it, generate LED pixel data, and drive a WS2812 LED strip via either an ESP8266 microcontroller over WiFi or directly from a Raspberry Pi.
Main Components
A. Audio Input Layer
– Microphone or virtual audio source on the host computer or USB audio device on Raspberry Pi.
– Python module: microphone.py
B. Processing & Visualization Layer (Host)
1. DSP Pipeline
• dsp.py – FFT, filtering, melbank generation (melbank.py), gamma correction table (gamma_table.npy)
2. Visualization Engine
• visualization.py – 1D mapping of frequency bins to pixel intensities
3. GUI (optional on Pi)
• gui.py – PyQtGraph to display real-time plot
4. Configuration
• config.py – settings: N_PIXELS, MIC_RATE, UDP_IP, device type
C. Network Transmission Layer
• led.py – packetizes pixel data into UDP frames, sends to ESP8266’s IP on the local WiFi network
• Uses standard UDP socket library
D. Microcontroller Firmware Layer
• Arduino sketch: ws2812_controller_esp8266.ino (also ESP32 variant)
• WebSocketServer library or raw UDP listener on ESP8266
• I²S peripheral driver to bit-bang/stream data into WS2812 strip
• Network stack (ESP8266 WiFi) configured via SSID/password/gateway/IP
E. Hardware Layer
1. Host machine or Raspberry Pi
2. WiFi router (SSID, gateway)
3. ESP8266 module (NodeMCU v3 / Feather HUZZAH)
4. WS2812B LED strip
5. Power supply + level shifter
Relationships and Data Flow
• Audio input → DSP → Visualization → (if on computer) GUI
• Visualization output → UDP → ESP8266
• ESP8266 → I²S → WS2812 LED strip
• On Raspberry Pi mode: Visualization can bypass UDP and drive LEDs via rpi_ws281x library directly.
Architectural Patterns and Design Principles
• Pipeline pattern for the audio-to-pixels transformation
• Clear separation of concerns:
– Capture (microphone.py)
– Process (dsp.py, melbank.py)
– Transport (led.py)
– Actuate (Arduino firmware)
• Configuration-driven behaviour (config.py) to switch between “computer+ESP8266” and “standalone Pi” modes
• Use of asynchronous or buffered I/O to maintain real-time constraints
Relevant Technologies and Frameworks
• Python 2.7/3.x, NumPy, SciPy, PyAudio, PyQtGraph
• UDP sockets (Python stdlib)
• Arduino IDE with ESP8266 addon, WebSocketServer library, esp8266_ws2812_i2s driver
• Raspberry Pi: rpi_ws281x library (C/Python bindings)