New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fill_rainbow() - Unexpected red pixel #668

Open
Tim-AQ opened this Issue Oct 16, 2018 · 7 comments

Comments

Projects
None yet
2 participants
@Tim-AQ

Tim-AQ commented Oct 16, 2018

I'm using the builtin fill_rainbow function for generating a rainbow spectrum on an LED strip. The issue is, I get a random red pixel midway through the yellow region. I've tried it on 3 different Arduino nano's, and two different LED-strips. Here's the code:

#include <FastLED.h>

#define DATA_PIN 2
#define NUM_LEDS 114
CRGB leds[NUM_LEDS];

uint8_t hue = 0;

void setup() {
  Serial.begin(115200);
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);

  fill_rainbow( leds, NUM_LEDS, hue, 1);
  for(int i=0; i<NUM_LEDS; i++) {
    Serial.print(i);
    Serial.print(' ');
    Serial.print(leds[i].r);
    Serial.print(' ');
    Serial.print(leds[i].g);
    Serial.print(' ');
    Serial.println(leds[i].b);
  }

  CHSV hsv;
  CRGB rgb;
  //rgb = hsv;
}


void loop() {
  fill_rainbow( leds, NUM_LEDS, hue, 1);
  FastLED.show();
}

Here pixel number 60 gets the rgb code 160, 0, 0. When it should have something like 160, 150, 0.

The strangest part of all is that I can get rid of the problem in two ways, either by uncommenting the line rgb = hsv;, or by commenting out the fill_rainbow function in the loop function. Any ideas whats going wrong?

@kriegsman

This comment has been minimized.

Contributor

kriegsman commented Oct 17, 2018

Great bug report, thank you I’ll take a look.

@Tim-AQ

This comment has been minimized.

Tim-AQ commented Oct 17, 2018

Could be worth mentioning that its not always there. Depending on the value of hue it sometimes there and sometimes not. So one pixel (which physical pixel changes, and follows the yellow region of the spectrum) is flickering between red and yellow when the variable hue is slowly increased.

@kriegsman

This comment has been minimized.

Contributor

kriegsman commented Oct 19, 2018

Something funny is going on here.

Sometimes I get 'smooth' color outputs, and sometimes I'm seeing a glitch around hue=60. Making small ("unrelated") changes to the sketch change the results. This looks like a compiler-level issue, which is weird already. (Maybe it's possibly related to ambiguities in the treatment of inline asm? Maybe? Investigating...)

Here's a segment out output showing R G B, and also the delta-R, delta-G, and delta-B between successive hues, when the glitch hits (me).

hue R dR G dG B dB
56 160 0 140 -3 0 0
57 160 0 143 -3 0 0
58 160 0 144 -1 0 0
59 160 0 147 -3 0 0
60 160 0 160 -13 0 0 <-- that's a big jump in G
61 160 0 152 8 0 0 <-- and then G jumps back again
62 160 0 155 -3 0 0
63 160 0 158 -3 0 0
64 160 0 160 -2 0 0

Making any number of small changes to the sketch itself can make this problem go away; the numbers change.

@kriegsman

This comment has been minimized.

Contributor

kriegsman commented Oct 19, 2018

Just rendering the data to show the glitch. It's not a math error per se, and the fact that re-arranging the source code has an effect on it is indicative of a certain kind of problem.

screen shot 2018-10-19 at 12 59 58 pm-colored

@kriegsman kriegsman self-assigned this Oct 19, 2018

@kriegsman

This comment has been minimized.

Contributor

kriegsman commented Oct 19, 2018

Just for my own reference, here's 'my' version of the code which shows a funky value at pixel 60 (aka hue = 60) repeatably, at least on an Leonardo clone, under avr-gcc 5.4.0 (Arduino 1.8.6 hourly build 2018/07/20... which is questionable, but still)

`#include <FastLED.h>

#define DATA_PIN 13
#define NUM_LEDS 114
CRGB leds[NUM_LEDS];

uint8_t hue = 0;

void setup() {
Serial.begin(115200);
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
delay(3000);
}

void loop() {
fill_rainbow( leds, NUM_LEDS, hue, 1);

static bool dump = true;
if( dump) {
dump = false;

for(int i=56; i<65; i++) {
  Serial.print(i);
  Serial.print(' ');
  Serial.print(leds[i].r);
  Serial.print(' ');
  Serial.print(leds[i].g);
  Serial.print(' ');
  Serial.println(leds[i].b);
}

}

FastLED.show();
}
`
Output =

56 160 140 0
57 160 143 0
58 160 144 0
59 160 147 0
60 160 160 0 <-- 'G' is too big here
61 160 152 0
62 160 155 0
63 160 158 0
64 160 160 0

PS I hate github Markdown. I'll get over it.

@kriegsman

This comment has been minimized.

Contributor

kriegsman commented Oct 19, 2018

What version of Arduino are you running, @Tim-AQ, and on what platform?

@Tim-AQ

This comment has been minimized.

Tim-AQ commented Oct 22, 2018

Im using Arduino version 1.8.7 , and the platform is Manjaro Linux.

When the glitch occurs for me, this is the output i get:
hue R G B
58 160 144 0
59 160 147 0
60 160 0 0
61 160 152 0
62 160 155 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment