user34731: Context
I keep the board in deepsleep mode and want to wake it with different buttons. I need to know which button has been pushed on boot. The board is immediately put back in deepsleep mode afterward.
I've been able to reset the board and pull a pin LOW at the same time. (see circuit below). The reset pin is momentarily pulled low so it reset the board effectively.
I'm not an electronic engineer, just a hobbyist, so any other method to do something are always welcome.
Problem
With the actual code/circuit, I need to hold the button until the device boot up so it can detect button was pushed but I would like to be able to just push the button quickly instead of having to hold it.
Question
How to add some sort of delay that will "hold" the SW-D5 button until the board boot?
Or anything that keep my D5 pin LOW for a short amount of time after the button has been pushed?
I think something in the range of 500 to 1000 milliseconds would be enough.
My actual circuit

simulate this circuit – Schematic created using CircuitLab
My code
#include <Spi.h>
#include <Arduino.h>
#include <ESP8266WiFi.h>

int buttonPin = D5;

void setup() {
  // Read pin value as soon as possible after boot
  pinMode(buttonPin, INPUT_PULLUP);
  int buttonValueAtBoot = digitalRead(buttonPin);

  pinMode(BUILTIN_LED, OUTPUT);
  Serial.begin(115200);
  Serial.println();

  if (buttonValueAtBoot == LOW) {
    Serial.println("D5 was pressed");

    // Do something useful here like making an HTTP request.
    digitalWrite(BUILTIN_LED, LOW);
  }

  // Avoid problem when the button is being hold
  while (digitalRead(buttonPin) == LOW) {
    // wait before going to deepsleep
    // or the capacitor will be drained
    delay(1);
  }

  Serial.println("going to sleep");
  ESP.deepSleep(0);
}

void loop() {
}


user4143: A simple RC network should do the job.

simulate this circuit – Schematic created using CircuitLab
Ok. A quick explanation of what we have here.  C1 and R1 are the same as you have at the moment for your reset circuit. R1 is the existing pullup resistor in the Wemos. R3 recharges the C1 when the button is released. It's effectively the pullup for the button.
D2 is to separate the two parts of the circuit. It prevents R3 from charging the capacitor C2.
The magic happens with C2 and R2. Pressing SW1 discharges C2, and the GPIO goes low.  When you release SW1 C2 charges up again through R2.  When the voltage across C2 rises to the VIH of the GPIO the GPIO will go high.
D1 is to protect the GPIO from the negative pulse you can get from C2 as it discharges.
Here's a simulation. Top line is the GPIO, bottom is RESET.

VIH for the ESP8266 is 0.75VIO, so 75% of 3.3V, or 2.475V.
The charge time of the capacitor C2 is calculated as T=RC, where T is the time taken to charge up to 63% of the supply voltage (2.08V)
With the shown values the time taken to rise to 63% of 3.3V will be 10,000 x 0.0001 seconds, or 1 second.  So to get to 75% it will take a little longer than 1 second.  75% is about 1.4T, so if T is 1 as in the above equation then it will take 1.4 seconds (1 * 1.4) to rise enough for the GPIO to register as HIGH.
Note these times are all from the moment you release the button. Reset has already happened before that time.
Also the internal pullup of the GPIO should be disabled otherwise it will also charge the capacitor and the charge time will be reduced. Since you don't know that resistor value it then becomes impossible to calculate what the charge time will be. Simplest to just disable it and only use the external resistor R2.

34731: <h2>Context</h2>

<p>I keep the board in deepsleep mode and want to wake it with different buttons. I need to know which button has been pushed on boot. The board is immediately put back in deepsleep mode afterward.</p>

<p>I've been able to reset the board and pull a pin LOW at the same time. (see circuit below). The reset pin is momentarily pulled low so it reset the board effectively.</p>

<p>I'm not an electronic engineer, just a hobbyist, so any other method to do something are always welcome.</p>

<h2>Problem</h2>

<p>With the actual code/circuit, I <em>need</em> to hold the button until the device boot up so it can detect button was pushed but <strong>I would like to be able to just push the button quickly</strong> instead of having to hold it.</p>

<h2>Question</h2>

