fabsenet/adrilight

WS2811 support

Closed this issue · 4 comments

Hi i have ws2811 led strip which was used by bambilight ... but it seem not working with adrilight. is there any way how to fix that ? thanks

This should definitely work. Did you flashed the arduino properly? Tell me more about your setup please

It does work with minor code adjustments!
WS2811 is what I have.
Give us details then we can provide some support.

Hi! I also have some problem with WS2811 and Adrilight. I hope someone can help me with this. I have

What do I did?
I've modified the following values in adrilight.ino:

  • Serial.begin value from1000000 to 115200 (but I've tried with 1000000 as well - but my com port has 115200
  • NUM_LEDS to (2x63+2x36)
  • and in setup part changed the led strip tipe to WS2811 but I've also tested with WS2812B FastLED.addLeds<WS2811, LED_DATA_PIN, GRB>(leds, NUM_LEDS);
  • Changed values in adrilight.exe. (spots x and y COM port and checked LED-output)

I could deploy the adrilight.ino into the arduino. Seems good. Data led is flashing when I check LED-ouptut checkbox in adrilight.exe, so i guess arduino receive the data. When LED-output is unchecked the led strip flashing like a rainbow but after I check that free in that state and do not doing anything after that.

Any idea?

My modified adrilight.ino:

#include "FastLED.h"

#define NUM_LEDS (2*63+2*36)
#define LED_DATA_PIN 3
#define NUM_BYTES (NUM_LEDS*3) // 3 colors  

#define BRIGHTNESS 255
#define UPDATES_PER_SECOND 60

#define TIMEOUT 3000

#define MODE_ANIMATION 0
#define MODE_AMBILIGHT 1
#define MODE_BLACK 2
uint8_t mode = MODE_ANIMATION;

byte MESSAGE_PREAMBLE[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 };
uint8_t PREAMBLE_LENGTH = 10;
uint8_t current_preamble_position = 0;

unsigned long last_serial_available = -1L;

int led_counter = 0;
int byte_counter = 0;

CRGB leds[NUM_LEDS];
byte buffer[NUM_BYTES];

// Filler animation attributes
CRGBPalette16 currentPalette = RainbowColors_p;
TBlendType    currentBlending = LINEARBLEND;
uint8_t startIndex = 0;

void setup()
{
    Serial.begin(115200); // 115200
    FastLED.clear(true);
    FastLED.addLeds<WS2811, LED_DATA_PIN, GRB>(leds, NUM_LEDS);
    FastLED.setBrightness(BRIGHTNESS);
}

void loop()
{
    switch (mode) {
        case MODE_ANIMATION: 
            fillLEDsFromPaletteColors();
            break;
        
        case MODE_AMBILIGHT:
            processIncomingData();
            break;

            case MODE_BLACK:
            showBlack();
            break;
    }
    
}

void processIncomingData()
{
    if (waitForPreamble(TIMEOUT))
    {
        Serial.readBytes(buffer, NUM_BYTES);

        while (byte_counter < NUM_BYTES)
        {
            byte blue = buffer[byte_counter++];
            byte green = buffer[byte_counter++];
            byte red = buffer[byte_counter++];
            
            leds[led_counter++] = CRGB(red, green, blue);
        }

        FastLED.show();
        
        // flush the serial buffer to avoid flickering
        while(Serial.available()) { Serial.read(); } 
        
        byte_counter = 0;
        led_counter = 0;
    }
    else
    {
        //if we get here, there must have been data before(so the user already knows, it works!)
        //simply go to black!
        mode = MODE_BLACK;  
    }
}

bool waitForPreamble(int timeout)
{
    last_serial_available = millis();
    current_preamble_position = 0;
    while (current_preamble_position < PREAMBLE_LENGTH)
    {
        if (Serial.available() > 0)
        {
            last_serial_available = millis();

            if (Serial.read() == MESSAGE_PREAMBLE[current_preamble_position])
            {
                current_preamble_position++;
            }
            else
            {
                current_preamble_position = 0;
            }
        }

        if (millis() - last_serial_available > timeout)
        {
            return false;
        }
    }
    return true;
}

void fillLEDsFromPaletteColors()
{
    startIndex++;

    uint8_t colorIndex = startIndex;
    for( int i = 0; i < NUM_LEDS; i++) {
            leds[i] = ColorFromPalette(currentPalette, colorIndex, BRIGHTNESS, currentBlending);
            colorIndex += 3;
        }

    FastLED.delay(1000 / UPDATES_PER_SECOND);

    if (Serial.available() > 0)
    {
        mode = MODE_AMBILIGHT;
    }
}

void showBlack()
{     
    for( int i = 0; i < NUM_LEDS; i++) 
    {
        leds[i] = CRGB(0,0,0);
    }
    FastLED.delay(1000 / UPDATES_PER_SECOND);

    if (Serial.available() > 0)
    {
        mode = MODE_AMBILIGHT;
    }
}

@matyaskov please start a seperate issue to not "take over" this issue. Your cannot change the baud rate in the arduino code because the pc part has a fixed baud rate of 1.000.000 as well. if you change it only on one side, it will break. Also: if you have 190 leds and a baud rate of only 115k...even if it would work, it would be painfully slow and lagging behind the screen content a frame or two.