Skip to content
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

Wrong color on first pixel with ESP32 #159

Closed
AMoo-Miki opened this issue Feb 7, 2018 · 27 comments · Fixed by #253
Closed

Wrong color on first pixel with ESP32 #159

AMoo-Miki opened this issue Feb 7, 2018 · 27 comments · Fixed by #253

Comments

@AMoo-Miki
Copy link

  • Arduino board: HUZZAH32 (ESP32)

  • IDE version: platformio 3.5.2a7

I have 2 pixels (Breadboard-friendly RGB Smart NeoPixel) connected in series to the ESP32. No matter what I do, the first led (pixel 0) is green, and if I set a color to it, it shows up different.

I switched the LEDs physically and still pixel 0 is green. FastLED, however, doesn't have this problem and shows the colors correctly.

I have tried with the latest code from this library, as well as with 1.1.3 and 1.1.4 and have the same problem.

#include <Adafruit_NeoPixel.h>

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(2, 21, NEO_GRB + NEO_KHZ800);

void setup() {
  pixels.begin();
  pixels.setPixelColor(0, pixels.Color(0, 0, 0));
  pixels.setPixelColor(1, pixels.Color(0, 0, 0));
  delay(10);
  pixels.show();
}

void loop() {}
@sansillusion
Copy link

Did you get your pixels together ? Some pixels are RGB some are GRB.

@AMoo-Miki
Copy link
Author

AMoo-Miki commented Feb 10, 2018

Yeah. The 2 pixels are from the same "board". Also, whether I set the LEDs as A-B or B-A, which ever is 0, lights up green for (0, 0, 0).

@lyusupov
Copy link

lyusupov commented Feb 10, 2018

I can also confirm the issue for ESP32 - one green pixel.
The same code works fine on ESP8266.

@lyusupov
Copy link

lyusupov commented Feb 10, 2018

It works Ok to me, although it may not completely fix AMoo-Miki's original issue.

index e316ee7..04188f0 100644
--- a/software/firmware/source/libraries/Adafruit_NeoPixel/esp8266.c
+++ b/software/firmware/source/libraries/Adafruit_NeoPixel/esp8266.c
@@ -61,14 +61,14 @@ void espShow(
 #ifdef ESP8266
     GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinMask);       // Set high
 #else
-    gpio_set_level(pin, HIGH);
+    GPIO.out_w1ts = pinMask;
 #endif
     startTime = c;                                        // Save start time
     while(((c = _getCycleCount()) - startTime) < t);      // Wait high duration
 #ifdef ESP8266
     GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinMask);       // Set low
 #else
-    gpio_set_level(pin, LOW);
+    GPIO.out_w1tc = pinMask;
 #endif
     if(!(mask >>= 1)) {                                   // Next bit/byte
       if(p >= end) break;

@AMoo-Miki
Copy link
Author

@lyusupov, your change does make the first pixel go off for (0, 0, 0), but the first pixel still gets the wrong colors. For example (171, 0, 85), which is pink, shows up as white.

@AMoo-Miki AMoo-Miki changed the title Wron color on first pixel with ESP32 Wrong color on first pixel with ESP32 Feb 23, 2018
@KilianB
Copy link

KilianB commented Mar 1, 2018

I encounter the same issue occasionally (rarely and not reproducible) using an esp8266 as well. Afterwards setting the color of individual pixel will overwrite the first green pixel just fine.
I faced the issue a lot more severe when I tried to run the led strip without level shifting the data signal from the esp. Are you converting the output to the correct voltage range?

@tueddy
Copy link

tueddy commented Mar 1, 2018

I have replaced the library with https://github.com/Makuna/NeoPixelBus.git
Without any hardware changes the neopixel works fine on my ESP-32 device

@xvinny-zz
Copy link

I have replaced the library with https://github.com/Makuna/NeoPixelBus.git
Without any hardware changes the neopixel works fine on my ESP-32 device

I liked the source code of this library. It is very robust and well done.
I'm gonna test it, because the SmartLeds library is causing me problems.

@boonkey
Copy link

boonkey commented Jul 22, 2019

I also got this issue with NodeMCU ESP-WROOM-32 and Adafruit 8x8 RGB matrix.
for me, every time I use the show() method, I get different corruptions. the first corruption is always green on led #0, but after that it's a random corruption.

this issue is also the same for my NodeMCU ESP8266 V1.0 (ESP-12E)

@xVinny @tueddy your suggested library looks good, but I'm looking for one which can print ASCII strings, have you any recommendation for that? Thanks.

Example for code with corruption:
Setup:
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(8, 8, 1, 1, 33, NEO_MATRIX_TOP + NEO_MATRIX_RIGHT + NEO_TILE_TOP + NEO_TILE_RIGHT + NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG + NEO_KHZ800 + NEO_GRB); matrix.begin(); matrix.setTextWrap(false); matrix.setBrightness(50);

Loop:
i = (i + 1) % 10; Serial.println(i); matrix.fillScreen(0); matrix.setCursor(2,0); matrix.print(i); matrix.show(); delay(100);

@tttonyyy
Copy link

Might not be software/timing at all. I have first pixel go green but it's from noise on the DIN signal - I don't even need the ESP connected, can just touch the DIN with a finger and that's enough noise to make the first LED go green. So you may find it was programmed correctly but noise flips it to green quite quickly.

I think this is why they recommend 470R series resistor on DIN (close to the neopixel end) and potentially 100k pulldown to GND (again at the neopixel end) to reduce signal noise.

@AMoo-Miki
Copy link
Author

@tttonyyy, that might not be the case with me though since switching to another library (without any physical change, not even movement) made it work fine.

@nevada750club
Copy link

nevada750club commented Jan 25, 2020

I have found a good solution: in my code I call "show()" twice and the problem is solved 99,9% for me (without this solution the first led wrong color always).
I hope this solution solve your problem also.
Let me know ;-)

