Battery monitorng for ‘Enviro Weather (Pico W Aboard) - Board Only’

Hi,

Is there a solution for battery monitoring for this board. ‘Enviro Weather (Pico W Aboard) - Board Only’ ??

I am powering the board with solar cell and the bq24074 Adafruit 4755 board. The battery is a LiPo connected to the charger.

  1. Would be nice to measure the battery voltage directly. How to do that?
  2. Is there interfacing to the adafruit charger board to digitally read the voltage?
  3. Maybe even read out other interesting stuff?
  4. Are there code libraries available to do that?

Cheers,
Gert

Have a look see here,
Design Notes | Adafruit Universal USB / DC / Solar Lithium Ion/Polymer charger - bq24074 | Adafruit Learning System

Pinouts etc are detailed.

  1. put an INA219 in between the battery and the charger
  2. no
  3. some pins to readout the charging status
  4. you will find many INA219 libraries. Watch out that they can deal with negative currents/voltages

The bq24074 does not provide anything in addition, so Adafruit is not to blame.

@bablokb

OK, that is a possibility. However we want to operate in a minimal power consumption situation. I mean that’s why the pico board has this smart sleep mode etc.

I’m wondering to just put a two resistor divider on the battery leads and feed the signal into one of the pico’s A/D inputs for reading. Would require a continuous ground between battery, charger and pico. Of course the current in th resistors has to be shut off. Possibly by putting the ground side of the divider on a pico digital output that would only pull low during measurement and otherwise go to high-Z.

Any code library to do that?

Cheers,
Gert

Before you worry about this, you should change the way you operate. As far as I understood, you send every reading using WLAN - which is very costly in terms of power consumption. Not so much because of the transfer power spike, but because of the needed uptime for WLAN connect and transfer. INA219 power consumption is far below what you have here.

Hi,

That’s exactly why we need to battery monitoring. Let’s establish that and then we can have a discussion about power budget.

Can we get some info on deploying a usable battery monitoring in the pico board? Someone must have developed some code that can be used.

Cheers,
Gert

Hi,

I’ve asked about voltage measurements at Adafruit forum with respect to BQ24074 having continuous ground which was confirmed.

A resistor divider into an analog port will also work. All of the grounds are common.

So I need some code to use an analog port from the pico to read the voltage and most importantly how to embed that in existing firmware and insert into the transmitted data.

Could anyone point to tutorial for that?

Cheers,
Gert

This is code I used to display the battery state on a Pico W + Display pack.

from machine import ADC, Pin
import time
import network
# change to DISPLAY_PICO_DISPLAY_2 for Pico Display 2.0
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY


def get_vsys():
    # Pico W voltage read function by darconeous on reddit: 
    # https://www.reddit.com/r/raspberrypipico/comments/xalach/comment/ipigfzu/
    conversion_factor = 3 * 3.3 / 65535
    wlan = network.WLAN(network.STA_IF)
    wlan_active = wlan.active()

    try:
        # Don't use the WLAN chip for a moment.
        wlan.active(False)

        # Make sure pin 25 is high.
        Pin(25, mode=Pin.OUT, pull=Pin.PULL_DOWN).high()
        
        # Reconfigure pin 29 as an input.
        Pin(29, Pin.IN)
        
        vsys = ADC(29)
        return vsys.read_u16() * conversion_factor

    finally:
        # Restore the pin state and possibly reactivate WLAN
        Pin(29, Pin.ALT, pull=Pin.PULL_DOWN, alt=7)
        wlan.active(wlan_active)


display = PicoGraphics(display=DISPLAY_PICO_DISPLAY, rotate=0)

display.set_backlight(0.8)

charging = Pin('WL_GPIO2', Pin.IN)  # reading this pin tells us whether or not USB power is connected

full_battery = 4.2                  # these are our reference voltages for a full/empty battery, in volts
empty_battery = 2.8                 # the values could vary by battery size/manufacturer so you might need to adjust them

# Create some pen colours for drawing with
BLACK = display.create_pen(0, 0, 0)
GREY = display.create_pen(190, 190, 190)
GREEN = display.create_pen(0, 255, 0)
RED = display.create_pen(255, 0, 0)

while True:
    # convert the raw ADC read into a voltage, and then a percentage
    percentage = 100 * ((get_vsys() - empty_battery) / (full_battery - empty_battery))
    if percentage > 100:
        percentage = 100.00
    
    # draw the battery outline
    display.set_pen(BLACK)
    display.clear()
    display.set_pen(GREY)
    display.rectangle(0, 0, 220, 135)
    display.rectangle(220, 40, 20, 55)
    display.set_pen(GREEN)
    display.rectangle(3, 3, 214, 129)

    # draw a green box for the battery level
    display.set_pen(GREEN)
    display.rectangle(5, 5, round(210 / 100 * percentage), 125)

    # add text
    display.set_pen(RED)
    if charging.value() == True:         # if it's plugged into USB power...
        display.text("Charging!", 15, 55, 240, 4)
    else:                             # if not, display the battery stats
        display.text('{:.2f}'.format(get_vsys()) + "v", 15, 10, 240, 5)
        display.text('{:.0f}%'.format(percentage), 15, 50, 240, 5)
    
    display.update()
    time.sleep(0.5)

@alphanumeric,

Thank you. This is awesome.

Need a little help here, I’m new to this board.

If I want to run my own code to experiment, how do I backup and restore the factory firmware? I"m sure there’s a tutorial out there. :-)

Thanks,
Gert

The factory firmware can be downloaded and re installed.
Use this file and it should be as it was when you first got it.
pimoroni/enviro (github.com)

I usually save the main.py file on my PC as a backup. Then do all my tinkering with a different test file. If I muck things up I just go get my last working saved file.

I have a Pico Enviro+. I’m just running the Pimoroni Pico W uf2. I’m not uploading data or anything like that. I’m just displaying it on the LCD.