Periodic or interrupt wakeup

Updated on 13 October 2022
dev board WeMos D1 Mini
chip ESP8266
features sleep wakeup
This tutorial is more than 1 year old. If the steps below do not work, then please check the latest versions and the documentations of the individual tools used.

Before starting

Dependancies

Ensure the following dependancies are downloaded and available:

Buy the components

Code

Download code 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() {
}

Makefile

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

Prototype

A photo of the actual setup.

Periodic or interrupt wakeup prototype

Schematic

Wire up the hardware accordingly

Periodic or interrupt wakeup schematic

Arduino IDE settings

Ensure the following IDE settings before flashing.

Periodic or interrupt wakeup Arduino IDE settings

Serial console

Serial output from the firmware.

Periodic or interrupt wakeup serial console

Description

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.

References