TransWikia.com

NeoPixels do not correctly display when calling strip.show()

Arduino Asked by Bogd on February 27, 2021

I am trying to display some animations on a NeoPixel strip (more precisely, a WS2815 strip), using an ESP8266. For some reason, one of the animations will not display properly.

To give you an idea of the setup – I have a long string of WS2815 strips (4 strips, 300 LEDs each). The strips cross each other, forming loops (called "cycles" in my code). And I am trying to light these "cycles" separately.

In my loop(), I am doing something like this:

 for (uint16_t i = 0; i<loops; i++) {
    
    r = random(256);
    g = max ( 0, (int)(random(256)) - r);
    b = max ( 0, (int)(random(256)) - r - g);
    
    prevcycle = cycle;
    while (cycle == prevcycle) {
      cycle = random(NUM_CYCLES);
    }
    
    cycleSetColor(cycle, r, g, b);
    delay(wait);
    clearStrip();
  }

The actual function looks like this:

void cycleSetColor(uint8_t cycle, uint8_t r, uint8_t g, uint8_t b) {
  for(uint16_t pix=cycle_start[cycle]; pix!=cycle_end[cycle]; pix=cycle_next(cycle, pix)) {
      setPixelColor(pix, r, g, b);  
  }  
  strip.show();
}

Now the behavior is very strange – the only one of the cycles that lights up is the first one (the one that includes LEDs 0 to 300). Whenever I call the function for another cycle (one farther from the starting LED), nothing happens – the whole strip remains blank.

Trying to troubleshoot, I tried the following:

  • called strip.show() every time I set a pixel. Result – all the pixels light up correctly, in sequence:
void cycleSetColor(uint8_t cycle, uint8_t r, uint8_t g, uint8_t b) {
  for(uint16_t pix=cycle_start[cycle]; pix!=cycle_end[cycle]; pix=cycle_next(cycle, pix)) {
      setPixelColor(pix, r, g, b);  
      strip.show();
  }  
  strip.show();
}
  • called strip.show() every X pixels (100, for example). And this is where things get weird – I see the LEDs lighting up to a multiple of 100, but then the last part of the cycle remains blank. It is like strip.show() is called correctly in the loop, but the strip.show() outside the loop never gets called.

For example, if I have a cycle that includes LEDs from 420 to 600, then 730 to 890, I see LEDs lighting up all the way to LED number 800 – but the LEDs from 801 to 890 remain dark.

void cycleSetColor(uint8_t cycle, uint8_t r, uint8_t g, uint8_t b) {
  for(uint16_t pix=cycle_start[cycle]; pix!=cycle_end[cycle]; pix=cycle_next(cycle, pix)) {
      setPixelColor(pix, r, g, b);  
      if (pix%100 == 0) {
        strip.show();  //This one lights the pixels
      }
  }  
  strip.show();  //This one does not?!
}

Of course, if I surround the final call to strip.show() with Serial.println() messages, they are printed to the console – so it does look like the function is called properly. Yet somehow, the results do not show on the strip.

I have to mention that I do have some additional background tasks running (when doing setPixelColor, for example, I make sure every X milliseconds to take care of time-sensitive tasks, like WiFi and MQTT communication). But those should not interfere with strip.show(), which is called directly from the library.

I also have to mention that I can display other animations, including some that light up pixels all the way to the end of the strip, without any issues – so I would say that I managed to solve the power and control voltage issues. It is just this particular function that I cannot get to work.

Can anyone point me in the right direction? Thank you!

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP