🤖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

    Scheduled Pinned Locked Moved General
    5 Posts 2 Posters 7.9k Views
    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 Offline
      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 Offline
        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 Offline
          babygirl1248
          last edited by

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

          1 Reply Last reply Reply Quote 0
          • felmueF Offline
            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 Offline
              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

              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

              With your input, this post could be even better 💗

              Register Login
              • First post
                Last post