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

    Core2: Python API to get battery charge level

    Scheduled Pinned Locked Moved UIFlow
    5 Posts 2 Posters 10.8k Views 2 Watching
    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.
    • O Offline
      ondrej1024
      last edited by

      Is there a Python API to get battery charge level for the Core2 battery?

      I found power.getChargeState() but it just returns true/false (charging/discharging). There is also power.getBatVoltage() which could be an indication of the charge level but would need some additional math to calculate the percentage.

      1 Reply Last reply Reply Quote 0
      • R Offline
        robalstona
        last edited by

        I found table with voltage and according percentage on internet and make this code

        https://github.com/stonatm/UiFlow-custom-blocks/blob/master/battery-capacity/battery.py

        ewentually you could calculate with formula something like this, but it is not accurate.

        percentage = int( (battery_voltage - 3.20) * 100)
        
        1 Reply Last reply Reply Quote 0
        • O Offline
          ondrej1024
          last edited by

          I see that your code applies to the M5stickC. Do you think the table is the same for the M5 Core2?

          1 Reply Last reply Reply Quote 0
          • R Offline
            robalstona
            last edited by robalstona

            Should work if you replace line

            volt = axp.getBatVoltage()
            

            with

            volt = power.getBatVoltage()
            

            Battery discharge characteristics should be the same +/- some small variations independently of battery capacity.

            O 1 Reply Last reply Reply Quote 0
            • O Offline
              ondrej1024 @robalstona
              last edited by

              Thanks. I checked on the Core2 and here battery voltage also ranges from about 3.2V to 4.2V.

              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