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

    Query battery status without board

    Scheduled Pinned Locked Moved WiPy 2&3
    wipylopybattery
    4 Posts 2 Posters 339 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.
    • W Offline
      Wolli01
      last edited by

      How can I query the battery status without board during Wipy/Lopy?
      With Board I am running like this.

          # takes battery voltage readings
          from machine import ADC #Batteriestatus
          def adc_battery():
          	adc = ADC(0)                                        # initialise adc hardware
          	adc_c = adc.channel(attn=3, pin='P16')              # create an object to sample ADC on pin 16 with attenuation of 11db (config 3)
          	adc_samples = []                                    # initialise the list
          	for count in range(100):                            # take 100 samples and append them into the list
          		adc_samples.append(int(adc_c()))
          	adc_samples = sorted(adc_samples)                   # sort the list
          	adc_median = adc_samples[int(len(adc_samples)/2)]   # take the center list row value (median average)
          # apply the function to scale to volts
          	adc_median = adc_median * 2 / 4095 / 0.3275
          	#print(adc_samples)
          	return adc_median
          lipo_voltage = adc_battery() #Batteriewerte zuordnen
          print('Batterie = ' + str(lipo_voltage) + ' Volt') #Wert anzeigen
          # takes battery voltage readings
      
      robert-hhR 1 Reply Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @Wolli01
        last edited by robert-hh

        @Wolli01 Assuming that with "board" you mean Expansion Board, you can rebuild the same principle with just a few external components, namely a voltage divider consisting of two resistors. The one on the expansion board uses 56k and 116k, but you can as well use identical values like 470k and 470k. Then you have to divide by 0.5 instead of 0.3275. Higher values are better, since this voltage divider will always consume power without an additional benefit. In case of 2*470k ~ 3.5µA. If you do not want that, you have add an external switch for the voltage divider (e.g. an p-channel mosfet transistor). Assuming that the output voltage of a GPIO port with small load is almost the same as the supply voltage, you can also drive the voltage divider from an GPIO output pin.
        Add a small capacitor (e.g. 10 nF) between the ADC input and GND. The noise of the ADC is lower and you might need fewer than 100 samples for your median.

        A few notes about your code:

        • list append is slow. Allocating the list once and then filling it is much faster.
          . you can use adc_samples.sort() for an in-place sort.

        P.S.: Sorry if I confused you.

        W 1 Reply Last reply Reply Quote 0
        • W Offline
          Wolli01 @robert-hh
          last edited by

          @robert-hh
          Thank you for your detailed description.
          But I thought it would be easier to do that without rebuilding anything.

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

            @Wolli01 This is not rebuildung everything, It's just two resistors and one capacitator. Pretty simply.

            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