Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Why On startup LED1(connceted at GPIO-0) ONCE gets blink at ESP-01 module

Status
Not open for further replies.

dattlara76

Junior Member level 2
Joined
Mar 1, 2019
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
291
Hi,
On startup ESP-01 MODULE, the LED1 connected at PIN GPIO-0 gets ONCE blink even writing HIGH
Code:
digitalWrite(BUTTON,HIGH); //  Have to write this pin high before entering the void loop otherwise this pin will be grounded
in void setup().
After that the code is working as expected (Button press LED1 OFF and release LED1 ON.

My question is why LED1 goes ONCE blink at POWER on the ESP-01. and how to resolve this issue? CKT.jpg
Code:
const int BUTTON=2;
const int LED=0  ;
int BUTTONState=0;
void setup() {
  // put your setup code here, to run once:
//delay(1000);
pinMode(LED,OUTPUT);
pinMode(BUTTON,INPUT);
digitalWrite(BUTTON,HIGH); //  Have to write this pin high before entering the void loop otherwise this pin will be grounded
}

void loop() {
  // put your main code here, to run repeatedly:
BUTTONState=digitalRead(BUTTON);
if(BUTTONState==HIGH)
{
  digitalWrite(LED,HIGH);
}
else
{
  digitalWrite(LED,LOW);
}
}

Please suggest??

Tnx.
 

Aussie Susan

Advanced Member level 4
Joined
Jan 5, 2015
Messages
1,331
Helped
387
Reputation
774
Reaction score
396
Trophy points
83
Activity points
14,375
Don't forget that those devices go through their own startup processes (i.e. checking for boot/programming options) before they move on to your code.
My guess (and it is nothing more than that) is that it might be testing GPIO-0 to see if it should go into the bootloader mode. With the LED and resistor to ground, I would have thought the pin might be read as 'low' which puts it into bootloader mode (high makes it go straight to your program). After that it might be trying to talk to the boot loader and then , when nothing comes back, go on to your program.
As I said - just a guess.....
Susan
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
15,198
Helped
4,955
Reputation
9,932
Reaction score
4,779
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
129,081
For the first 50mS or so after power is applied, the IO0 pin is used by the internal bootloader to see if it should enter programming mode or normal mode, this could be the reason for your flash. The pin is internally pulled high by default so it doesn't accidentally go into programming mode and this could account for your LED current.

A possible solution is to 'reverse' the logic, connect the LED and resistor between +3.3V and IO0 then in your program swap the digitalWrite() instructions over.

Brian.

(Sorry Susan, I cross posted! - but great minds think alike!)
 

dattlara76

Junior Member level 2
Joined
Mar 1, 2019
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
291
No Improvement!!On startup LED1(connceted at GPIO-0) ONCE gets blink at ESP-01 module

Thks all of you..
A possible solution is to 'reverse' the logic, connect the LED and resistor between +3.3V and IO0 then in your program swap the digitalWrite() instructions over.
According to you, I implemented with ckt and code as attached here, but NO Improvement is found.
Code:
const int BUTTON=2;
const int LED=0  ;
int BUTTONState=0;

void setup() {
  pinMode(BUTTON,INPUT);
  digitalWrite(BUTTON,HIGH); //  Have to write this pin high before entering the void loop otherwise this pin will be grounded
  //pinMode(LED,OUTPUT);
}

void loop() {
  BUTTONState=digitalRead(BUTTON);
  if(BUTTONState==HIGH)
    {
    digitalWrite(LED,LOW);//Active low, LED Turn On
    }
  else
    {
    digitalWrite(LED,HIGH);//Active low, LED Turn OFF
    }
}
CKT-UPDATE.jpg

Please suggest, is there any others to be done in code as well as h/w ckt to resolve the blink once at startup?
thx
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
49,116
Helped
14,378
Reputation
29,020
Reaction score
13,129
Trophy points
1,393
Location
Bochum, Germany
Activity points
283,145
The question can't be answered without knowing the internal register and library details, also how pins are initialized by the run time library.

With many microcontrollers, we would first write the intended output state and then enable the output.
 

andre_luis

Super Moderator
Staff member
Joined
Nov 7, 2006
Messages
9,307
Helped
1,165
Reputation
2,349
Reaction score
1,152
Trophy points
1,403
Location
Brazil
Activity points
54,219
Why did you remove LED pin config from your code?
It is not supposed to blink any time:

Code:
  //pinMode(LED,OUTPUT);
 

dattlara76

Junior Member level 2
Joined
Mar 1, 2019
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
291
It got commented during the copy past of code here.
 

Aussie Susan

Advanced Member level 4
Joined
Jan 5, 2015
Messages
1,331
Helped
387
Reputation
774
Reaction score
396
Trophy points
83
Activity points
14,375
If, as @betwixt and I surmise, the flash is due to the initial bootstrap code that is triggered after power on, then i has nothing to do with your code.
The bootstrap code we are talking about is run immediately after power is applied (or other resets) but BEFORE your code is run.
Susan
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
15,198
Helped
4,955
Reputation
9,932
Reaction score
4,779
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
129,081
I haven't checked but it is also possible the pin carries a short burst of serial information. When the ESP8266 powers up it sends a list of configuration settings to it's serial pins but also to some other pins too. Possibly IO0 has that data on it immediately after booting.

I've got four ESP32s and one ESP8266 in front of me right now, all talking to each other through an MQTT broker (a Raspberry Pi), I'm still developing software so I can't stop to do tests right now but I will try to look at IO0 tomorrow on an oscilloscope and see exactly how it behaves.

Brian.
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
15,198
Helped
4,955
Reputation
9,932
Reaction score
4,779
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
129,081
OK, here are the results:

On the module I checked, which has been programmed with my own code but this is at power-up and before it runs:

IO0 goes high for 37.6mS then for about 45mS carries a 2MHz waveform that alternates between 0.25uS high/ 0.25us low for about 40uS and .375uS high/.125uS low for about 10uS.

TX and IO2 both carry identical serial data starting after 42mS. The data lists the bootloader revision and date then some information about memory allocations and reason for last reset at around 75.4K Bauds.

The image shows IO0 on the top line, then TX and then IO2.
The rise at the start is when the power is turned on.

Brian.
 

Attachments

  • ESP8266_startup.png
    ESP8266_startup.png
    7.3 KB · Views: 37

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top