Pixelblaze LED Controller Documentation

repository·master·Indexed 42 days ago

https://github.com/simap/pixelblaze

Open-source components, adapters, and libraries for the Pixelblaze LED controller platform. Includes comprehensive references for writing patterns and mappers using a subset of ES6 JavaScript, featuring core render functions like render(), render2D(), and render3D(), as well as guides for creating custom UI controls, utilizing the sensor expansion board, and implementing coordinate transformations.

Tokens
5.5K
Snippets
11
Records
24
Agent score
54%

What's inside Pixelblaze

  1. Access Pixelblaze documentation and references

    master

    Pixelblaze is a hardware platform for controlling addressable LEDs. While the core Pixelblaze firmware is not open source, this repository provides open-source components, adapters, and libraries.

    For official setup, guides, and documentation, visit the Electromage Docs.

    To write patterns and mappers, refer to the following internal documentation files in this repository:

    • Pattern code Reference: README.expressions.md
    • Mapper code Reference: README.mapper.md
  2. Use the Var Watcher to inspect data

    master

    The Var Watcher UI component displays the values of any exported variables.

    • Arrays: Supports watching arrays, showing each element with its index.
    • Sensor Data: You can watch data from the sensor expansion board (ADC, accelerometer, light, sound).
    • Sampling: Data is sampled at the end of rendering.

    Tip: If you export a global variable modified inside render(), the watcher usually only shows the last value. To inspect data for a specific pixel, use conditional assignment: if (index == 42) myExportedVar = someInterestingData

  3. How the Pixel Mapping System works

    master

    The pixel mapping system allows patterns to be aware of the physical LED layout (e.g., matrices, rings, or 3D shapes). Instead of treating LEDs as a simple 1D list, the system uses a pixel map to assign each pixel a coordinate in a 2D or 3D space.

    Core Workflow

    1. Define a Pixel Map: Create a map in the Mapper tab specifying coordinates for every pixel. Coordinates can be pairs [x, y] for 2D or triplets [x, y, z] for 3D.
    2. Coordinate Scaling: The system automatically scales your input coordinates (whether in inches, mm, or pixels) to a normalized range of 0.0 to 1.0. This represents the position within the mapped "world."
    3. Pattern Rendering: Patterns use specialized render functions to access these coordinates. Because coordinates are normalized, a single pattern can work on any physical layout by scaling to the mapped world size.

    Scaling Options

    When defining the map, you can choose how the world dimensions are handled:

    • Fill: Stretches or squishes the map to fit every dimension.
    • Contain: Maintains the aspect ratio, resizing to fit the largest dimension.
    // Example of the mental model: patterns use normalized coordinates
    // regardless of the physical size of the LED array.
    export function render2D(index, x, y) {
      // x and y are between 0.0 and 1.0
      hsv(x, 1, y)
    }
  4. How Pixelblaze patterns are rendered

    master

    Pixelblaze uses specific exported functions to drive the pixel strip. The engine looks for these functions to determine how to generate colors and handle timing.

    Core Render Functions

    • render(index): The primary function called for every pixel. The index argument represents the current pixel position. Use hsv() or rgb() within this function to set the color.
    • render2D(index, x, y) and render3D(index, x, y, z): Alternative render functions used if a 2D or 3D pixel map is configured in the Mapper tab.

    Animation and Timing

    • beforeRender(delta): Called once before a new frame is rendered. The delta argument is the elapsed time in milliseconds since the last call (with 6.25ns resolution). Use delta to ensure animations run at a consistent speed regardless of frame rate.

    Global Constants

    • pixelCount: A global variable representing the total number of configured LED pixels.
    export function render(index) {
      hsv(0, 1, 1);
    }
    
    export function beforeRender(delta) {
      // Use delta for frame-rate independent animations
    }
  5. Use the Mounting Cradle for Pixelblaze enclosures

    master

    The Mounting Cradle is a universal component that allows you to snap in any of the 4 enclosure configurations. It provides several mounting and cable management options:

    • Screw Mounting: Includes holes for M2.5-M4 screws.
    • Versatile Mounting: Features variable-width slots for using smaller screws, hanging on a wall, or mounting to poles (e.g., a bike) using zip ties.
    • Strain Relief:
      • Includes an optional output strain relief shelf (can be added to shell versions later).
      • Includes a strain relief platform for the USB power connection that accepts a zip tie.
  6. Access Pixelblaze runtime logs via serial

    master

    If the power supply is confirmed to be working, you can inspect the device's runtime status using serial logging.

    Setup Steps:

    1. Connect a 3.3V serial adapter to the serial communication pins on the Pixelblaze expansion header.
    2. Open a terminal program on your computer.
    3. Configure the terminal settings to: 115200 baud, 8N1 (8 data bits, no parity, 1 stop bit).

    Monitor the logs for specific errors, particularly those related to WiFi connectivity (e.g., *WM: Connection timed out).

    # Terminal settings
    Baud rate: 115200
    Data bits: 8
    Parity: None
    Stop bits: 1
  7. Create custom User Interface Controls

    master

    You can create persistent UI controls that appear when a pattern is active. These allow users to change pattern behavior without editing code. Controls are created by exporting functions with specific name prefixes.

    Input Controls

    These functions are called when the user interacts with the UI. You should typically store the incoming value in a variable to use in your pattern.

    PrefixExample FunctionDescription
    slidersliderMySlider(v)A slider returning a value between 0.0 and 1.0.
    hsvPickerhsvPickerColor(h, s, v)A color well returning Hue, Saturation, and Value (0.0 to 1.0).
    rgbPickerrgbPickerColor(r, g, b)A color well returning Red, Green, and Blue (0.0 to 1.0).
    toggletoggleEnabled(isEnabled)A switch returning true (1) or false (0).
    triggertriggerFire()A button that triggers a function call (no parameters).
    inputNumberinputNumberScale(v)A numeric input for any decimal or integer value.

    Output Controls

    These functions are called frequently to display information in the UI. They must return a value.

    PrefixExample FunctionDescription
    showNumbershowNumberEnergy()Displays a number with 4 decimal places.
    gaugegaugeLightLevel()Displays a percentage gauge (clamped between 0.0 and 1.0).

    Note: Controls are persistent and their settings are preserved across restarts.

    var mySetting = 0.5
    export function sliderMySetting(v) {
    	mySetting = v
    }
    
    export function hsvPickerPrimaryColor(h, s, v) {
      // Use h, s, v to set colors
    }
    
    export function gaugeLightLevel() {
      return light / 100; // Example return
    }
  8. Choose a Pixelblaze enclosure configuration

    master

    Pixelblaze enclosures are available in four variants based on how you intend to connect your LED strips and power. The choice depends on whether you prefer soldering or using pre-soldered connectors.

    Ready-to-Run (R2R)

    Designed specifically for the "no soldering required" Pixelblaze version.

    • Connector: Uses a JST-XH connector pre-installed on the underside of the circuit board.
    • Openings: Has an opening on the bottom for the JST-XH and a side opening for an optional USB power connection (2.1A max).

    Flexible Connection

    Designed for users who want to choose their connection method. You must snap out the plastic for the specific output openings you need.

    • Option 1: Traditional screw terminal soldered to the top of the board.
    • Option 2: JST-XH soldered to the top of the board.
    • Option 3: JST-XH soldered to the bottom of the board (similar to the R2R version).
    • Openings: Supports any of the above plus an optional USB power-in connection.
  9. Map a pixel layout using a JSON Array

    master

    You can define a pixel map by providing a plain JSON array of arrays in the Map Editor. Each top-level element represents a single pixel. Inside that element, provide an array containing the coordinates.

    • 2D Mapping: Use [x, y]
    • 3D Mapping: Use [x, y, z]

    Example of a 4-pixel box (top-left, top-right, bottom-right, bottom-left):

    [
      [0,0],
      [100,0],
      [100,100],
      [0,100]
    ]
  10. Secure enclosure lids and wires

    master

    Securing Lids

    While the slide-in lids use a friction-fit design, they include a hole for an M2x8mm self-tapping or wood screw if additional security is required.

    Wire Strain Relief

    Both the Ready-to-Run and Flexible Connection designs offer an optional strain relief shelf on the output side. You can use a small zip tie to tighten your output wires to this shelf. This is highly recommended for JST-XH connections, as they can be pulled out with moderate force.

  11. Connect LED strips without soldering

    master

    If you use the "no soldering required" Pixelblaze, it comes with a JST-XH connector (a small white connector without a retaining notch) pre-installed on the underside of the circuit board.

    To connect this to typical LED strips (which usually use JST-SM 3 or 4 pin connectors with a retaining notch), you can use various JST-XH to JST-SM adapters. These adapters handle different pin assignments, allowing for a solderless connection to most LED strips.

  12. Verify Pixelblaze bootloader functionality

    master

    If the Pixelblaze does not output any logging information via the serial method, the bootloader may be corrupted. You can test the bootloader using esptool.

    Steps to test:

    1. Install esptool.
    2. Put the Pixelblaze into bootloader mode. The easiest method is to hold GP0 low (grounded) during power-up.
    3. Run an esptool.py command to query the device (e.g., flash_id).

    If esptool fails to receive a response, refer to the official esptool troubleshooting documentation.

    $ esptool.py --port /dev/ttyUSB0 -b 115200 flash_id