🤖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

    UIFlow
    2
    5
    9.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.
    • O
      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
        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
          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
            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
              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
              • First post
                Last post