ESP8266: Differentiate wakeup due to sleep interval or button press
sayanee wrote 09/22/2017 at 00:31 • 0 pointsI have an ESP8266, ESP-12F modules that is in deep sleep mode.
It wakes up every 6 hours to read a humidity sensor, display it on LED and then post to IFTTT. Because it is every 6 hours, it actually wakes up every hour just to check an EEPROM stored counter to see if the 6 hour has elapsed. Otherwise, it will increase or reset the EEPROM counter accordingly.
I also want the user to press a button to wake up the ESP, read the humidity sensor, display it on the LED and send to IFTTT even if the 6 hours have not elapsed.
Here is the on-going project link: https://hackaday.io/project/26927-ariel-measure-humidity-with-esp12-ifttt-si7021
Is there a way to differentiate wakeup due to sleep interval vs a button press reset? In both cases the reset reason is from ESP is 5. I have used ESP.getResetInfoPtr in this case.
I'm open to both hardware and firmware solutions.
I have also tried to simulate a possible circuit in falstad. But the GPIO12 (which I am trying to read as LOW right after ESP wakes up) does not hold on to the LOW value long enough for me to read it right after wake up.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
https://user-images.githubusercontent.com/10696636/110329009-5a752b80-801c-11eb-8544-397b0f6ed2d9.png
C1=100µF
Are you sure? yes | no
I use this schema ...the C1 is wrong the right one is 100µF
https://user-images.githubusercontent.com/10696636/110329009-5a752b80-801c-11eb-8544-397b0f6ed2d9.png
Are you sure? yes | no
Sorry, everyone that I took this long to reply to this thread. I have since eventually gotten this circuit to work!
Here's my schematic for future reference: https://hutscape.com/cactus/hardware/docs/schematic.pdf
Are you sure? yes | no
You should consider using the RTC memory to store the wakeup counter instead of the EEPROM - RTC memory is preserved during deep sleep and does not have any maximum number of writes.
In my #SynchroClock project I have a config button that sends a reset pulse and can be held to place it in a configuration mode. Maybe you can do something similar.
Are you sure? yes | no
You can determine the reason for the restart/reset from e.g. rsti = ESP.getResetInfoPtr(); Andreas Spiess gives a good example here: https://github.com/SensorsIot/ESP8266-RTC-Memory
Are you sure? yes | no
I have already used the reset reason function. Whether it is wake up due to sleep interval or button press, the reset reasons are still 5.
As written above in my original post:
> In both cases the reset reason is from ESP is 5
Further edited my original post to indicate that I have already used the reset reason function.
Are you sure? yes | no
You could assign an interrupt to the pin, then a transition would wake the device and a check of the interrupt status or timer value would easily determine which caused the event, in fact I recall the timer event is also recorded in the status register.
Are you sure? yes | no
http://esp-idf.readthedocs.io/en/latest/api-reference/system/sleep_modes.html
Explains how to differentiate wake up reasons to, hope this helps.
Are you sure? yes | no
https://pcbreflux.blogspot.co.uk/2017/02/esp32-deep-sleep-example.html
And exactly the example you need GPIO or Timer, hope this helps.
Are you sure? yes | no
This should work: http://tinyurl.com/ydb92h4n Might be even possible to use 100k and 1uF. More than 10uF might be not good, because of high current for the switch and diode, which you could additionally limit with a low resistor, like 100 ohm.
Are you sure? yes | no
@Frank - thank you so much for the updated simulated!
I just prototyped it in breadboard. The voltage drop does happen in GPIO12, but it is still too fast for the ESP to read it as LOW immediately after wakeup. I tried with both sets of values (10k and 10u, 100k and 1u). Maybe I need to try out with another set of capacitor and resistor values to slow down the voltage rise for GPIO12.
Here is the screenshot from the logic analyser capture of the circuit with 10u capacitor and 470k resistor: https://dropbox.com/s/muso2lehriyw3ev/a.png?dl=0
Are you sure? yes | no
Maybe it is a voltage problem, because it is only detected as logic 0 below 0.8V input voltage. You could build a proper monoflop, with transistors or an IC, like the CD4098:
http://www.programelectronics.com/2015/10/25/experimenting-with-the-cd4098-dual-monostable-multivibrator/
For such simple projects a PIC microcontroller is very useful, because they are cheap and you don't need any external components (but a 100 nF decoupling capacitor between VDD and VSS might be useful). It is fun to write such small programs, I just created a project for it:
https://hackaday.io/project/27471-monoflop
You would need to connect RA0 (pin 7) to the reset pin and RA1 (pin 6) to your GPIO12 pin. But I guess there is a firmware-only solution as well.
Are you sure? yes | no
I found this thread because I was looking for a solution for the same problem.
@sayanee : I was able to make it work with a resistor of 10k and a capacitor of 22uF.
@Frank Buss : I simplified your schema by removing the diode on the right side of the circuit, the one connected with RST. Here the link: http://tinyurl.com/tefnd3l Do you see any problem? For the simulator, voltage and current seem fine.
Are you sure? yes | no
@Vincenzo M No problem, you can remove the diode.
Are you sure? yes | no
@Vincenzo M Nice! Glad you got it to work. Mine eventually worked with a 10u capacitor with a long press of a button.
Schematic: https://hutscape.com/cactus/hardware/docs/schematic.pdf
Are you sure? yes | no
Can't you just look at the timer and check if the hour is already over?
Are you sure? yes | no
@Florian, I am not aware of any ESP sleep API that exposes this timer value right after wakeup. I tried looking in the API docs just now: http://www.esp8266.com/wiki/doku.php?id=esp8266_power_usage. Please let me know if there is a way to read this value and then we will be able to have a complete firmware-only solution.
Are you sure? yes | no
Hmm, looks like this is more complicated than expected. Documentation seems to be very sparse - same for usable APIs. You probably need to read the setting of the RTC directly and compare the current time with the target value. You can probably dig the right address out the guts of systemdeepsleep() or from
https://github.com/esp8266/Arduino/blob/master/cores/esp8266/esp8266_peri.h
Are you sure? yes | no