My Pico is plugged into a Pimoroni Pico Omnibus (https://shop.pimoroni.com/products/pico-omnibus) . . . and powered using 4 x AA batteries (2,000mAh rechargeable NiMH cells) connected directly to VSYS (PIN 39) and GND (PIN 38).
Cases to house 4 x AA batteries are readily available (e.g. https://shop.pimoroni.com/products/4-x- ... off-switch) - The four batteries are held in series, for a nominal output of 4.8V DC for rechargeables (5.2V when fully charged, 4.4V when discharged). Use rechargeable batteries, as 4 x normal alkaline batteries can produce over 6V DC when new, which will damage your Pico.
If you wish to use standard alkaline AA batteries make sure to use only a two or three battery case (e.g. https://shop.pimoroni.com/products/batt ... ith-switch or https://shop.pimoroni.com/products/batt ... and-switch)
Alternatively, If you just want to use a USB power pack to keep your Pico running when you unplug it from your computer (and are not interested in detecting whether it is running from micro USB or battery power), how about using one of these https://www.tindie.com/products/8086net ... al-diodes/ to provide dual redundant power sources via the microUSB connector..
The example code below then uses GPIO 24 to detect whether the Pico is being powered via the micro USB or a battery connected to VSYS and changes the LED flash pattern to indicate this (if battery powered the LED off time is extended from 0.5 seconds to 1.5 seconds).
Code: Select all
import machine
import utime
led_onboard = machine.Pin(25, machine.Pin.OUT)
USBpower = machine.Pin(24, machine.Pin.IN)
while True:
led_onboard.value(1)
utime.sleep(0.5)
led_onboard.value(0)
utime.sleep(0.5)
if USBpower() != 1:
utime.sleep(1)
Power consumption when running this code is approximately 0.1W (19mA at 4.99V, so 4 x AA batteries (@ 2,000mAh each) would keep the Pico running for well over 4 days
The ability to detect the power source (micoUSB vs battery) could be very useful to drive different behaviours when running independently of a computer connection . . . e.g. initialising and data logging to a file when battery powered, but not logging when connected to a computer to allow the previously created/saved log file to be recovered to the computer (see this post https://www.raspberrypi.org/forums/vie ... 7#p1809207 and/or this post viewtopic.php?f=146&t=300275&p=1807232#p1807232 for details of how to implement a corrected RTC when data logging)
The battery should provide a voltage greater than 1.8v and less than 5.5v. Importantly if both a battery and a micro USB cable are connected at the same time a Schottky diode should be placed between the battery positive and VSYS [see section 4.4 & 4.5 of the Raspberry Pi Pico Datasheet https://datasheets.raspberrypi.org/pico ... asheet.pdf] . . . then, as long as the battery voltage is less than that coming in from the USB cable, power will be drawn from the USB supply and not the battery . . . and, when you unplug the Pico from its USB supply, the Pico will keep on running, using power from the battery (and visa versa when you plug it back in).