example:
for (int i=0; i<NUMLEDS; i++) { leds.setPixelColor(i, iColor); } leds.show(); leds.show();

@acturcato
Copy link

There is a "known timing problem" between Neopixel and ESP32.
See the comment of Mike (Adafruit Support) on:
https://forums.adafruit.com/viewtopic.php?f=24&t=137339

In my case, I have replaced the library with https://github.com/Makuna/NeoPixelBus.git
Without any hardware changes, my Neopixel Ring (24 leds) works fine on my ESP-32 device!!!

@Giotoc
Copy link

Giotoc commented Mar 6, 2020

I had the same problem with a NodeMCU-43S and a single pixel. I had the problem only when I tried to switch off the pixel with pixels.setPixelColor(0, pixels.Color(0,0,0)); all other values were working correctly.
The "workaround" to duplicate pixels.show() works for me, I am not going to change the library for now

@XFactHD
Copy link

XFactHD commented Mar 25, 2020

I am having the same problem with the builtin pixel on the Adafruit Feather M4 Express.
The color is always wrong when calling setPixelColor() and show() or clear() and show() directly after calling begin().
The "fix" to duplicate pixel.show() works for me as well. Another solution I found is to add a delay of at least 40 microseconds between begin() and show().

@hznupeter
Copy link

The "fix" to duplicate pixel.show() works for me as well.

@dr2okevin
Copy link

I Have the same Problem. duplicate pixel.show() works only half. The Pixel gets green and ~100ms later goes off. Using some animations that means a constant green flashing first pixel.

@chinloon
Copy link

Mine seems to give problem when I use with pubsubclient.h. Double show() gets the colour to be correct but get a flash of bright Green occasionally first.

@lifankohome
Copy link

How to solve this problem? what's the reason of first light flashing green?

@luiscamaral
Copy link

I am facing the same issue. Not sure how to solve it yet., and double call to pixel.show() during an animation didn't help much but to cause some flickering.
I notice that if I disable Wifi (WiFi.disconnect()) the issue is gone. So, I am suspecting it is a timing issue with the library.

@lifankohome
Copy link

lifankohome commented Sep 22, 2020

I knew the reason: the first pulse is wrong.
I try to control the led with a stm32f1xx using PWM with DMA, but same problem oocured, every led is good but the first blink green sometime. I check the time sequence found that first high pulse is too long and low pulse is too short. So i deleted all PWM code and replaced with delay funciton, everything goes well. Here is my time sequence with delay function:
https://gitee.com/lifanko/Car/raw/delay/timeline.png
And you guys could get all the code at https://gitee.com/lifanko/Car/tree/delay/

@luiscamaral
Copy link

I've confirmed on the oscilloscope today and you're right. When I turn-on the WiFi on the ESP-WROOM-32, for some reason the first pulse go wrong and kind of mess with everything after it. I am not sure if we can use timed interruption to modulate pulses in ESP32, but it might be a good implementation if it actually works.

Looks like the current implementation for ESP32 is using CycleCounter register like bellow:
__asm__ __volatile__("rsr %0,ccount":"=a" (ccount));

Any suggestions on how to better debug/fix this?

@lifankohome
Copy link

Maybe we should focus on why only the first pulse has problem.
why disable WiFi could make first pulse be normal, first pulse is the most impossible to be influenced.

@luiscamaral
Copy link

luiscamaral commented Sep 24, 2020

Screen Shot 2020-09-23 at 8 17 26 PM

I agree. Probably they are different issues as I am still getting first LED with green color after a few tries.
I can see the short pulse on the logic analyzer, but still it (the LA) can decode the LED correctly.

On the image we can see a sequence of 16 LEDs signals sent to the first LED (1) and what the second LED get from the first (0).

@tablatronix
Copy link
Contributor

Same problem, there is a timing issue with the first bit first pixel, everytime, this is not a random interrupt.
Seems to happen in certain instances, cannot narrow down what execution is causing it.

IMG_7773

@tablatronix
Copy link
Contributor

Ok so I figured I can skew the start bit, so that whatever is wrong with getCycleCount is done, then the first bit might send correctly.

I delayed it half 1.5 periods

    while(((c = _getCycleCount()) - startTime) < period*1.5); // Wait for bit start (EXTRA WAIT)

Seems to be working for now, this might also explain why calling delay(1) before show(); fixes other interrupt issues

@ladyada
Copy link
Member

ladyada commented Oct 30, 2020

plesae try #253

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.