Last active
July 27, 2019 01:02
-
-
Save Kongduino/e333db9132a65a866b3aee14e7aa17a9 to your computer and use it in GitHub Desktop.
Implementation of deep sleep with wakeup button for the M5StickC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <esp_sleep.h> | |
#include <esp_wifi.h> | |
#include <esp_bt.h> | |
#include <esp_bt_main.h> | |
#include <driver/adc.h> | |
#include <M5StickC.h> | |
void setup() { | |
M5.begin(); | |
Serial.begin(115200); | |
while (Serial.available()) char c = Serial.read(); | |
delay(200); | |
Serial.println("Deep Sleep Test."); | |
Serial.println("Press Button A to go to sleep and come back."); | |
} | |
void loop() { | |
M5.update(); | |
if (M5.BtnA.isPressed()) { | |
Serial.println("Going to sleep"); | |
myDeepSleep((gpio_num_t)BUTTON_A_PIN); | |
Serial.println("Hello!"); | |
} | |
} | |
void myDeepSleep(gpio_num_t PIN) { | |
esp_sleep_enable_ext0_wakeup(PIN, LOW); | |
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_AUTO); | |
while (digitalRead(BUTTON_A_PIN) == LOW) delay(10); | |
M5.Axp.SetSleep(); | |
esp_wifi_stop(); | |
/* | |
On recommendation from https://twitter.com/ioPush_net | |
to further reduce consumption | |
*/ | |
esp_bluedroid_disable(); | |
esp_bluedroid_deinit(); | |
esp_bt_controller_disable(); | |
esp_bt_controller_deinit(); | |
esp_bt_mem_release(ESP_BT_MODE_BTDM); | |
adc_power_off(); | |
esp_deep_sleep_start(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment