-->
Page 1 of 1

How to use attachInterrupt

PostPosted: Sat Feb 16, 2019 5:14 am
by Erik84750
I would like to use an external active low pulse on GPIO2 to wake ESP8266 from deep-sleep-forever.

https://techtutorialsx.com/2016/12/11/e ... nterrupts/ shows how to set a GPIO as interrupt handler.
However: when a ESP8266 is brought to deep sleep forever, will this GPIO, when set with an attachInterrupt, be able to bring the ESP8266 out of deep sleep?

Re: How to use attachInterrupt

PostPosted: Sat Feb 16, 2019 6:39 am
by btidey
No. That won't work.

In deep sleep the ESP8266 is doing nothing except potentially running a deep sleep counter which can send a pulse out on GPIO16 when it terminates. The CPU is off and it is not monitoring any GPIO.

The only ways out of deep sleep are to pulse the reset line, or the EN line, or to power cycle it.

The GPIO16 end of deep sleep pulse may be used to wake it back up by connecting to reset, or external circuitry can be used to do something with reset or EN. I actually prefer using EN as it is a raw input; the reset line normally has a timing capacitor which can complicate things.

Re: How to use attachInterrupt

PostPosted: Sat Feb 16, 2019 8:56 am
by Erik84750
btidey wrote:No. That won't work.

In deep sleep the ESP8266 is doing nothing except potentially running a deep sleep counter which can send a pulse out on GPIO16 when it terminates. The CPU is off and it is not monitoring any GPIO.

The only ways out of deep sleep are to pulse the reset line, or the EN line, or to power cycle it.

The GPIO16 end of deep sleep pulse may be used to wake it back up by connecting to reset, or external circuitry can be used to do something with reset or EN. I actually prefer using EN as it is a raw input; the reset line normally has a timing capacitor which can complicate things.


Ok, thanks for that.

Now what about the Light Sleep Forever mode? According to the attached notice the GPIO pins would remain active?
How to attribute a GPIO pin as an interrupt handler? How to program the ESP8266 so that this pin rewakes the chip on a high to low transition?

Re: How to use attachInterrupt

PostPosted: Sat Feb 16, 2019 10:42 am
by btidey
Yes. The GPIO can, in principle, wake the processor from light sleep. The pdf has an example on how to set that up and how to assign the wake up pin.

Note that some users have struggled to get this to work. See for example https://github.com/esp8266/Arduino/issues/1381

I don't use light sleep myself as the current drawn (1mA) is still too much for my battery applications. Deep sleep is much lower.