🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Detecting when plugged in VS when charging

    General
    2
    5
    6.2k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      babygirl1248
      last edited by

      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.
      Lile

      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.

      1 Reply Last reply Reply Quote 0
      • felmueF
        felmue
        last edited by felmue

        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.

        Thanks
        Felix

        GPIO translation table M5Stack / M5Core2
        Information about various M5Stack products.
        Code examples

        1 Reply Last reply Reply Quote 0
        • B
          babygirl1248
          last edited by

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

          1 Reply Last reply Reply Quote 0
          • felmueF
            felmue
            last edited by

            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.

            Thanks
            Felix

            GPIO translation table M5Stack / M5Core2
            Information about various M5Stack products.
            Code examples

            1 Reply Last reply Reply Quote 0
            • B
              babygirl1248
              last edited by

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

              1 Reply Last reply Reply Quote 0
              • First post
                Last post