Skip to content

Smart LEDs util library sends incorrect data beyond 2nd pixel #355

@tschundler

Description

@tschundler

Using more than one LED color yields random-seeming output (see photos linked below). This in on an ESP32-S3 (examples below). I got slightly different and still incorrect behavior on a plain ESP32.

Using this code to generate a simple pattern:

    leds.write(std::iter::repeat(RGB::new(0,0,0)).take(64)).unwrap();
    leds.write((0..8_u8).map(|n| // only 8 to test
            match (n, n%4) {
                (_, 0) => RGB::new(n,0,63-n), // Blue->Red gradient
                (_, 1) => RGB::new(40,40,0), // Yellow
                (_, 2) => RGB::new(0,63,0), // Green
                (_, _) => RGB::new(0,40,40), // Cyan
            }
        ))

With esp-idf-sys

    let mut leds = Ws2812Esp32Rmt::new(0,17).unwrap();

using https://github.com/cat-in-136/ws2812-esp32-rmt-driver:

yields https://photos.app.goo.gl/fZh9Lh9fwJUy3wMk8 (what I expect)

With esp-hal

    let peripherals = Peripherals::take();
    let mut system = peripherals.SYSTEM.split();
    let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

    let mut rtc = Rtc::new(peripherals.RTC_CNTL);
    let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks);
    let mut wdt = timer_group0.wdt;
    let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);

    // Disable MWDT and RWDT (Watchdog) flash boot protection
    wdt.disable();
    rtc.rwdt.disable();

    let pulse = PulseControl::new(
        peripherals.RMT,
        &mut system.peripheral_clock_control,
        ClockSource::APB,
        0,
        0,
        0,
    )
    .unwrap();
    let mut leds = <smartLedAdapter!(64)>::new(pulse.channel0, io.pins.gpio17);

...copied from https://github.com/esp-rs/esp-hal/blob/main/esp32s3-hal/examples/hello_rgb.rs

yields https://photos.app.goo.gl/CePVYZvMFgJtBtCH6

almost all LEDs are lit, and except the first two, the colors aren't even in the correct order.)

Debugging

I started debugging setting a pin high. I noticed...

  • in esp-hal
    • there's a 4.2-4.3ms delay before data is sent out.
    • The data out is ~1.9ms total (full 64px?)
    • each bit is ~1.2us from rising-edge to rising-edge
    • changing buffer to only 8px instead of 64, the delay to output is the same, and the length of the data out is the same (~1.9ms)
    • changing the buffer to 256px increases delay to 109ms and the burst to 78ms (this seems crazy - 4x pixels=>40x time to transmit??)
  • in esp-idf
    • 72us delay before data is sent
    • data is 240us total (just the provided 8px)
    • also ~1.2us per bit

...will report more if I find more. The first pixel in esp-hal is right, but afterwards things get odd.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions