I have been working on a project as a gift for my girlfriend for Christmas which involves some a bunch of standard "white" LEDs controlled by shift registers and darlington arrays, and also some RGB LED strips (WS2812B strip, 29 LEDs on strip). Everything is going fine with the white LEDs, but not so much with the RGB ones.
If I leave the RGB leds running for a while all of the LEDs on the strip turn red, except for the first one, which continues to change color. I am not sure how long "a while" is because in "short term" testing, approximately running continuously for an hour, it works fine and all of the LEDs change appropriately, but if I leave it running overnight I wake up with the issue of all red and one single RGB "working". I then have to reset to get it working again. These RGB LEDSs need to be run for long periods (24 hours) of time without "freezing". The rest of the program (with the normal LEDs) continues to work fine despite the RGB ones not.
Let me explain how I am controlling them. V_rgb
is 5V (5V - 8A power supply), which it is also grounded to. Then the data line, C
, is connected to an Arduino Uno, on pin 12, which is a PWM pin.
In software, I am using a Adafruit Neopixel Library to control the RGB LEDs and write their respective colors, based off the examples given in their git repo and the tutorial here.
I have pasted my code below in case that may help, but honestly I am not sure if it is software or hardware related. (unrelated code has been removed)
#include <Adafruit_NeoPixel.h>
#define rgbPin 11
#define numRGBleds 29
Adafruit_NeoPixel strip = Adafruit_NeoPixel(numRGBleds, rgbPin, NEO_GRB + NEO_KHZ800);
int colorStep = 0;
int rgbIndex = 0;
void shiftColor() {
int i = 0;
for (i = 0; i < numRGBleds; i++) {
int idx = (rgbIndex + i) % numRGBleds;
int colorVal = round(i * colorStep);
strip.setPixelColor(idx, Wheel(colorVal & 255));
}
strip.show();
rgbIndex++;
}
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if (WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} if (WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
void setup()
{
strip.begin();
strip.show();
rgbIndex = 0;
colorStep = 255 / (numRGBleds - 1);
}
void loop()
{
shiftColor();
delay(1000); // Redo every second
}
My thoughts of what it could be are the following, let me know if any make any sense or are known issues:
- Having issues with
micros()
value rollover - Overheating
- Noisy power supply
- Defective LED strip
- black magic?
Thanks in advance for any help.
UPDATE
My current solution to the problem is to just reset the board using the watchdog functionality. It reboots in a few milliseconds and sometimes flashes in the process, but I would like to figure out the real problem.
UPDATE #2
So with the reset solution, I left it running overnight and it did not freeze which leads me to think it is definitely a software, not hardware, issue. I have changed some of the wiring and coding to make sure the watchdog reset is not noticeable. It resets every half hour or so. This will make sure all of the memory is cleaned, except stuff I store in the EEPROM (which I do use to make the reset less noticeable). This reset delays processing by a few milliseconds, but time is not critical, so it is not a big deal.
I still however, would like to know a more elegant way of doing this. The software reset is a bit "hacky"
delay(1000)
todelay(1)
. That way the problem might pop up a lot faster. Also, try changingrgbIndex++;
torgbIndex=(rgbIndex+1)%numRGBleds;
. I thing the problem is theint
rgbIndex
rollover, which occurs after about 9 hours.