issue with DemoReel100 example code for WS2812

I am trying to use and modify the DemoReel100 code for a 300LED 60/m LED strip. The strip works, but something in the code doesnt. It does the first rainbow runs then the glitteri, but then seems to get stuck on the rainbow and flicker a bit, but not advance onto the next patterns., it won’t advance to the next pattern. No idea what’s wrong, no error codes, and I have not modified it in any way from its original state in the example. Not sure what to modify to perhaps shorten the rainbow sequence from taking so long with 300 LED’s or what is wrong in my code. Any assistance in sorting my problem or shortening the rainbow sequence for all 300 LEDs might work. See my exact code below, though I am positive its just the example code from DemoReel100

#include <FastLED.h>

FASTLED_USING_NAMESPACE

// FastLED “100-lines-of-code” demo reel, showing just a few
// of the kinds of animation patterns you can quickly and easily
// compose using FastLED.
//
// This example also shows one easy way to define multiple
// animations patterns and have them automatically rotate.
//
// -Mark Kriegsman, December 2014

#if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000)
#warning “Requires FastLED 3.1 or later; check github for latest code.”
#endif

#define DATA_PIN 7
//#define CLK_PIN 3
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define NUM_LEDS 300
CRGB leds[NUM_LEDS];

#define BRIGHTNESS 80
#define FRAMES_PER_SECOND 120

void setup() {
delay(3000); // 3 second delay for recovery

// tell FastLED about the LED strip configuration
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
//FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);

// set master brightness control
FastLED.setBrightness(BRIGHTNESS);
}

// List of patterns to cycle through. Each is defined as a separate function below.
typedef void (*SimplePatternList)();
SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm };

uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
uint8_t gHue = 0; // rotating “base color” used by many of the patterns

void loop()
{
// Call the current pattern function once, updating the ‘leds’ array
gPatternsgCurrentPatternNumber;

// send the ‘leds’ array out to the actual LED strip
FastLED.show();
// insert a delay to keep the framerate modest
FastLED.delay(1000/FRAMES_PER_SECOND);

// do some periodic updates
EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the “base color” through the rainbow
EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
}

#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))

void nextPattern()
{
// add one to the current pattern number, and wrap around at the end
gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
}

void rainbow()
{
// FastLED’s built-in rainbow generator
fill_rainbow( leds, NUM_LEDS, gHue, 7);
}

void rainbowWithGlitter()
{
// built-in FastLED rainbow, plus some random sparkly glitter
rainbow();
addGlitter(80);
}

void addGlitter( fract8 chanceOfGlitter)
{
if( random8() < chanceOfGlitter) {
leds[ random16(NUM_LEDS) ] += CRGB::White;
}
}

void confetti()
{
// random colored speckles that blink in and fade smoothly
fadeToBlackBy( leds, NUM_LEDS, 10);
int pos = random16(NUM_LEDS);
leds[pos] += CHSV( gHue + random8(64), 200, 255);
}

void sinelon()
{
// a colored dot sweeping back and forth, with fading trails
fadeToBlackBy( leds, NUM_LEDS, 20);
int pos = beatsin16( 13, 0, NUM_LEDS-1 );
leds[pos] += CHSV( gHue, 255, 192);
}

void bpm()
{
// colored stripes pulsing at a defined Beats-Per-Minute (BPM)
uint8_t BeatsPerMinute = 62;
CRGBPalette16 palette = PartyColors_p;
uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
for( int i = 0; i < NUM_LEDS; i++) { //9948
leds = ColorFromPalette(palette, gHue+(i2), beat-gHue+(i10));

  • }*
    }
    void juggle() {
  • // eight colored dots, weaving in and out of sync with each other*
  • fadeToBlackBy( leds, NUM_LEDS, 20);*
  • byte dothue = 0;*
  • for( int i = 0; i < 8; i++) {*
  • leds[beatsin16( i+7, 0, NUM_LEDS-1 )] |= CHSV(dothue, 200, 255);*
  • dothue += 32;*
  • }*
    }

