Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Read input voltage via code?

    Scheduled Pinned Locked Moved GPy
    3 Posts 2 Posters 292 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.
    • techykermitT Offline
      techykermit
      last edited by

      Hi! I have a GPy with the Makr board and a battery connected on the battery +/- 2-pin connector on the board. I want to be able to read how much input voltage I am getting from the battery on the GPy so that I can notify myself in advance before the battery runs out of power.

      So, I am wondering if there is there any way I can read how much power the PyCom are receiving from the battery connector in my code? If not, is there anything else I can do?

      robert-hhR 1 Reply Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @techykermit
        last edited by robert-hh

        @techykermit If the BAT jumper of the expansion board (pymakr, as you call it) is on place, the battery is connected by a voltage divider to P16. You can get it e.g. with this little script:

        import machine
        adc = machine.ADC()             # create an ADC object
        apin = adc.channel(pin='P16', attn=adc.ATTN_11DB)   # create an analog pin on P16
        val = apin.voltage()                    # read the value from ADC
        print(val * 2)    # compensate for the voltage divider
        

        Please note, that the voltage only allows to estimate the charge. For a LiPo battery, you can assume the battery as almost empty when the voltage is below 3.3V.

        techykermitT 1 Reply Last reply Reply Quote 1
        • techykermitT Offline
          techykermit @robert-hh
          last edited by

          @robert-hh Thanks! :)

          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
          • 1 / 1
          • First post
            Last post

          Pycom on Twitter

          Pycom