Dependancies
Buy the components
periodic-wakeup-interrupt.ino
#include <ESP8266WiFi.h>
#define USERBUTTON 12 // GPIO012 on ESP or D6 on WeMos
void setup() {
Serial.begin(115200);
Serial.setTimeout(2000);
int userButtonValue = digitalRead(USERBUTTON);
while(!Serial) { }
Serial.println("Wake up!");
Serial.print("User button value: ");
Serial.println(userButtonValue);
if (userButtonValue == 0) {
Serial.print("User long pressed button: ");
}
Serial.println("Do task");
Serial.println("Going into deep sleep for 10s, unless button pressed...");
ESP.deepSleep(10e6);
}
void loop() {
}
BOARD?=esp8266com:esp8266:d1_mini
PORT?=/dev/cu.wchusbserial1410
BUILD=build
# Arduino CLI version 0.14.0 is used.
.PHONY: default lint all flash clean
default: lint all flash clean
lint:
cpplint --extensions=ino --filter=-legal/copyright *.ino
all:
arduino-cli compile --fqbn $(BOARD) --output-dir $(BUILD) ./
flash:
arduino-cli upload --fqbn $(BOARD) --port $(PORT) --input-dir $(BUILD)
clean:
rm -r build
Do something periodically on wake up after deep sleep or by pressing the button on-board.
On WeMos board , the pin REST
to 10kΩ
pulled up to +3V3
is already there. Remember to include it back with the ESP8266
module.