achimpieters/esp32-led-strip

1.0.0

Latest
uploaded 1 day ago
Multi-protocol LED strip controller for ESP32 with RGB and RGBW support. Supports WS2812, WS2812B, SK6812, APA104, APA102, SK9822, LPD8806, and WS2801.

readme

# Example for `ESP32-led-strip` Component

## What it Does

This example demonstrates how to control addressable LED strips using the `ESP32-led-strip` component within the ESP-IDF framework. It supports the following LED types:

- WS2812 / WS2812B  
- SK6812 (RGB or RGBW)  
- APA104  
- APA102 / SK9822 (SPI)  
- LPD8806 / WS2801 (SPI)

The component handles low-level RMT or SPI transmission depending on the LED type. It also supports both RGB and RGBW color formats.

## Configuration

No `menuconfig` configuration is required. The component is initialized by defining a configuration struct in code:

```c
smart_led_config_t config = {
    .led_type = LED_TYPE_WS2812B,
    .format = SMART_LED_RGB,
    .rmt = {
        .gpio = GPIO_NUM_18,
    },
    .num_pixels = 10
};

smart_led_init(&config);
```

## API Overview

The following public API functions are provided:

- `esp_err_t smart_led_init(const smart_led_config_t *config);`
- `esp_err_t smart_led_set_pixel(uint16_t index, uint8_t r, uint8_t g, uint8_t b, uint8_t w);`
- `esp_err_t smart_led_refresh(void);`
- `esp_err_t smart_led_clear(void);`

Use `.rmt` or `.spi` in the config struct depending on LED type (RMT for WS2812-type, SPI for APA102/WS2801-type).

## Example Code

```c
#include <stdio.h>
#include "smart_led.h"

void app_main(void)
{
    smart_led_config_t config = {
        .led_type = LED_TYPE_SK6812,
        .format = SMART_LED_RGBW,
        .rmt = {
            .gpio = GPIO_NUM_18,
        },
        .num_pixels = 8
    };

    smart_led_init(&config);

    for (int i = 0; i < 8; i++) {
        smart_led_set_pixel(i, 255, 0, 0, 32); // red + soft white
    }

    smart_led_refresh();
}
```

## Building and Running

Build the project:
```bash
idf.py build
```

Flash it to the ESP32:
```bash
idf.py flash
```

Monitor logs:
```bash
idf.py monitor
```

## Example Output (LED behavior)

- LEDs display configured colors
- If RGBW: white mixes into output
- No flicker or stutter with correct timings

## Notes

- Fully compatible with all ESP32-series targets (ESP32, C2, C3, C5, C6, S2, S3)
- Automatically selects RMT or SPI backend
- RGBW output depends on strip capabilities
- Designed for HomeKit or other RGB/RGBW control layers
- You can combine this with a color conversion library like `color-converter` for dynamic effects

---

**StudioPieters®** | Innovation and Learning Labs  
🌐 https://www.studiopieters.nl | 🧑‍💻 GitHub: https://github.com/AchimPieters

Links

Maintainer

  • info@studiopieters.nl

License: MIT

To add this component to your project, run:

idf.py add-dependency "achimpieters/esp32-led-strip^1.0.0"

or download archive

Stats

  • Archive size
    Archive size ~ 4.97 KB
  • Downloaded in total
    Downloaded in total 0 times
  • Downloaded this version
    This version: 0 times

Badge

achimpieters/esp32-led-strip version: 1.0.0
|