Electronic – How to keep a momentary button low long enough for microcontroller to read it

buttonesp8266

I'm using an ESP-12F to fire off mqtt messages when a button is pressed. The circuit works as expected; the physical button resets the device which boots, runs the code and deep sleeps indefinitely. I want to add more than one button (or external trigger) but I want to know which one woke the device up. I attached multiple momentary buttons to the circuit and they all do the job of reseting the device but I was unable to capture which button was pressed.

button press vs startup
The yellow line is my button press (drives reset low), it takes about 150ms. The blue is a simple digitalWrite in the setup method of a blank program. It appears the ESP12 takes about 250ms to boot up into setup where I could read the pin but by then the button has returned to it's original state. Is there an easy way to extend the low so it can be read by the IC?

This is also an empty program, once I add libraries etc it adds another 50-100ms just to get to setup so I would probably have to extend the button state to say 400ms to be safe.

Edit: So an issue with this design is that if I hold the button low to try and capture it since it's connect to reset it doesn't actually reset. I need to "capture" the low and then release but then read it after startup.

Edit: Blue is connected to an LED on a GPIO. I'm using this to basically see when the program is in setup() by switching this high. The yellow line is the reset pin, the initial low resets the device and then when I release the button it returns to high via a pullup.

Best Answer

The EXT_RSTB input on the Expressif 8266EX is level-sensitive (low active) so stretching the push-button press will not help- the processor only boots once the EXT_RSTB signal has been removed.

You can use a couple one-shots to stretch the pushbutton presses (perhaps a 74HC123) but you'll also have to combine the two switches to create one reset signal. If you pull the inputs low, you can use an AND gate (half a 74HC00, for example).

schematic

simulate this circuit – Schematic created using CircuitLab