Neopixels don't turn on consistently

Hey Everyone,
I made a neopixel powered desk lamp that is controlled by the Blynk app using a Photon. I wrote an app that turns the Neopixels on, but not all LEDs on all rows always turn on. It varies daily. I have checked the wiring and it’s solid.

Here are some pics:

I’m suspecting there is something wrong with how I send data to neopixels, any suggestions?

/* ======================= includes ================================= */
#include "HttpClient/HttpClient.h"
#include "blynk/blynk.h"
#include "clickButton/clickButton.h"
#include "application.h"
#include "neopixel/neopixel.h" // use for Build IDE

void fullWhite();

WidgetLED BlynkLED1(V1); // warmWhite LED on Blynk App.
WidgetLED BlynkLED2(V2); // fullWhite LED on blynk app
WidgetLED BlynkLED3(V4); // allRed LED on blynk app
WidgetLED BlynkLED4(V6); // allBlue LED on blynk app

// the Button
const int buttonPin1 = D3;
ClickButton button1(buttonPin1, HIGH, CLICKBTN_PULLUP);

// Button results
int function = 0;

// IFTTT Functions
int warm(String command);
int white(String command);
int red(String command);
int blue(String command);
int off(String command);

enum {
  LIGHT_OFF,
  WARMWHITE,
  FULLWHITE,
  ALLRED,
  ALLBLUE,
  ALLGREEN,
} state;

SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(SEMI_AUTOMATIC);

// IMPORTANT: Set pixel COUNT, PIN and TYPE
// #define PIXEL_PIN D2
#define PIXEL_COUNT 16
#define PIXEL_TYPE SK6812RGBW
#define BRIGHTNESS 255 // 0 - 255

Adafruit_NeoPixel strips[] = {
  Adafruit_NeoPixel(PIXEL_COUNT, D2, PIXEL_TYPE),
  Adafruit_NeoPixel(PIXEL_COUNT, D1, PIXEL_TYPE),
  Adafruit_NeoPixel(PIXEL_COUNT, D0, PIXEL_TYPE),
};

/* ======================= program ====================== */


void setup() {
  setupButton();
  setupStrips();
  Blynk.begin(auth);
  fullOffBlynkLED();
  Particle.function("Warm", warm);
  Particle.function("White", white);
  Particle.function("Red", red);
  Particle.function("Blue", blue);
  Particle.function("Off", off);
  WiFi.on();
  WiFi.setCredentials("xxxxxx", "xxxxxxx");
}
void setupButton() {
  pinMode(buttonPin1, INPUT_PULLDOWN);
  // Setup button timers (all in milliseconds / ms)
  // (These are default if not set, but changeable for convenience)
  button1.debounceTime   = 20;   // Debounce timer in ms
  button1.multiclickTime = 250;  // Time limit for multi clicks
  button1.longClickTime  = 300; // time until "held-down clicks" register
}

void setupStrips() {
  for (Adafruit_NeoPixel &strip : strips) {
    strip.setBrightness(BRIGHTNESS);
    strip.begin();
    strip.show(); // Initialize all pixels to 'off'
  }
}

BLYNK_WRITE(V0) {
  static int oldParam = 0;
  if (param.asInt() && !oldParam) { // On button press
    togglewarmWhite();
  }
  oldParam = param.asInt();
}

BLYNK_WRITE(V3) {
  static int oldParam = 0;
  if (param.asInt() && !oldParam) { // On button press
    togglefullWhite();
  }
  oldParam = param.asInt();
}

BLYNK_WRITE(V5) {
  static int oldParam = 0;
  if (param.asInt() && !oldParam) { // On button press
    toggleallRed();
  }
  oldParam = param.asInt();
}

BLYNK_WRITE(V7) {
  static int oldParam = 0;
  if (param.asInt() && !oldParam) { // On button press
    toggleallBlue();
  }
  oldParam = param.asInt();
}

BLYNK_WRITE(V9) {
  int r = param[0].asInt();
  int g = param[1].asInt();
  int b = param[2].asInt();
  for (Adafruit_NeoPixel &strip : strips) {
    for (uint16_t i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, strip.Color(g, r, b, 0 ));
    }
    strip.show();
  }
}

BLYNK_WRITE(V10) {

  int pinData = param.asInt();
  if (pinData == 1)
  {
    fullWhite();
    fullWhiteBlynkLED();
    state = FULLWHITE;
  }
  if (pinData == 0)
  {
    fullOff();
    fullOffBlynkLED();
    state = LIGHT_OFF;
  }
}

void loop() {
  Blynk.run();

  // Update button state
  button1.Update();

  // single short or long button click
  if (button1.clicks == 1 || button1.clicks == -1) {
    togglefullWhite();
  }

  if (button1.clicks == 2) {
    togglewarmWhite();
  }

  if (Particle.connected() == false) {
    Particle.connect();
  }
}

void togglewarmWhite() {
  if (state == WARMWHITE) {
    state = LIGHT_OFF;
    fullOff();
    fullOffBlynkLED();
  } else {
    state = WARMWHITE;
    warmWhite();
    warmWhiteBlynkLED();
  }
}

void togglefullWhite() {
  if (state == FULLWHITE) {
    state = LIGHT_OFF;
    fullOff();
    fullOffBlynkLED();
  } else {
    state = FULLWHITE;
    fullWhite();
    fullWhiteBlynkLED();
  }
}

void toggleallRed() {
  if (state == ALLRED) {
    state = LIGHT_OFF;
    fullOff();
    fullOffBlynkLED();
  } else {
    state = ALLRED;
    allRed();
    allRedBlynkLED();
  }
}

void toggleallBlue() {
  if (state == ALLBLUE) {
    state = LIGHT_OFF;
    fullOff();
    fullOffBlynkLED();
  } else {
    state = ALLBLUE;
    allBlue();
    allBlueBlynkLED();
  }
}

@squeakywheel, is there any reason you didn’t wire your neopixels as one string and control everything via a single pin? Do you have enough power? Three rows of 16 pixels at 50ma per pixel (assume 3 pixels) is 2.4 Amps.

Did you know you could create a simple set of text commands that you send to a single Particle.function() which can parse those commands. For example, you could get fancy and send a command like “Warm,Off,30” which would mean “turn on with Warm and go to Off in 30 minutes”. :wink:

1 Like

Also, note this change in the LED lights we call Neopixels.

3 Likes

Hey @peekay123,

No real reason. I actually have 3 strips of neopixels so it was just simpler to wire each data wire to a digital pin. Do you think that is the cause for inconsistent operation?

Do you have enough power? Three rows of 16 pixels at 50ma per pixel (assume 3 pixels) is 2.4 Amps.

Yup, running it with a 12V, 5A power supply. Went through the same calculation.

I am super interested in code improvements. That would be amazing! What would I need to change?

Thanks! I bought the LEDs last year so I think I am safe.

Might be. The neopixel library is bit-banged and timing is critical. You may be better off using a single strand by connecting them in series.

If you search the forum for “command parsing” you will find a lot of examples.