I tried the exact same code with only 100 of the LEDs active instead of 300 for NUMBER OF LEDS, and that worked fine, why won't it work when I change 100 to 300 LED's at the top of the code.

why won't it work when I change 100 to 300 LED's at the top of the code.

For the same reason you can't put a size 45 foot in a size 8 shoe.

Have you tried reducing FRAMES_PER_SECOND to a lower value? At 120 frames/second you may not have enough time to actually update all the LEDs each frame.

JekyllandHyde:
I am trying to use and modify the DemoReel100 code for a 300LED 60/m LED strip.

No idea what's wrong, no error codes, and I have not modified it in any way from its original state in the example.

I don't know how to reconcile those two statements.

I just meant that I was playing around with the DemoReel100 code, trying patterns and all that, but I just wanted to get the whole string to run, and haven’t been able to do so, with the original example code from the arduino program or any modification. Using the original example with no modification, it works with the shorter string (<100 LEDs), but using the whole 300 doesnt work.

PaulS:
For the same reason you can't put a size 45 foot in a size 8 shoe.

Well thanks for that statement, but can you offer a fix?

It doesn't seem to me that you've expended very much effort in debugging this yourself. It looks like: "100 LEDs Work", "300 LEDs Don't Work", "Ask for Help - and improperly post code without Code Tags".

What have you done to investigate the problem? If it were my project I'd start trying things like:

  • Strategically placed debug prints to get a better idea of where and when the code is going astray.

  • Gradually increase the LED count from 100 rather than jumping straight to 300. Maybe you'll find a sharp threshold where it breaks. That would be interesting information.

  • Modify the code to only run one of the patterns continuously instead of cycling through them all. Maybe that will show something.

  • I've never used the FastLED.delay(),EVERY_N_MILLISECONDS(), and EVERY_N_SECONDS() functions, so I'm not familiar with how they work at a very detailed level. But, maybe you could try replacing all of them with a millis()-based state machine approach. That might give you better control of the program's timing -- in case the problem is timing-related.

On the hardware side:

  • How are you providing 5 VDC to the LEDs? Does your power supply have enough current capacity and bypassing to power 300 LEDs? Maybe you need to double end feed power to the LED strip.

  • You didn't bother to tell us why type of board you're using. Is it a 3.3V processor? If so, do you have a proper level shifter (like a 74AHCT125) in the data line. Don't try to use a bidirectional shifter meant for I2C, it probably won't be fast enough.

I have tried both an arduino uno and mega, and am using a 5v 20a power supply for my LED strip along with a 4.5v battery pack for the arduino. though technically Im only using 80/255 brighteness and not using any white colored lights, so its never getting close to 60ma per LED. I have tried the code and the problem is the rainbow part. it does the rainbow and rainbow with glitter first two pattern steps but then freezes on a rainbow thing, and flickers, but does not continue to any of the runs or flashing patterns that are listed after it in the sequence. If I remove the rainbow part, the first two patterns, it works perfectly fine too.I want the whole code to run, all the patterns. Tweaking the values of the patterns makes no difference I can see.

I did some testing with increments above 100 LEDs, I did 200, 150, and 125, but none work. at all those, it starts with a rainbow pattern as indicated in the code, but it stays on that maybe a second before switching to a reddish and green alternating thing, maybe 20 LEDs red then 20 green, you get the idea. No idea how that managed to happen. Only 100 seems to work flawlessly

What about 99 LEDs? What about 101? What do your Serial debug prints tell you?

JekyllandHyde:
though technically Im only using 80/255 brighteness and not using any white colored lights, so its never getting close to 60ma per LED.

Just to verify, are you using RGB or RGBW LEDs?

JekyllandHyde:
Well thanks for that statement, but can you offer a fix?

Yes. Order some more memory for your Arduino. Don't forget the micro-soldering iron needed to install it.