0

I bought some individually addressable LED strips (a large reel). To keep the cost down they are WS2811 and it's one chip per 6 leds. I don't know the cheapness or LED styl makes any difference to the problem but I'm just putting it out there.

They support 24V so to be safe I'm running them at 23V. I have the data line hooked up to pin 13 of the ESP, and a ground connection to the power supply to create a common ground. I am using Alexa to control the colours. This is the code:

#include <WiFi.h>
#include <Espalexa.h>
#include <FastLED.h>
#include <Adafruit_NeoPixel.h>

FASTLED_USING_NAMESPACE

#define NUM_LEDS 120
#define LED_TYPE WS2811
#define LED_PIN 13
CRGB leds[NUM_LEDS];

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, LED_PIN, NEO_RGB + NEO_KHZ400);

#define ESPALEXA_ASYNC
Espalexa espalexa;

#define RELAY_PIN 12

boolean connectWifi();

void colorLightChanged(uint8_t brightness, uint32_t rgb);

const char* ssid = "****";
const char* password = "****";
boolean wifiConnected = false;


void setup()
{
  Serial.begin(115200);
  delay(2000);
  
//  FastLED.addLeds<LED_TYPE, LED_PIN>(leds, NUM_LEDS);
//
  pinMode(LED_PIN, OUTPUT);
  pinMode(RELAY_PIN, OUTPUT);

  digitalWrite(RELAY_PIN, HIGH);
//
//  for (int i = 0; i < NUM_LEDS ; i++) {
//    leds[i] = CRGB(0, 0, 0);
//  }
//  FastLED.show();

  strip.begin();
  strip.show();
  
  wifiConnected = connectWifi();
  
  if(wifiConnected){
    espalexa.addDevice("Lights", colorLightChanged);

    espalexa.begin();
    
  } else
  {
    while (1) {
      Serial.println("Cannot connect to WiFi. Please check data and reset the ESP.");
      delay(2500);
    }
  }
}
 
void loop()
{
   espalexa.loop();
   delay(1);
}

void colorLightChanged(uint8_t brightness, uint32_t rgb) {
  for (int i = 0; i < NUM_LEDS; i++) {
//    leds[i] = CRGB((rgb >> 16) & 0xFF, (rgb >>  8) & 0xFF, rgb & 0xFF);
//    FastLED.setBrightness(brightness);
      strip.setPixelColor(i, (rgb >> 16) & 0xFF, (rgb >>  8) & 0xFF, rgb & 0xFF);
  }
//  FastLED.show();
    strip.show();

  if(brightness == 0) { //lights off
    digitalWrite(RELAY_PIN, LOW);
  }
  else { //lights on
    digitalWrite(RELAY_PIN, HIGH);
  }

//  Serial.print("Brightness: ");
//  Serial.print(brightness);
//  Serial.print(", Red: ");
//  Serial.print((rgb >> 16) & 0xFF); //get red component
//  Serial.print(", Green: ");
//  Serial.print((rgb >>  8) & 0xFF); //get green
//  Serial.print(", Blue: ");
//  Serial.println(rgb & 0xFF); //get blue
}

boolean connectWifi(){
  boolean state = true;
  int i = 0;
  
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.println("");
  Serial.println("Connecting to WiFi");

  Serial.print("Connecting...");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    if (i > 40){
      state = false; break;
    }
    i++;
  }
  Serial.println("");
  if (state){
    Serial.print("Connected to ");
    Serial.println(ssid);
    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());
  }
  else {
    Serial.println("Connection failed.");
  }
  return state;
}

I've tried both Neopixel and FastLED with the same outcomes. Those outcomes are totally wrong colours: This is supposed to be cyan except it's mostly yellow with a bit of blue. This is supposed to be purple And I think you get the idea. The lights strips light up with wrong colours (I've had whats supposed to be gold, be purple), blotches of colours or just make some look really similar (on Alexa, warm white to cool white look almost identical apart from a change in brightness).

I don't know what could be causing this though. I've made sure theres a common ground, I've made sure the pin on the ESP is right (i.e. just a plain output pin with no other fancy stuff), I've tried 2 different libraries and still no luck.

Could anyone help me out?

EDIT: These are these the strips I bought if it helps: https://www.superlightingled.com/65ft20m-roll-ws2811-dc24v-36ledsm-addressable-led-light-strips-digital-full-dream-color-chasing-flexible-led-strips-p-3163.html

6
  • at this point it is unclear if the problem is with alexa, or with the LED strip itself .... remove all of the alexa code ... light the whole strip one color, pause 5 seconds, light whole strip another color , and so on .... start with red, then green, then blue
    – jsotola
    Commented Dec 19, 2020 at 19:06
  • 1
    I tried it without Alexa code and they work perfectly. What confuses me is there is nothing wrong with the RGB values that come from the Alexa. Red comes through as 255 0 0 purple comes through as 171 35 255 and so on. Could it be that the LED libraries don't like being run in a callback? Commented Dec 20, 2020 at 11:01
  • If it's the callback issue, try moving strip.show(); to your loop function. If that too fails, try moving everything into the loop, and have colorLightChanged only store the new values in a global (volatile) variable, that your loop uses.
    – Gerben
    Commented Dec 20, 2020 at 15:50
  • Just tried putting the FastLED code in loop and using a flag to determine when to set the colour. Unfortunately, still doesn't work. My last idea is just to try changing the colour on a different core so espalexa and fastled are totally separate. I'm not hopeful but it's worth a shot Commented Dec 21, 2020 at 9:55
  • why are you using adafruit and fastled at the same time? I don't think that will work. Also, it's much faster to use .fill() instead of setPixelColor if they are all the same color.
    – dandavis
    Commented Dec 21, 2020 at 21:24

1 Answer 1

1

That strip seems to be BGR instead or RGB.

Use NEO_GRB instead in your initializer. So:

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, LED_PIN, NEO_BGR + NEO_KHZ400);
2
  • I'll still try it but would that make a difference to the colours? I didn't mention it (probably should have) but all the primary colours (red, green, blue) show up correctly. If I set the strip to red, it shows red. Commented Dec 20, 2020 at 9:59
  • Giving the new information you provided, this probably won't fix it.
    – Gerben
    Commented Dec 20, 2020 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.