Hi, your library is really helping! Such a great job.

Hi, your library is really helping! Such a great job. I am trying now to send some data via serial, 8 parameters. This will be used to display some levels of different sensors.
Everything seems to be working fine, but if I include FastLED.show(); it begins to lose packages, and the communication becomes patchy.
This is my code, I wonder if you could recommend another way of doing this?

byte values[8];

#include “FastLED.h” // FastLED library. Preferably the latest copy of FastLED 2.1.

#if FASTLED_VERSION < 3001000 // This guarantees the person will have to use FastLED 3.1
#error “Requires FastLED 3.1 or later; check github for latest code.”
#endif

// Fixed definitions cannot change on the fly.
#define LED_DT 6 // Data pin to connect to the strip.
#define COLOR_ORDER GRB // Use BGR for APA102 and GRB for WS2812
#define LED_TYPE WS2812B // Or WS2812. Don’t forget to change the FastLED.addLeds line as well.
#define NUM_LEDS 120 // Number of LED’s.

// Initialize changeable global variables.
uint8_t max_bright = 64; // Overall brightness definition.

struct CRGB leds[NUM_LEDS]; // Initialize our LED array.

void setup() {
Serial.begin(9600);
Serial1.begin(9600);

FastLED.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS);        // Use this for WS2812B

FastLED.setBrightness(max_bright);          

}

void loop() {

while (Serial1.available() > 0) {

 if (Serial1.read() == 80) {
 delay(5);
 
   if (Serial1.read() == 80) {
     delay(5);
     
     for (int i=0; i<8 ;i++){
        
       if (Serial1.available() > 0) {   
   
           values[i]=  Serial1.read();

           delay(5);
            
        }
     }
     
   for (int i=0; i<8 ;i++)  {  

     Serial.println( values[i]);
     delay(2);
      }  
 
    Serial.println("/////////////////////////////");
    delay(2);
   }
  } 
 }

values[2] = map(values[2],0,250,0,NUM_LEDS);
leds[values[2]] = CRGB::White;
fadeToBlackBy( leds, NUM_LEDS, 20); //all leds which have not been turned on specifically
FastLED.show();
}

I am using an Arduino Mega and a ws2812B led strip

This is a thing that comes up often enough that I’ve just written up a wiki page for it - https://github.com/FastLED/FastLED/wiki/Interrupt-problems

But the short version is - you are losing data because interrupts are being disabled while LED data is being written out. That wiki page has some more discussion about what’s going on, and some ways to work around it.

Thank you so much, Daniel!

After reading your wiki entry, I am trying with the data request and the flushing serial strategy. Despite this, there are still several packages with rong lectures.
I read that each LED takes a time to update, so, would it be possible to stick a delay function ater the FastLED.show() that would give some time to the strip to update?

No, I think you’re misunderstanding things. The flushing alone isn’t enough. You need the flushing and a reliable way to identify the beginning of a new set of values - which you don’t have.

The delay in updating LED is the writing of LED data, which is what FastLED.show does, during which time interrupts are disabled.

I’d need to see what your code currently looks like to comment more on what’s happening to it - post a copy of it up to git (posting code in g+ comments is a nightmare to read/follow through, especially on phones).

I suspect one other source of problem could be - can you guarantee that you are never sending two 80’s in a row as part of “normal” data? Because if not, you may also be throwing off your own packet reading.