Skip to content

nRF52 - First call to showPixels() with neopixel results in wrong color #856

Closed

Description

@henrygab

Reported via #840

Repro is trivial:

#define FASTLED_INTERNAL
#include <FastLED.h>
#define NUM_LEDS 80
CRGB leds[NUM_LEDS];
// LED_RED      for built-in red LED   == 3
// LED_BLUE     for built-in blue LED  == 4
// PIN_NEOPIXEL for built-in NEOPIXEL  == 8
void setup() {
  delay(2000);
  pinMode(PIN_NEOPIXEL, OUTPUT);
  pinMode(LED_RED,      OUTPUT);
  pinMode(LED_BLUE,     OUTPUT);
  FastLED.addLeds<NEOPIXEL, PIN_NEOPIXEL>(leds, NUM_LEDS);
  FastLED.setBrightness(10);
  fill_solid(leds, NUM_LEDS, CRGB::Blue);
  FastLED.show();
}

void loop() {
//  static int i = 0;
//  for (int j = 0; j < 0x200; j++) {
//    fill_solid(leds, NUM_LEDS, CRGB::Blue);
//    FastLED.show();
//    fill_solid(leds, NUM_LEDS, CRGB::Red);
//    FastLED.show();
//  }
//  i++;
//  digitalWrite(LED_RED, (i % 2) ? HIGH : LOW); // blink LED
}

Activity

  1. henrygab commented on Aug 10, 2019

    @henrygab
    ContributorAuthor

    @masonevans -- Would be willing to validate a potential fix for #856 (first LED wrong color first time only)? See
    henrygab@ded19a5.

    The potential fix is to add the following four lines (two of which are comments) to file platforms/arm/nrf52/clockless_arm_nrf52.h at function init():

        // to avoid pin initialization from causing first LED to have invalid color,
        // call mWait.mark() to ensure data latches before color data gets sent.
        startPwmPlayback_InitializePinState();
        mWait.mark();

    While I couldn't get my scope connected to pin 8 to prove the cause,
    it appears to prevent any the first LED color issue, without affecting
    later calls to showPixels().

    Can you please let me know, whether you don't test it, or the results you get when testing it?

    Thanks!

  2. henrygab commented on Aug 10, 2019

    @henrygab
    ContributorAuthor

    OK, I confirmed this is caused by a lack of setting the pin to the proper state at startup.

    You can fix this in your sketch by ensuring (for non-inverted chipsets) that you set the pin

      digitalWrite(PIN_NEOPIXEL, LOW);
      delay(100);

    I will also push the preventative measure above.

  3. masonevans commented on Aug 12, 2019

    @masonevans

    @henrygab thanks for the update on this one, I am out of town until Friday but I will check on this fix when I get back home

  4. added a commit that references this issue on Aug 13, 2019
    4432597
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions