Display on during deep sleep?

  • I can't believe this problem has no solution: keeping the display of M5stack ON during light or deep sleep. It should be trivial and yet no one on this forum can present a working solution. This seems to be an impossible task!

  • @m5er said in Display on during deep sleep?:

    I can't believe this problem has no solution: keeping the display of M5stack ON during light or deep sleep. It should be trivial and yet no one on this forum can present a working solution. This seems to be an impossible task!

    The reason no solution exist is because having the screen on goes against the purpose of deep sleep and also because it’s such an unusual question that you have asked, no one has yet to think of a solution in the esp32 world.

    Please be patient, M5Stack is still a young project and not everything is thought off until the end user posses a query. If you discover a way to do please let us know but in the mean time please continue to wait patiently.

  • I agree with @ajb2k3 that M5Stack is a young project, so that indeed explains the lack of such queries. However, I don't think my use case is unusual - I can think of a lot of applications that would benefit from sleeping while the display is on, such as: a clock showing hours and minutes only (so waking up only once a minute); sensor monitoring application (e.g. temperature, humidity, etc.) that constantly displays the latest values and wakes up once each X minutes to update measurements; displaying the number of twitter followers, likes, page visits, etc. In all these use cases it is useful to have the CPU sleep most of the time while the display remains on.

    In any case, it would be great if someone can present a working solution. It is probably just a few lines of code, but I just can't seem to get the right ones.

  • @m5er

    Thank you.
    What some people dont know is that the esp32 is not like an arduino.
    the esp32 has 3 cores, 2 primary and 1 Ultra Low power.
    In true deep sleep, the primary core are deactivated and the basic "Upkeep" code is off loaded to the ULP.
    Because the M5Stack is based on the ESP32 and not much is understood about the ULP, very little progress has been made on deep sleep.
    In theory, from what I have read the ULP could maintain a low power screen for a Like (to use your example) and then wake up the core to take the sensor measurements before storing them (for the ulp to recall and display) putting the cores back to sleep.

    If you are interested in leaning more, look into the ESP32's ULP (Ultra Low Power core)

  • @m5er said in Display on during deep sleep?:

    dernières valeurs et se réveille toutes les X minutes pour mettre à jour les mesures; affichage du nombre d'abonnés twitter, de likes, de visites de pages, etc. Dans tous ces cas d'utilisation, il est utile de laisser le CPU dormir la plupart du temps pendant que l'affichage reste allumé.
    Dans tous les cas, ce serait bien si quelqu'un pouvait présenter une solution de travail. Ce n'est probablement que quelques lignes de code, mais je n'arrive pas à trouver les bonnes.


    I'm editing this old post... Do you have a solution?


  • @PierreD

    Random Nerd Tutorials published by Rui and Sara Santos have a tutorial how to use the deep sleep mode on the ESP32and how to store data in the RTC memory:


    I havn't tried it out yet, but it probably should also work with the M5Stack ESP32.

    @PierreD Tu trouves une code exemplaire de programmation pour le sub-ordnateur ESP32-RTC au site de Rui et Sara Santos à https://randomnerdtutorials.com/esp32-timer-wake-up-deep-sleep/

    bonne chance crami25

  • Hello Crami25,

    Thank you for your help.
    I took the time to try, to test.

    For sleep, it's OK.
    I made a small example but it doesn't work every time ???

    On the other hand, I wish to wake up with the buttons.
    I've searched the schematics:
    Button A GPIO39
    Button B GPIO38
    Button C GPIO37

    Following the example of this site:

    In this example, the ESP32 wakes up when the GPIO 33 is triggered to high:

    esp_sleep_enable_ext0_wakeup(GPIO_NUM_33,1); //1 = High, 0 = Low
    Instead of GPIO 33, you can use any other RTC GPIO pin.

    #include <M5Stack.h>

    #define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds /
    #define TIME_TO_SLEEP 10 /
    Time ESP32 will go to sleep (in seconds) */
    //#define BUTTON_PIN_BITMASK 0x8000000000

    void setup()
    M5.begin(true, false, true);
    esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
    Serial.println("Setup ESP32 to sleep for every " + String(TIME_TO_SLEEP) + " Seconds");

    esp_sleep_enable_ext0_wakeup(GPIO_NUM_39,0); //1 = High, 0 = Low

    //esp_deep_sleep_start(); //entre en someil profond


    void loop() {

    M5.update();// update button state

    if (M5.BtnA.wasReleased())
    esp_sleep_enable_ext0_wakeup(GPIO_NUM_39,0); //1 = High, 0 = Low

    if (M5.BtnB.wasReleased())
    esp_deep_sleep_start(); //entre en someil profond

    if (M5.BtnC.wasReleased())
    M5.Lcd.setCursor(40, 60);
    M5.Lcd.print("Temperature: ");

  • Hey @pierred and @crami25 - no offense, but it looks like you are hijacking this thread to discuss a different topic, i.e. how to wake from sleep. The original topic of this thread is "how to enter deep sleep while keeping the LCD on". This is still not solved and I doubt that it will ever be.

  • @m5er During deep sleep the LCD background led draws(a lot of) current. Also you have to refresh your screen 50 times per second
    The only solution to your problem would be adding an e-ink display which doesn't need any refresh during deep_sleep.

  • Hello all

    the reason nothing can be seen on the LCD during deep sleep is that the backlight is off. The LCD backlight is driven by GPIO32 (PWM) which is stopped when the ESP32 goes into deep sleep. Luckily GPIO32 can be controlled by the Ultra Low Processor (ULP) too. Below is a small test program which implements PWM for GPIO32 with ULP C macros / assembler.


    #include <M5Stack.h>
    #include "esp32/ulp.h"
    #include "driver/rtc_io.h"
    const int lcdBrightness = 1; // (1-255)
    void ulp_start(void) {
      // Slow memory initialization
      memset(RTC_SLOW_MEM, 0, 8192);
      // M5Stack LCD backlight is connected to GPIO32 (specify by +14)
      const gpio_num_t lcdPWMPin = GPIO_NUM_32;
      const int lcdPWMBit = RTCIO_GPIO32_CHANNEL + 14;
      // GPIO32 initialization (set to output and initial value is 0)
      rtc_gpio_set_direction(lcdPWMPin, RTC_GPIO_MODE_OUTPUT_ONLY);
      rtc_gpio_set_level(lcdPWMPin, 0);
      // Define ULP program
      const ulp_insn_t  ulp_prog[] = {
        I_WR_REG(RTC_GPIO_OUT_REG, lcdPWMBit, lcdPWMBit, 1), // on
        I_DELAY(lcdBrightness * 100),
        I_WR_REG(RTC_GPIO_OUT_REG, lcdPWMBit, lcdPWMBit, 0), // off
      // Run ULP program
      size_t size = sizeof(ulp_prog) / sizeof(ulp_insn_t);
      ulp_process_macros_and_load(0, ulp_prog, &size);
    void setup() {
      M5.begin(true, false, true, false);
      M5.Lcd.println("Put something onto the LCD...");
      M5.Lcd.println("Going to deep sleep");
      esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
    void loop() {