hpwit / I2SClocklessLedDriver

MIT License
61 stars 14 forks source link

Unable to display LEDs properly with WiFi streaming data + task #32

Closed XavierGerD closed 2 weeks ago

XavierGerD commented 2 weeks ago

Hi,

I've been attempting to stream some data over WiFi to display LED color/video. Unfortunately, I'm unable to make the display work consistently. Bugs include:

Using WS2813Cs, here is my code (I removed the irrelevant parts, hopefully I didn't forget anything)

#define NUM_LEDS_PER_STRIP 320
#define FULL_DMA_BUFFER
#include <FastLED.h>
#include "I2SClocklessLedDriver.h"
#define LEDSTRIP1_PIXEL_COUNT 320
#define LEDSTRAND1_GPIO_NUM 17

I2SClocklessLedDriver driver;
CRGB leds[NUM_LEDS_PER_STRIP];
int pins[1] = { LEDSTRAND1_GPIO_NUM };

struct LightingState_s {
  Mode_e mode;
  uint8_t blackout;
  uint8_t strobe;
  uint8_t global_brightness;
  Color_t global_color;
};

struct LightingState_s lightingState;

void setup() {
  driver.initled((uint8_t*)leds, pins, 1, NUM_LEDS_PER_STRIP, ORDER_GRB);
  xTaskCreatePinnedToCore(LEDTask, "LED", 10000, NULL, configMAX_PRIORITIES - 1, NULL, 1);

// Some code to connect to WiFi
}

void LEDTask(void* p) {
 for (;;) {
      for (uint16_t i = 0; i < NUM_LEDS_PER_STRIP; i++) {
        driver.setPixelinBuffer(i, lightingState.global_color.red, lightingState.global_color.green, lightingState.global_color.blue);
      }
      driver.setBrightness(lightingState.global_brightness);
      driver.showPixelsFromBuffer(NO_WAIT);
      vTaskDelay(30);
      continue;
  }
}

// This function contains a lot more code but this is the essential
void WifiReceivePacket(AsyncUDPPacket& packet) {
  e131_packet_t* e131_packet = reinterpret_cast<e131_packet_t*>(packet.data());
  Color_t dmxColor;
  dmxColor.red = e131_packet->property_values[CHANNEL_RED];
  dmxColor.green = e131_packet->property_values[CHANNEL_GREEN];
  dmxColor.blue = e131_packet->property_values[CHANNEL_BLUE];
  // Here we set the color that will be later pushed to the LEDs in LEDTask.
  lightingState.global_color = dmxColor;
}

As mentioned above, the most common bug is that the LEDs display random colors. For example, if I set the RGB values to (255, 0,0), it will show the colors properly. But, if I bring down the value below about (150, 0,0), then I start to see some flickering. Also, changing the color too quickly crashed the ESP sometimes.

Also I should mention that the LEDs show perfectly fine when using a built-in color function that doesn't rely on the WiFi data. So I'm not sure it's an electrical problem.

Any insight is much appreciated! Thanks!!

XavierGerD commented 2 weeks ago

Closed because I needed a level shifter... D'oh

hpwit commented 1 week ago

So it works now ?

XavierGerD commented 1 week ago

Thanks for the reply. It seems most of my issues are fixed now, it was indeed a problem with the 3.3V logic.

However, one weird issue still remains. When using setPixelinBuffer and showPixelsFromBuffer, giving the pixels high-ish RGB values makes the ESP crash. For example:

for (uint16_t i = 0; i < NUM_LEDS_PER_STRIP; i++) {
   driver.setPixelinBuffer(i, red, green, blue);
}
driver.showPixelsFromBuffer();

In this case, the values 215, 30, 149 shows the proper color just fine. But as soon as I raise the red channel to something like 200+, the ESP crashes repeatedly:

rst:0x3 (SW_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)

Any ideas on why this might be? I'm calling the setPixelinBuffer and showPixelFromBuffer methods from inside a task.

hpwit commented 1 week ago

Hello Strange I will have a look at it Yves