<p>How to add some sort of delay that will "hold" the <strong>SW-D5</strong> button until the board boot?</p>

<p>Or anything that keep my D5 pin LOW for a short amount of time after the button has been pushed?</p>

<p>I think something in the range of 500 to 1000 milliseconds would be enough.</p>

<h2>My actual circuit</h2>



<p><img src="https://i.stack.imgur.com/bKKgT.png" alt="schematic"></p>



<p><sup><a href="/plugins/schematics?image=http%3a%2f%2fi.stack.imgur.com%2fbKKgT.png">simulate this circuit</a> &ndash; Schematic created using <a href="https://www.circuitlab.com/" rel="nofollow">CircuitLab</a></sup></p>

<h2>My code</h2>



<pre class="lang-c prettyprint-override"><code>#include &lt;Spi.h&gt;
#include &lt;Arduino.h&gt;
#include &lt;ESP8266WiFi.h&gt;

int buttonPin = D5;

void setup() {
  // Read pin value as soon as possible after boot
  pinMode(buttonPin, INPUT_PULLUP);
  int buttonValueAtBoot = digitalRead(buttonPin);

  pinMode(BUILTIN_LED, OUTPUT);
  Serial.begin(115200);
  Serial.println();

  if (buttonValueAtBoot == LOW) {
    Serial.println("D5 was pressed");

    // Do something useful here like making an HTTP request.
    digitalWrite(BUILTIN_LED, LOW);
  }

  // Avoid problem when the button is being hold
  while (digitalRead(buttonPin) == LOW) {
    // wait before going to deepsleep
    // or the capacitor will be drained
    delay(1);
  }

  Serial.println("going to sleep");
  ESP.deepSleep(0);
}

void loop() {
}
</code></pre>
 4143: <p>A simple RC network should do the job.</p>



<p><img src="https://i.stack.imgur.com/Iv8jX.png" alt="schematic"></p>



<p><sup><a href="/plugins/schematics?image=http%3a%2f%2fi.stack.imgur.com%2fIv8jX.png">simulate this circuit</a> &ndash; Schematic created using <a href="https://www.circuitlab.com/" rel="nofollow">CircuitLab</a></sup></p>

<p>Ok. A quick explanation of what we have here.  C1 and R1 are the same as you have at the moment for your reset circuit. R1 is the existing pullup resistor in the Wemos. R3 recharges the C1 when the button is released. It's effectively the pullup for the button.</p>

<p>D2 is to separate the two parts of the circuit. It prevents R3 from charging the capacitor C2.</p>

<p>The magic happens with C2 and R2. Pressing SW1 discharges C2, and the GPIO goes low.  When you release SW1 C2 charges up again through R2.  When the voltage across C2 rises to the V<sub>IH</sub> of the GPIO the GPIO will go high.</p>

<p>D1 is to protect the GPIO from the negative pulse you can get from C2 as it discharges.</p>

<p>Here's a simulation. Top line is the GPIO, bottom is RESET.</p>

<p><a href="https://i.stack.imgur.com/UYR6B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UYR6B.png" alt="enter image description here"></a></p>

<p>V<sub>IH</sub> for the ESP8266 is 0.75V<sub>IO</sub>, so 75% of 3.3V, or 2.475V.</p>

<p>The charge time of the capacitor C2 is calculated as T=RC, where T is the time taken to charge up to 63% of the supply voltage (2.08V)</p>

<p>With the shown values the time taken to rise to 63% of 3.3V will be 10,000 x 0.0001 seconds, or 1 second.  So to get to 75% it will take a little longer than 1 second.  75% is about 1.4T, so if T is 1 as in the above equation then it will take 1.4 seconds (1 * 1.4) to rise enough for the GPIO to register as HIGH.</p>

<p>Note these times are all from the moment you <em>release</em> the button. Reset has already happened before that time.</p>

<p>Also the internal pullup of the GPIO should be <strong>disabled</strong> otherwise it will also charge the capacitor and the charge time will be reduced. Since you don't know that resistor value it then becomes impossible to calculate what the charge time will be. Simplest to just disable it and only use the external resistor R2.</p>
