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
1 Answer 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);
-
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.DreamingInsanity– DreamingInsanity2020年12月20日 09:59:47 +00:00Commented Dec 20, 2020 at 9:59
-
Giving the new information you provided, this probably won't fix it.Gerben– Gerben2020年12月20日 15:50:53 +00:00Commented Dec 20, 2020 at 15:50
255 0 0
purple comes through as171 35 255
and so on. Could it be that the LED libraries don't like being run in a callback?strip.show();
to yourloop
function. If that too fails, try moving everything into the loop, and havecolorLightChanged
only store the new values in a global (volatile) variable, that your loop uses.