Periodic or interrupt wakeup

dev board WeMos D1 Mini
chip ESP8266
features sleep wakeup

Before starting

Dependancies

Ensure the following requirements are available:

Buy the components

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.

Code

Download code
#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

Serial console

Serial output from the firmware.

Periodic or interrupt wakeup serial console

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

Prototype

A photo of the actual setup.

Periodic or interrupt wakeup prototype

References