<?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[Battery level]]></title><description><![CDATA[<p dir="auto">Hi, does this sketch work with M5Stick too?</p>
<pre><code>
// https://github.com/m5stack/M5Stack/issues/74


#include &lt;M5Stack.h&gt;

int8_t getBatteryLevel()
{
  Wire.beginTransmission(0x75);
  Wire.write(0x78);
  if (Wire.endTransmission(false) == 0
   &amp;&amp; Wire.requestFrom(0x75, 1)) {
    switch (Wire.read() &amp; 0xF0) {
    case 0xE0: return 25;
    case 0xC0: return 50;
    case 0x80: return 75;
    case 0x00: return 100;
    default: return 0;
    }
  }
  return -1;
}

void setup() {
    M5.begin();
    Wire.begin();
  }

void loop() {
  delay(1000);
  M5.Lcd.clear();
  M5.Lcd.setTextColor(GREEN);
  M5.Lcd.setCursor(0, 20);
  M5.Lcd.setTextSize(2);
  M5.Lcd.print("Battery Level: ");
  M5.Lcd.print(getBatteryLevel());
  M5.Lcd.print("%");
}

</code></pre>
<p dir="auto">tnks a lot?</p>
]]></description><link>https://community.m5stack.com/topic/973/battery-level</link><generator>RSS for Node</generator><lastBuildDate>Sun, 19 Apr 2026 15:34:04 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/973.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 02 May 2019 08:58:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Battery level on Wed, 03 Jul 2019 16:25:06 GMT]]></title><description><![CDATA[<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/935">@cepics</a> said in <a href="/post/4752">Battery level</a>:</p>
<blockquote>
<p dir="auto">does it should work on GRAY M5Stick too ?</p>
<p dir="auto">tnks</p>
</blockquote>
<p dir="auto">I don't think so but i could be mistaken.</p>
]]></description><link>https://community.m5stack.com/post/4755</link><guid isPermaLink="true">https://community.m5stack.com/post/4755</guid><dc:creator><![CDATA[ajb2k3]]></dc:creator><pubDate>Wed, 03 Jul 2019 16:25:06 GMT</pubDate></item><item><title><![CDATA[Reply to Battery level on Wed, 03 Jul 2019 06:57:44 GMT]]></title><description><![CDATA[<p dir="auto">does it should work on GRAY M5Stick too ?</p>
<p dir="auto">tnks</p>
]]></description><link>https://community.m5stack.com/post/4752</link><guid isPermaLink="true">https://community.m5stack.com/post/4752</guid><dc:creator><![CDATA[cepics]]></dc:creator><pubDate>Wed, 03 Jul 2019 06:57:44 GMT</pubDate></item><item><title><![CDATA[Reply to Battery level on Tue, 02 Jul 2019 01:28:14 GMT]]></title><description><![CDATA[<p dir="auto">Theres a pretty nice comprehensive blog post on the battery and output of the stick c but in japanese <a href="https://lang-ship.com/blog/?p=523" target="_blank" rel="noopener noreferrer nofollow ugc">https://lang-ship.com/blog/?p=523</a>. He posts his arduino code though on how to read different information about the battery. I tested and it works pretty well.</p>
<pre><code>#include &lt;M5StickC.h&gt;
 
void setup() {
  // put your setup code here, to run once:
  M5.begin();
  M5.Lcd.fillScreen(BLACK);
   
  M5.Axp.EnableCoulombcounter();
}
double vbat = 0.0;
int discharge,charge;
double temp = 0.0;
double bat_p = 0.0;
double bat_p2 = 0.0;
 
void loop() {
  M5.Lcd.fillScreen(BLACK);
  vbat      = M5.Axp.GetVbatData() * 1.1 / 1000;
  charge    = M5.Axp.GetIchargeData() / 2;
  discharge = M5.Axp.GetIdischargeData() / 2;
  temp      =  -144.7 + M5.Axp.GetTempData() * 0.1;
  bat_p     =  M5.Axp.GetPowerbatData() * 1.1 * 0.5 /1000;
   
  M5.Lcd.setCursor(0, 0, 1);
  M5.Lcd.printf("vbat:%.3fV\r\n",vbat);
  M5.Lcd.printf("icharge:%dmA\r\n",charge);
  M5.Lcd.printf("idischg:%dmA\r\n",discharge);
  M5.Lcd.printf("temp:%.1fC\r\n",temp);
  M5.Lcd.printf("pbat:%.3fmW\r\n",bat_p);
  M5.Lcd.printf("CoIn :%d\r\n",M5.Axp.GetCoulombchargeData());
  M5.Lcd.printf("CoOut:%d\r\n",M5.Axp.GetCoulombdischargeData());
  M5.Lcd.printf("CoD:%.2fmAh\r\n",M5.Axp.GetCoulombData());
  M5.Lcd.printf("Vin:%.3fmV\r\n",M5.Axp.GetVinData() * 1.7);
  M5.Lcd.printf("Iin:%.3fmA\r\n",M5.Axp.GetIinData() * 0.625);
  M5.Lcd.printf("VBin:%.3fmV\r\n",GetVBinData() * 1.7);
  M5.Lcd.printf("IBin:%.3fmA\r\n",GetIBinData() * 0.375);
  M5.Lcd.printf("VAPS:%.3f\r\n", GetVapsData()*1.4/1000);
  delay(1000);
}
 
