Detecting when plugged in VS when charging

  • Hello, please excuse me for all the posts lately. I am trying to figure out how to detect when the device has been unplugged VS when it's plugged in.

    If plugged in run xyz
    And if disconnected from USB run abc.

    If it's inside the mcore2.h file I haven't seen it. I'm also legally blind so I very well could, have missed it too. Thank you giys.

  • Hello @babygirl1248

    you didn't overlook it. It's not in M5Core2.h. But I think it could be done.

    According to the M5Core2 schematic USB power goes into ACIN of the AXP192 IC and with that the AXP192 should be able to detect when USB is connected or disconnected.

    According to the AXP192 datasheet this information should be available in the interrupt status register 1 (0x44).

    You cannot actually use the interrupt since in M5Core2 the interrupt out line of the AXP192 is unused and has not been connected to anything, but you should be able to poll the interrupt status register 1.


  • Thank you so much! I will look into this further.

  • Hello @babygirl1248

    I was wrong. There already is a function to detect whether USB is plugged in or not. Please try:

    bool M5.Axp.isACIN();

    You can find the function in AXP192.h.

    Sorry about that.


  • Awesome! Thank you so much for taking the time to look. I really appriciate it.