4
\$\begingroup\$

I have an ESP8266, ESP-12F modules that is in deep sleep mode.

It wakes up every 6 hours to read the 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.

Is there a way to differentiate wakeup due to sleep interval vs a button press reset? In both cases the reset reason is 5.

I'm open to both hardware and firmware solutions.

I have also tried to simulate a possible circuit. 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.

\$\endgroup\$
0

2 Answers 2

3
\$\begingroup\$

One hardware solution is to use SR Latch. From description it look like the NAND one (/S, /R) would be suitable in this situation. You should be able to find a chip with such latch or build one from gates using for example 74HC00 (4 nand gates out of which 2 would be used). However one extra pin to reset the SR latch after power up caused by the external button is needed.

Connection could be as follows:

  • /S - connected to wake up button connected also to ESP8266. Assumed the ESP8266 wake up (/RESET) is active low, momentary switch pulls to GND, and this line is normally pulled up (like in the falstad schematic from question).
  • /R - connected to some output of the ESP8266 (GPIO) - you would need pull up on this pin too, so it is defined when ESP8266 is in power down
  • Q (SR output) - connected to some input of the ESP8266 (GPIO)

Operation would be as follows:

  1. Pressing the momentary switch (shorting to GND) - would change state of the SR output to 1.
  2. After boot up is finished software would read state of the Q - if it is "1" this is power up due to switch/if 0 this is power up due to timer.
  3. Before going to sleep again, you would arm the SR latch for next power up by applying short pulse to GND on /R pin so Q would be 0.

One drawback of this solution is that after first applying power to the system (3.3V ramp up) SR latch state is unknown (either 0 or 1). This means that you might misread first power up reason but later on would be OK.

Standard disclaimer - solution provided w/o any simulation or prototyping - you should think it through, check if works at all and if is suitable for your application.

\$\endgroup\$
0
\$\begingroup\$

An easy answer is to use diode steering and a delay cap.

Wake from a button... Your reset button goes to 2 diodes, one connects to the ESP RST pin, the other connects to any other GPIO (lets say GPIO 6). GPIO-6 has a cap to gnd, and a slow pull up resistor. Pressing the button brings both pins lo and discharges the cap, releasing the button releases the reset pin, the cap holds GPIO 6 low for some time, you sample GPIO 6 during boot before the cap charges.

Wake from timer... GPIO 16 from the ESP goes to the RST pin. When this goes lo, GPIO 6 does not go lo. Maybe use a diode here too so pressing the reset button does not pull GPIO 6 low (it is set as an output, best not to over current it.)

Of course, you can do the opposite, GPIO16 pulls both RST and GPIO 6 low, the reset button pulls only the RST pin low.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.