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() {
}
pinMode()
insetup()
kicks in in about 200ms – dandavis Oct 29 '17 at 23:37setup()
.PushSW-D5
-> trigger reboot -> releaseSW-D5
-> few hundreds of milliseconds later ->setup()
– Remi Oct 30 '17 at 1:16