uint16_t GetVBinData(void){
 
    uint16_t vin = 0;
 
    Wire1.beginTransmission(0x34);
    Wire1.write(0x5a);
    Wire1.endTransmission();
    Wire1.requestFrom(0x34, 1);
    uint8_t buf = Wire1.read();
 
    Wire1.beginTransmission(0x34);
    Wire1.write(0x5b);
    Wire1.endTransmission();
    Wire1.requestFrom(0x34, 1);
    uint8_t buf2 = Wire1.read();
 
    vin = ((buf &lt;&lt; 4) + buf2); // V
    return vin;
 
}
 
uint16_t GetIBinData(void){
 
    uint16_t iin = 0;
 
    Wire1.beginTransmission(0x34);
    Wire1.write(0x5c);
    Wire1.endTransmission();
    Wire1.requestFrom(0x34, 1);
    uint8_t buf = Wire1.read();
 
    Wire1.beginTransmission(0x34);
    Wire1.write(0x5d);
    Wire1.endTransmission();
    Wire1.requestFrom(0x34, 1);
    uint8_t buf2 = Wire1.read();
 
    iin = ((buf &lt;&lt; 4) + buf2); // V
    return iin;
 
}
 
uint16_t GetVapsData(void){
 
    uint16_t vaps = 0;
    Wire1.beginTransmission(0x34);
    Wire1.write(0x7E);
    Wire1.endTransmission();
    Wire1.requestFrom(0x34, 1);
    uint8_t buf = Wire1.read();
 
    Wire1.beginTransmission(0x34);
    Wire1.write(0x7F);
    Wire1.endTransmission();
    Wire1.requestFrom(0x34, 1);
    uint8_t buf2 = Wire1.read();
     
    vaps = ((uint16_t)(buf &lt;&lt; 4) + buf2);
    return vaps;
 
}</code></pre>
]]></description><link>https://community.m5stack.com/post/4743</link><guid isPermaLink="true">https://community.m5stack.com/post/4743</guid><dc:creator><![CDATA[lukasmaximus]]></dc:creator><pubDate>Tue, 02 Jul 2019 01:28:14 GMT</pubDate></item><item><title><![CDATA[Reply to Battery level on Mon, 01 Jul 2019 09:06:14 GMT]]></title><description><![CDATA[<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/481">@m5-docs</a> coool it works!!</p>
<p dir="auto">but, when I plug the usb cable the serial monitor say 100%,<br />
though the battery level is less..</p>
<p dir="auto">is there a software way to know if the usb cable is connected? (to make power cable symbol appear on display)</p>
]]></description><link>https://community.m5stack.com/post/4738</link><guid isPermaLink="true">https://community.m5stack.com/post/4738</guid><dc:creator><![CDATA[cepics]]></dc:creator><pubDate>Mon, 01 Jul 2019 09:06:14 GMT</pubDate></item><item><title><![CDATA[Reply to Battery level on Sun, 05 May 2019 08:47:43 GMT]]></title><description><![CDATA[<p dir="auto">You can try this code for testing battery voltage level.</p>
<pre><code>#include &lt;M5Stack.h&gt;
#include &lt;U8x8lib.h&gt;

int8_t getBatteryLevel()
{
  Wire.beginTransmission(0x75);
  Wire.write(0x78);
  if (Wire.endTransmission(false) == 0
   &amp;&amp; Wire.requestFrom(0x75, 1)) {
    switch (Wire.read() &amp; 0xF0) {
    case 0xE0: return 25;
    case 0xC0: return 50;
    case 0x80: return 75;
    case 0x00: return 100;
    default: return 0;
    }
  }
  return -1;
}

void setup() {
    M5.begin();
    Wire.begin();
  }

void loop() {
  delay(200);
  Serial.print("Battery Level: ");
  Serial.print(getBatteryLevel());
  Serial.println("%");
}

</code></pre>
]]></description><link>https://community.m5stack.com/post/4128</link><guid isPermaLink="true">https://community.m5stack.com/post/4128</guid><dc:creator><![CDATA[m5-docs]]></dc:creator><pubDate>Sun, 05 May 2019 08:47:43 GMT</pubDate></item><item><title><![CDATA[Reply to Battery level on Fri, 03 May 2019 00:04:31 GMT]]></title><description><![CDATA[<p dir="auto">I didn’t test it, but probably not likely to work. The M5Stack and m5stickC use different power management chips (IP5306_i2c vs. AXP192). This sketch might help you get some power info from the m5stickC though.</p>
<p dir="auto"><a href="https://github.com/m5stack/M5StickC/blob/master/examples/Basics/AXP192/AXP192.ino" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/m5stack/M5StickC/blob/master/examples/Basics/AXP192/AXP192.ino</a></p>
]]></description><link>https://community.m5stack.com/post/4100</link><guid isPermaLink="true">https://community.m5stack.com/post/4100</guid><dc:creator><![CDATA[world101]]></dc:creator><pubDate>Fri, 03 May 2019 00:04:31 GMT</pubDate></item></channel></rss>