<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[High power consumption with deep sleep]]></title><description><![CDATA[<p dir="auto">My goal: make the "M5" button behave like the power button.<br />
The "M5" button is more user friendly.<br />
This code runs once, puts the M5Stick C Plus into deep sleep, then the "M5" button wakes it up:</p>
<pre><code>#include &lt;M5StickCPlus.h&gt;

//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, &amp;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();
}
</code></pre>
<p dir="auto">Right now it does nothing, it only prints the battery level and goes to sleep after 10 seconds.<br />
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.<br />
I imagine that if I actually make it do stuff (like connecting to WiFi and perform a HTTP request), it would last even less.</p>
<p dir="auto">Is this correct? Can I improve it somehow?</p>
<p dir="auto">Thanks</p>
]]></description><link>https://community.m5stack.com/topic/3135/high-power-consumption-with-deep-sleep</link><generator>RSS for Node</generator><lastBuildDate>Tue, 28 Apr 2026 23:21:44 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/3135.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 30 Mar 2021 09:49:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to High power consumption with deep sleep on Wed, 31 Mar 2021 11:28:16 GMT]]></title><description><![CDATA[<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/robalstona" aria-label="Profile: robalstona">@<bdi>robalstona</bdi></a> what do you mean by "check when the power button is pressed to power on device" ?</p>
</blockquote>
<p dir="auto">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.</p>
]]></description><link>https://community.m5stack.com/post/13340</link><guid isPermaLink="true">https://community.m5stack.com/post/13340</guid><dc:creator><![CDATA[robalstona]]></dc:creator><pubDate>Wed, 31 Mar 2021 11:28:16 GMT</pubDate></item><item><title><![CDATA[Reply to High power consumption with deep sleep on Tue, 30 Mar 2021 22:32:31 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/user/koichirose" aria-label="Profile: koichirose">@<bdi>koichirose</bdi></a></p>
<p dir="auto">sorry, my mistake. I've missed the fact that you are using the Plus version.</p>
<p dir="auto">Yes, the M5Core2 is better in that regard (about 1.8 mA in deep sleep) plus it has a bigger battery.</p>
<p dir="auto">Thanks<br />
Felix</p>
]]></description><link>https://community.m5stack.com/post/13332</link><guid isPermaLink="true">https://community.m5stack.com/post/13332</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Tue, 30 Mar 2021 22:32:31 GMT</pubDate></item><item><title><![CDATA[Reply to High power consumption with deep sleep on Tue, 30 Mar 2021 15:09:39 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/felmue" aria-label="Profile: felmue">@<bdi>felmue</bdi></a> that's really unfortunate. The C-plus actually has a 120mAh battery, not that it makes a difference...<br />
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.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/robalstona" aria-label="Profile: robalstona">@<bdi>robalstona</bdi></a> what do you mean by "check when the power button is pressed to power on device" ?</p>
<p dir="auto">Thanks</p>
]]></description><link>https://community.m5stack.com/post/13325</link><guid isPermaLink="true">https://community.m5stack.com/post/13325</guid><dc:creator><![CDATA[koichirose]]></dc:creator><pubDate>Tue, 30 Mar 2021 15:09:39 GMT</pubDate></item><item><title><![CDATA[Reply to High power consumption with deep sleep on Tue, 30 Mar 2021 12:03:35 GMT]]></title><description><![CDATA[<p dir="auto">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.</p>
]]></description><link>https://community.m5stack.com/post/13324</link><guid isPermaLink="true">https://community.m5stack.com/post/13324</guid><dc:creator><![CDATA[robalstona]]></dc:creator><pubDate>Tue, 30 Mar 2021 12:03:35 GMT</pubDate></item><item><title><![CDATA[Reply to High power consumption with deep sleep on Tue, 30 Mar 2021 10:37:42 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/user/koichirose" aria-label="Profile: koichirose">@<bdi>koichirose</bdi></a></p>
<p dir="auto">a couple of month ago I did some <a href="https://gwendesign.ch/kb/m5stack/m5stickc/#power-management-unit-axp192" target="_blank" rel="noopener noreferrer nofollow ugc">measurements</a> and your numbers are about in line with those.</p>
<p dir="auto">The internal battery is only about 95 mAh. You are getting about 12 hours which means an average current of about 8 mA.</p>
<p dir="auto">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.</p>
<p dir="auto">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.</p>
<p dir="auto">Thanks<br />
Felix</p>
]]></description><link>https://community.m5stack.com/post/13323</link><guid isPermaLink="true">https://community.m5stack.com/post/13323</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Tue, 30 Mar 2021 10:37:42 GMT</pubDate></item></channel></rss>