6
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ So you can drive a pin low before the esp executes the rest of your startup code (which takes 250 ms)? Then you can also read inputs first, can't you? \$\endgroup\$ – Christoph Feb 24 '18 at 14:03
  • \$\begingroup\$ It's a physical button driving the pin (RESET) low. This restarts the controller and by the time it starts up the button is back to high. \$\endgroup\$ – Ryan Detzel Feb 24 '18 at 14:20
  • \$\begingroup\$ Why don't you explain better what you're doing exactly, as there seems to be some confusion. My guess is you're executing code to read a button and then go to deep sleep where you can only awake from reset. You have several buttons and you need to determine which one was pressed and at the same time each button also resets the processor. You are now driving the output low for demonstration (timing) purposes only, right? \$\endgroup\$ – gommer Feb 24 '18 at 14:40
  • \$\begingroup\$ That is correct. \$\endgroup\$ – Ryan Detzel Feb 24 '18 at 14:41
  • 1
    \$\begingroup\$ I'd just use a PIC10F200 in SOT-23-6 and be done with it. \$\endgroup\$ – jonk Feb 24 '18 at 18:28
4
\$\begingroup\$

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

\$\endgroup\$
3
\$\begingroup\$

To answer your specific question, one way to do it would be to add a SR latch between the button and the microcontroller, so that the button sets the latch and then the microcontroller can reset the latch when it's ready.

Christoph is right though, it would be odd if you could write outputs before the boot finishes but not read inputs...

\$\endgroup\$
  • \$\begingroup\$ I figured a latch would work somehow, guess I need to do some reading up on how they work. Thanks \$\endgroup\$ – Ryan Detzel Feb 24 '18 at 14:20
  • \$\begingroup\$ Or a cap across the switch and pullup Resistor large enough to stretch to 1 second \$\endgroup\$ – Tony Stewart Sunnyskyguy EE75 Feb 24 '18 at 14:22
  • \$\begingroup\$ @TonyStewart.EEsince'75 what kind of size we talking about? :-) Does this work by "filling" the cap and thus the pin low until it's full? \$\endgroup\$ – Ryan Detzel Feb 24 '18 at 14:24
  • 1
    \$\begingroup\$ read about RC time constant 1uF*1Mohm= T=1 s. , linear ramp to 50%Vdd slightly less than t= T then it curves slower towards Vdd. Threshold is loosely Vdd/2. \$\endgroup\$ – Tony Stewart Sunnyskyguy EE75 Feb 24 '18 at 14:29
  • 1
    \$\begingroup\$ @Christoph I can read it, it will just be high (yellow line) and not low so it doesn't tell me that it was pressed. If I have four buttons, they'll all read high by the time the UC startsup because the buttons have returned to high via the pullup. \$\endgroup\$ – Ryan Detzel Feb 24 '18 at 15:11
0
\$\begingroup\$

If you're willing to 'reduce' the sleep level (to light sleep maybe), then you can use your external interrupts to wake the device, save the cause to EEPROM in your handler and then reset the ESP with ESP.restart().

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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