Arduino not running full code for WS2812B

Hi,

I am working on a light show with and arduino uno and a ws2812b led strip. Everything was going great until all of a sudden the arduino wouldn't run the full code. It would run the first few lines that were all written in the loop. But when it got to the function section, it would just stop right away and the leds would turn off and not come back on. I re-uploaded the code multiple times and it still would not continue to run the code. In addition I added a test light the would go on for a few seconds at the beginning of the loop. The led would continue to turn on, while the strip just remained blank. I also ran an example code and it worked just fine. I am unsure of what to do at this point and cannot find much online. It is also worth mentioning that I switched the led strip out for a matrix(both WS2812B) and it still would not work. After some time I just gave up and started writing a new code. Until troubles appeared there. It was just a simple program with some for loops and at one point after making an adjustment, I uploaded the code again. Well I tried too, an error message showed up saying the device did not recognize the program/code. After trying a few more times the code uploaded. The code was working for a couple rounds, then the leds just froze on one of the colors. I happened to touch the connector and all of sudden they started working again. sort of. The second for for loop stopped at led #50 or so. I thought it might just be a color un-distinct color difference. So I changed the code and re-uploaded, only to have an error message saying "the selected serial port does not exist or your board is not connected. I double checked the everything and the board was plugged in and it had power, but the computer didn't recognize it. So, I unplugged the board from the computer and plugged it in again and uploaded the code. The code immediately worked, but like before, not for long. I have looked online and have not found anything quite like this so I am trying here. I am fairly new with this and help would be greatly appreciated.

Also, I am using the FastLED library and get this message whenever I upload
"
In file included from C:\Users\xxxxxxx\Documents\Arduino\sketch.ino:1:0:

C:\Users\xxxxxxx\Documents\Arduino\libraries\FastLED.h:14:21: note #pragma message: FastLED version 3.003.001

pragma message "FastLED version 3.003.001"

^~~~~~~~~~~~~~~~~~~~~~
"
Just thought I would add that,

Thanks,
Nick

The message is normal, tells you which version of the FastLED library you're using.

As we can't see your code so it will be very difficult to advise (hint). Just in case, read the sticky "how to use this forum", specifically point #7 about posting code.

How many leds in total? How are they powered? Did you remember the resistor(s) between the strips(s) and the Uno and the capacitor(s) over the strip(s).

What are the memory statistics after compiling, specifically about the dynamic memory available?

The Installation and Troubleshooting section is not for problems with your project :wink: I will ask a moderator to move the thread.

Hi,

There are about 150 leds. I have a resistor in place and the arduino is currently powering the strip while I test things out. I also do not currently have a capacitor over the strip. The message after uploading tells me that the code is only using 4846/32256(15%) of storage space.

Here is my code,

#include<FastLED.h>

#define DataPin 6
#define NumLeds 195
#define Brightness 50
#define LED_Type WS2812B
#define ColorOrder GRB

CRGB leds[NumLeds];

void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
FastLED.addLeds<LED_Type, DataPin, ColorOrder>(leds, NumLeds);
FastLED.setBrightness(Brightness);
}

