High power consumption with deep sleep



  • My goal: make the "M5" button behave like the power button.
    The "M5" button is more user friendly.
    This code runs once, puts the M5Stick C Plus into deep sleep, then the "M5" button wakes it up:

    #include <M5StickCPlus.h>
    
    //seconds
    const int timeout = 10;
    
    hw_timer_t * timer = NULL;
    bool go_to_sleep = false;
    
    void IRAM_ATTR onTimer()
    {
      Serial.println("onTimer called");
      go_to_sleep = true;
    }
    
    void setup() {
      sleep_wake();
      M5.begin();
      M5.Lcd.fillScreen(BLACK);
      set_backlight();
      setCpuFrequencyMhz(80);
      timer = timerBegin(0, 80, true);
      timerAttachInterrupt(timer, &onTimer, true);
      timerAlarmWrite(timer, timeout * 1000 * 1000, true);
      timerAlarmEnable(timer);
      M5.Lcd.setCursor(0, 35, 4);
      battery_display();
    }
    
    void loop() {
      delay(1000);
      sleep_check();
    }
    
    void sleep_check(void)
    {
      if(go_to_sleep == true) {
        deep_sleep();
      }
    }
    
    void set_backlight(void)
    {
        M5.Axp.ScreenBreath(8);
    }
    
    void clear_txt(void)
    {
      M5.Lcd.fillScreen(BLACK);
    }
    
    void battery_display(void)
    {
      M5.Lcd.setCursor(20, 20, 4);
      M5.Lcd.setTextSize(2);
      M5.Lcd.printf("%d%%", (int) battery_level());
      M5.Lcd.print("\n");
      M5.Lcd.setTextSize(1);
      M5.Lcd.printf("%fV", M5.Axp.GetBatVoltage());
    }
    
    double battery_level(void)
    {
      uint16_t vbatData = M5.Axp.GetVbatData();
      double vbat = vbatData * 1.1 / 1000;
      double percentage = 100.0 * ((vbat - 3.0) / (4.07 - 3.0));
      return min(percentage, 100);
    }
    
    void sleep_wake(void)
    {
      pinMode(GPIO_NUM_37, INPUT_PULLUP);
      esp_sleep_enable_ext0_wakeup(GPIO_NUM_37, LOW);
    }
    
    void backlight_off(void)
    {
      delay(1000);
      M5.Axp.ScreenBreath(0);
    }
    
    void deep_sleep(void) {
      clear_txt();
      M5.Lcd.setCursor(0, 30, 2);
      M5.Lcd.printf("Deep sleep\n");
      delay(1000);
      clear_txt();
      backlight_off();
      delay(3900);
      clear_txt();  
    
      // if I use this function, I can't wake it up with the M5 button anymore
      // M5.Axp.DeepSleep();
    
      // this works
      esp_deep_sleep_start();
    }
    

    Right now it does nothing, it only prints the battery level and goes to sleep after 10 seconds.
    If I unplug the device when fully charged (4.1V), then press the "M5" button once in a while (less than once an hour), I noticed a battery life of about 12 hours, which is way too little.
    I imagine that if I actually make it do stuff (like connecting to WiFi and perform a HTTP request), it would last even less.

    Is this correct? Can I improve it somehow?

    Thanks



  • Hello @koichirose

    a couple of month ago I did some measurements and your numbers are about in line with those.

    The internal battery is only about 95 mAh. You are getting about 12 hours which means an average current of about 8 mA.

    You could try to power off screen backlight, logic and microphone (not sure how much that helps though). Unfortunately you cannot turn off the MPU6886 as it uses the same power rail as the ESP32.

    As it has been stated multiple times before in this forum - M5Stack devices are not very good in using the low power capabilities of ESP32 light and deep sleep.

    Thanks
    Felix



  • In this case the problem is a AXP192 power management chip which consumes whole time ~2mA. This chip is connected to internal battery and power builtin microphone, lcd and other devices. Also check when the power button is pressed to power on device.



  • @felmue that's really unfortunate. The C-plus actually has a 120mAh battery, not that it makes a difference...
    The Core2 actually lasts a while, I have one that's been unplugged for a few days (doing the same thing, just showing the battery level) and it's still alive.

    @robalstona what do you mean by "check when the power button is pressed to power on device" ?

    Thanks



  • Hello @koichirose

    sorry, my mistake. I've missed the fact that you are using the Plus version.

    Yes, the M5Core2 is better in that regard (about 1.8 mA in deep sleep) plus it has a bigger battery.

    Thanks
    Felix



  • @robalstona what do you mean by "check when the power button is pressed to power on device" ?

    I mean that this axp192 chip is always powered and waits for power button press to powering upthe esp32 chip and lcd with backligth. And check when this button is pressed for 6 seconds to shut down the power.