Don't know if still relevant, but you can just power it off if you see it was plugged in. I attach a basic code here, and you can tweak it to your needs of course. Be aware that you might need to use a small delay before M5.Axp.GetVBusVoltage() will give you a result you can trust. //function which reads the voltage coming out of the USB, and if it's above 4.1 I know the device is being charged. bool isBeingCharged() { float charge = M5.Axp.GetVBusVoltage(); //Serial.println(charge); return charge > 4.1; } //check here of anywhere you want in the code if the device is being charged, and power it off. void setup() { if (isBeingCharged()) { M5.Axp.PowerOff(); } }