adafruit / Adafruit_DotStar

GNU General Public License v3.0
97 stars 59 forks source link

Off-by-one error? Last LED is not properly updated on strip.show(); #2

Closed pzich closed 7 years ago

pzich commented 9 years ago

I just recently got a strip of DotStar LEDs, and noticed while programming a strip to flash between two colors that if I set the length to the number of LEDs and periodically called strip.show() with alternating colors, the last LED always seemed to be out of sync. Two workarounds that seemed to work was making the strip an extra LED longer or calling strip.show() twice (as commented below). I've attached a brief example that demonstrates this by toggling the last 5 LEDs in a strip (adjust NUMPIXELS to the strip you use).

#include <Adafruit_DotStar.h>
#include <SPI.h>

#define NUMPIXELS  72 // 73

#define DATAPIN    11
#define CLOCKPIN   13
Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DATAPIN, CLOCKPIN);

void setup() {
  strip.begin();
}

boolean flash = false;

void loop() {
  for(int i = NUMPIXELS-5; i<NUMPIXELS; i++)
    strip.setPixelColor(i, flash ? 0xFF0000 : 0x0000FF);
  strip.show();
  // strip.show();
  delay(500);
  flash = !flash;
}
danielmahon commented 9 years ago

+1

danielmahon commented 9 years ago

typo? NUMPIXELS-5 should be 0 ?

#include <Adafruit_DotStar.h>
#include <SPI.h>

#define NUMPIXELS  72 // 73

#define DATAPIN    11
#define CLOCKPIN   13
Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DATAPIN, CLOCKPIN);

void setup() {
  strip.begin();
}

boolean flash = false;

void loop() {
  for(int i = 0; i<NUMPIXELS; i++)
    strip.setPixelColor(i, flash ? 0xFF0000 : 0x0000FF);
  strip.show();
  // strip.show();
  delay(500);
  flash = !flash;
}
pzich commented 9 years ago

As I say, "demonstrates this by toggling the last 5 LEDs in a strip", depending on the length of the strip and how it's powered, you may not be able to drive the full length of LEDs, but the issue is with the end of the strip.

danielmahon commented 9 years ago

@pzich oops! Im assuming youre still having this issue? Im getting the same result using the Fast LED library as well.

trainman419 commented 9 years ago

I'm seeing similar problems where the last few LEDs on my strip don't update properly unless I call strip.show() twice.

I have about 320 LEDs on my strip, and I'm powering it at both ends, and at two points in the middle.

trainman419 commented 9 years ago

The last few LEDs on my strip work more frequently if I use the hardware SPI mode.

Makuna commented 8 years ago

I have seen where the first few pixels were very noisy (wrong colors); and others beyond sometimes would light poorly; but this turned out to be dodgy IO connection (both a solder joint to the strip, and a alligator clip that was a little corroded) which drove me crazy for a day.

Even with the fix above I am seeing problems where the terminator bytes were showing up at the end of the strip. If I have a physical strip of 30, but I code for only 25, then the 26th LED will light as white.

This is due to the terminator (oxffffffff) is the same as a full white (oxffffffff). So the terminator has no real magic behind it all otherwise a full white pixel earlier in the strip would cause problems.

If you don't send the terminator at all, then it doesn't effect the update of the pixels at all. I continue to see all the pixels get updated AND each pixel visually shows its status when it decodes its own data.

I ran into the link above, but I can't confirm anything it states to be valid and it is not what I see; so either the DotStars have changed (mine are pretty new) or they missed something in their investigation.