void loop() {
// put your main code here, to run repeatedly:
fill_solid(&(leds[0]),190,CRGB::Black);
delay(2000);
digitalWrite(13, HIGH);
delay(1000);
fill_solid(&(leds[0]),190, CRGB(225,0,0));
digitalWrite(13, LOW);
FastLED.show();
delay(400);
fill_solid(&(leds[0]),190, CRGB(0,225,0));
FastLED.show();
delay(500);
fill_solid(&(leds[0]),190, CRGB(0,0,225));
FastLED.show();
delay(300);
fill_solid(&(leds[60]),100, CRGB(225,225,225));
fill_solid(&(leds[0]),60, CRGB(0,0,0));
FastLED.show();
delay(500);
fill_solid(&(leds[60]),100, CRGB(0,0,0));
FastLED.show();
Riff();
Riff();
Riff();
Riff();

}
void shw()
{
FastLED.show();
}
void Riff()
{
fill_solid(&(leds[101]),150,CRGB::Black);
fill_solid(&(leds[0]),19,CRGB::White);
shw();
delay(500);
fill_solid(&(leds[0]),19,CRGB::Black);
fill_solid(&(leds[20]),39,CRGB::White);
shw();
delay(500);
fill_solid(&(leds[20]),39,CRGB::Black);
fill_solid(&(leds[40]),59,CRGB::White);
shw();
delay(550);
fill_solid(&(leds[40]),59,CRGB::Black);
fill_solid(&(leds[60]),79,CRGB::White);
shw();
delay(250);
fill_solid(&(leds[60]),79,CRGB::Black);
fill_solid(&(leds[80]),100,CRGB::White);
shw();
delay(400);
fill_solid(&(leds[0]),100,CRGB::Black);//turns all of end of first part of riff
shw();
delay(150);
fill_solid(&(leds[0]),19,CRGB::White);
shw();
delay(250);
fill_solid(&(leds[0]),19,CRGB::Black);
fill_solid(&(leds[20]),39,CRGB::White);
shw();
delay(500);
fill_solid(&(leds[20]),39,CRGB::Black);
fill_solid(&(leds[40]),59,CRGB::White);
shw();
delay(500);
fill_solid(&(leds[40]),59,CRGB::Black);
fill_solid(&(leds[60]),79,CRGB::White);
shw();
delay(250);
fill_solid(&(leds[60]),79,CRGB::Black);
fill_solid(&(leds[80]),99,CRGB::White);
shw();
delay(225);
fill_solid(&(leds[0]),100,CRGB(0,0,0));
FastLED.show();
}

Thanks

You do not need the dereference for the leds array in the fill_solid function, just leds or leds[ 0] should work.

edit: Sorry, I was wrong about that, have not used fill_solid like that much.

You main problem is the first line in riff() that writes to 150 leds starting at leds[101], which exceeds the length of your leds array.

fill_solid(&(leds[0]),190,CRGB::Black);
not a good idee make a function like

void clearScreen(){
  fill_solid(leds,NUM_LEDS,CRGB::Black) ;
  FastLED.show();
  
}

and call it in the loop

here is some cyclon that may interest you as a show

void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { LED[i].nscale8(250); } }

void cyclon(){
  static uint8_t hue = 0;
  // First slide the led in one direction
  for(int i = 0; i < NUM_LEDS; i++) {
    // Set the i'th led to red 
    LED[i] = CHSV(hue++, 255, 255);
    // Show the leds
    FastLED.show(); 
    // now that we've shown the leds, reset the i'th led to black
    // leds[i] = CRGB::Black;
    fadeall();
    // Wait a little bit before we loop around and do it again
    delay(10);
      
  }
  // Now go in the other direction.  
  for(int i = (NUM_LEDS)-1; i >= 0; i--) {
    // Set the i'th led to red 
    LED[i] = CHSV(hue++, 255, 255);
    // Show the leds
    FastLED.show();
    // now that we've shown the leds, reset the i'th led to black
    // leds[i] = CRGB::Black;
    fadeall();
    // Wait a little bit before we loop around and do it again
    delay(10);
  }
}

have fun

bmbbsr:
fill_solid(&(leds[0]),190,CRGB::Black);
not a good idee make a function like

void clearScreen(){

fill_solid(leds,NUM_LEDS,CRGB::Black) ;
  FastLED.show();
 
}




and call it in the loop

FastLED.clear() will accomplist the same thing.

Thanks to you all for the help, I made the changes and the code worked. I greatly appreciate at it.

Thanks,
N. Mersman

here are some more pattern with low coding
try also the fill_gradiend
see the GIF animation i added

  // full DEG CHSV
  float colorstep = 360.0/PIXELS;
  for (int i=0 ; i<PIXELS;i++){
    {leds[i] = CHSV(i*colorstep,255,130);}
  }
  FastLED.show();
  FastLED.delay(MAINDELAY);
  for (int i=0 ; i<PIXELS;i++){
    {leds[i] = CHSV(i,255,130);}
  }
  FastLED.show();
  FastLED.delay(MAINDELAY);
  colorstep = 180.0/PIXELS;
  for (int i=0 ; i<PIXELS;i++){
    {leds[i] = CHSV(i*colorstep,255,130);}
  }
  FastLED.show();
  FastLED.delay(MAINDELAY);

at the FastLED.clear() function you can get trouble if you use ledsets to show patterns like snowflakes
animals or so it will only clear the last pattern not the whole display

NMermsan:
... and the arduino is currently powering the strip while I test things out. ...

Nobody else saw this?

@SteveMann

Yes, but only a few leds are on at a time.