It's easy to use the Proto Doubler PiCowbell with CircuitPython to monitor the voltage of an attached lipoly battery with the analogio core module. This module allows you to easily write Python code for accessing basic analog inputs and outputs.
Raspberry Pi Pico ADC3 and VSYS
The Raspberry Pi Pico can use its internal ADC3 pin (GPIO29) to monitor the voltage on VSYS. As a result, you can read the voltage currently being supplied to VSYS (aka the voltage from your battery) with this calculation in CircuitPython:
((ADC3 value * 3) * 3.3) / 65535
CircuitPython Microcontroller Wiring
Plug a Pico or Pico W into your Proto Doubler PiCowbell exactly as shown below. Then, plug in a supported lipoly battery to the PiCowbell JST 2-PH port. Here's an example of connecting a Pico to the PiCowbell with a lipoly battery.
Connect the Pico with plug headers into the Proto Doubler PiCowbell. It should be plugged in with the Pico USB port pointing towards the STEMMA QT port and the USB text on the PiCowbell board silk.
Then, plug in a lipoly battery with matching polarity to the JST 2-PH port on the PiCowbell.
CircuitPython Usage
To use with CircuitPython, you need to update code.py with the example script.
In the example below, click the Download Project Bundle button below to download the code.py file in a zip file. Extract the contents of the zip file, and copy the code.py file to your CIRCUITPY drive.

Example Code
If running CircuitPython: Once everything is saved to the CIRCUITPY drive, connect to the serial console to see the data printed out!
# SPDX-FileCopyrightText: 2024 ladyada for Adafruit Industries # # SPDX-License-Identifier: MIT import time import board from analogio import AnalogIn from digitalio import DigitalInOut, Direction led = DigitalInOut(board.LED) led.direction = Direction.OUTPUT analog_in = AnalogIn(board.A3) def get_vsys(pin): return ((pin.value * 3) * 3.3) / 65535 while True: led.value = True print(f"The battery level is: {get_vsys(analog_in):.1f}V") led.value = False time.sleep(5)
Every 5 seconds, the analog reading from pin A3 on the Pico is passed to the get_vsys()
function. This function calculates the voltage on VSYS and prints the reading to the serial monitor. The screenshot below shows a battery initially plugged in at 4.2V. The battery was unplugged, reading 4.9V from the USB power and then plugged back in, reading 4.3V.
Page last edited January 21, 2025
Text editor powered by tinymce.