Here is a working code example:
/*
- Test of IP5306 functions
*/
#include <M5Stack.h>
void setup()
{
// initialize the M5Stack object
M5.begin();
Wire.begin(); // required to access IP5306
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setCursor(0, 10);
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setTextSize(2);
M5.Lcd.printf("IP5306 Function Test\r\n");
if(!M5.Power.canControl())
{
M5.Lcd.setTextColor(RED);
M5.Lcd.printf("No communication with IP5306 chip");
while(1);
}
}
void loop()
{
M5.Lcd.fillRect(0,180,360,60,0);
uint8_t bat = M5.Power.getBatteryLevel();
M5.Lcd.setCursor(0,180);
if (M5.Power.isCharging()) M5.Lcd.printf("Battery is charging\r\n");
else M5.Lcd.printf("Battery is not charging\r\n");
M5.Lcd.printf("Battery Level %d", bat);
M5.Lcd.progressBar(0, 220, 360, 20, bat);
delay(5000);
}