Page 1 of 1

How to avoid initial flashing of common anode RGB LED

Posted: Sun Jan 12, 2020 9:13 pm
by bittailor
Hi

I try to control a common anode RGB LED with ledc functions. My problem is a short initial white flash off the RGB LED on the first boot.
How could I avoid this initial white flash?

Interestingly the initial white flash does not happen after an ESP.restart(); but after it happens after a ESP.deepSleep(2000);

Minimal code:

Code: Select all

#include <Arduino.h>

uint8_t ledR = 33;
uint8_t ledG = 32;
uint8_t ledB = 22; 

void setup() {
   ledcAttachPin(ledR, 1);
   ledcAttachPin(ledG, 2);
   ledcAttachPin(ledB, 3);
   ledcSetup(1, 12000, 8);
   ledcSetup(2, 12000, 8);
   ledcSetup(3, 12000, 8);
   ledcWrite(1, 256);
   ledcWrite(2, 256);
   ledcWrite(3, 256);
   delay(1000);
}

void loop(){
   ledcWrite(1, 100);
   ledcWrite(2, 100);
   ledcWrite(3, 256);
   delay(1000);
   ledcWrite(1, 50);
   ledcWrite(2, 150);
   ledcWrite(3, 150);
   delay(1000);
   ESP.restart();
   //ESP.deepSleep(2000);
}
I already tried to set the pins to HIGH before the call to ledcSetup but this did not remove the short white flash.

Code: Select all

  
   // ... 
   digitalWrite(22, HIGH);
   digitalWrite(32, HIGH);
   digitalWrite(33, HIGH);
   ledcAttachPin(ledR, 1);
   ledcAttachPin(ledG, 2);
   ledcAttachPin(ledB, 3);
   ledcSetup(1, 12000, 8);
   ledcSetup(2, 12000, 8);
   ledcSetup(3, 12000, 8);
   // ...  
I would appreciate any suggestion on how to avoid this initial white flash.

Thanks

Re: How to avoid initial flashing of common anode RGB LED

Posted: Tue Jan 14, 2020 1:53 am
by dotbot
Can you describe the circuit you are using a bit more, are you using a pull up resistor on the cathode of the LEDs?
Are you sinking the LED current through the GPIO Pins?
Any chance you have a scope and can measure the voltage of the GPIO durring the reset where the flash happens?
I'm not sure what the issue is but my thinking would be to determine if this is a software or hardware issue first.

Re: How to avoid initial flashing of common anode RGB LED

Posted: Tue Jan 14, 2020 9:37 pm
by bittailor
This is the circuit I'm using:
Screenshot 2020-01-14 at 22.20.50.png
Screenshot 2020-01-14 at 22.20.50.png (54.94 KiB) Viewed 5072 times
When I add a logic analyser an an additional output 19 ( as Logic 3) as trigger

Code: Select all

   pinMode(19, OUTPUT);
   digitalWrite(19, HIGH);
   ledcAttachPin(ledR, 1);
   ledcAttachPin(ledG, 2);
   ledcAttachPin(ledB, 3);
   ledcSetup(1, 12000, 8);
   ledcSetup(2, 12000, 8);
   ledcSetup(3, 12000, 8);
   ledcWrite(1, 256);
   ledcWrite(2, 256);
   ledcWrite(3, 256);
   digitalWrite(19, LOW);
   delay(1000);
I see that all three outputs ( Logic 0-2) go low for ~8ms after a ESP.deepSleep(2000);:
Screenshot 2020-01-14 at 22.26.04.png
Screenshot 2020-01-14 at 22.26.04.png (63.94 KiB) Viewed 5072 times
Also after a ESP.restart(); the outputs go low put at different times and for different lenghts:
Screenshot 2020-01-14 at 22.29.45.png
Screenshot 2020-01-14 at 22.29.45.png (59.78 KiB) Viewed 5072 times

Re: How to avoid initial flashing of common anode RGB LED

Posted: Wed Jan 15, 2020 3:33 am
by dotbot
This might do the trick

https://docs.espressif.com/projects/esp ... /gpio.html
"
void gpio_deep_sleep_hold_en(void)
Enable all digital gpio pad hold function during Deep-sleep.

When the chip is in Deep-sleep mode, all digital gpio will hold the state before sleep, and when the chip is woken up, the status of digital gpio will not be held. Note that the pad hold feature only works when the chip is in Deep-sleep mode, when not in sleep mode, the digital gpio state can be changed even you have called this function.

Power down or call gpio_hold_dis will disable this function, otherwise, the digital gpio hold feature works as long as the chip enter Deep-sleep.
"

Havn't tried it myself but its discription does sounds like what your looking for