DWiskow
Posts: 57
Joined: Sun Apr 09, 2017 1:56 pm

Pico battery power (and detection)

Wed Jan 27, 2021 5:14 pm

Is is perfectly possible to power the Pico from a battery, and it is very easy to use MicroPython to detect whether the Pico is being powered from a USB cable (via VBUS) or a battery (via VSYS).
Pico on Pico Omnibus (powered by battery).gif
Pico on Pico Omnibus (powered by battery).gif (54.26 KiB) Viewed 42940 times

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..
Pico on Pico Omnibus (powered by battery - connection).gif
Pico on Pico Omnibus (powered by battery - connection).gif (45.92 KiB) Viewed 42940 times

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
Pico on Pico Omnibus (power consumption).gif
Pico on Pico Omnibus (power consumption).gif (34.82 KiB) Viewed 42940 times

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).
Last edited by DWiskow on Sun Jan 31, 2021 1:33 pm, edited 9 times in total.

zmarties
Posts: 66
Joined: Fri Jan 22, 2021 6:53 pm

Re: Pico battery power (and detection)

Wed Jan 27, 2021 5:33 pm

Your definition of "on battery power" is somewhat different to mine.

The key states that I want to distinguish are:
  • when the Pico is standalone ("on battery power"), but the power is still being supplied via the USB connector, from a rechargable USB power pack
  • when the system is connected over USB to a host computer (ie. "not on battery power")

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 31862
Joined: Sat Jul 30, 2011 7:41 pm

Re: Pico battery power (and detection)

Wed Jan 27, 2021 5:41 pm

zmarties wrote:
Wed Jan 27, 2021 5:33 pm
Your definition of "on battery power" is somewhat different to mine.

The key states that I want to distinguish are:
  • when the Pico is standalone ("on battery power"), but the power is still being supplied via the USB connector, from a rechargable USB power pack
  • when the system is connected over USB to a host computer (ie. "not on battery power")
If the power is coming in from the same port in both cases, how could you tell where it came from?
Principal Software Engineer at Raspberry Pi Ltd.
Working in the Applications Team.

DWiskow
Posts: 57
Joined: Sun Apr 09, 2017 1:56 pm

Re: Pico battery power (and detection)

Wed Jan 27, 2021 5:47 pm

You are perfectly correct . . . but there are a couple of reasons why "on battery power" requires connection to VSYS

  • most USB Power Packs will automatically switch off unless a significant current draw is present [and in any case more than the Pico typically consumes]
  • the Pico board can't differentiate between two sources which provide the same standard USB voltage on the same connector
zmarties wrote:
Wed Jan 27, 2021 5:33 pm
Your definition of "on battery power" is somewhat different to mine.

The key states that I want to distinguish are:
  • when the Pico is standalone ("on battery power"), but the power is still being supplied via the USB connector, from a rechargable USB power pack
  • when the system is connected over USB to a host computer (ie. "not on battery power")

Ratz Fatz
Posts: 3
Joined: Wed Feb 10, 2021 8:34 am

Re: Pico battery power (and detection)

Wed Feb 10, 2021 8:44 am

Yesterday I set up my Pico using a 3 NiMH AAA Battery Pack connected to VSYS and Gnd and used the same blink program (using sleep_ms() instead). I also measured the power consumption and found that the Pico draws about 25mA when the LED is on and 20mA with LED off.
I wonder why this is so much: according to the "Raspberry Pi Pico Datasheet Chapter 3.1.4" (referring to the hello_sleep binary), the Pico should only consume about 1.5mA (powered via 5V though).
Does anyone have an explanation for this?

mattgomes28
Posts: 2
Joined: Fri Feb 12, 2021 2:28 pm

Re: Pico battery power (and detection)

Fri Feb 12, 2021 3:52 pm

I had a similar setup as you and bricked my first Pico (oops :D ). It was probably (definitely) my fault!

I bought a 4 AA battery pack from an online retailer as I could not get your pack (out of stock). In addition, I bought a set of 4 rechargeable AA batteries from Amazon (230mA). The specs say each battery should output an average of 1.2V, but a fresh, first full charge outputs on average 1.35V, bringing the output of the battery pack to 5.43V. I assumed this was within the tolerated threshold for the Pico. See the full setup in the image below:

Image

Now, once I connected live to VSYS (pin39) and ground to pin40, it worked as expected: the Pico turned n and my "hello world + LEDs" program executed. A few minutes later, when trying to power the Pico from the battery again, I noticed it wasn't turning on. This is the moment I knew I messed up somehow (or the battery output I have is damaging the Pico).

I'm not going to lie, I was using some jumper wires (F/M) to connect the battery pack to the Pico, so I may or may not have touched the same pin with both live and ground from the battery (oops).

My question is: Given the battery setup above, should I be fine powering my Pico with my battery pack? I am a software engineer, who is a newbie to electronics and don't know much apart from what I read online.
Last edited by mattgomes28 on Fri Feb 12, 2021 7:24 pm, edited 1 time in total.

DWiskow
Posts: 57
Joined: Sun Apr 09, 2017 1:56 pm

Re: Pico battery power (and detection)

Fri Feb 12, 2021 4:11 pm

mattgomes28 wrote:
Fri Feb 12, 2021 3:52 pm
output of the battery pack to 5.43V ...

Supported input power is 1.8–5.5V DC, so that voltage provided to VSYS is absolutely fine . . .


... provided it is not applied to any other pin !

PiGraham
Posts: 5128
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Pico battery power (and detection)

Fri Feb 12, 2021 4:15 pm

According to the datasheet:
power supply
chip supporting input voltages from 1.8-5.5V.
Four alkaline cells would be too much but I should think four NiMH cells should be OK.
Two or three cells would be safer.

mattgomes28
Posts: 2
Joined: Fri Feb 12, 2021 2:28 pm

Re: Pico battery power (and detection)

Fri Feb 12, 2021 4:22 pm

DWiskow wrote:
Fri Feb 12, 2021 4:11 pm
... provided it is not applied to any other pin !
I thought so! I might have touched the VBUS pin accidentally.... Lesson learnt.

User avatar
rpdom
Posts: 20889
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Pico battery power (and detection)

Fri Feb 12, 2021 4:26 pm

VBUS shouldn't be a problem. It's the 5V from the USB connector. It goes through a diode to VSYS. The thing that might cause some damage (but I doubt it at that voltage) is that it also goes to a resistor divider to detect when VBUS is present. I'm not sure if that could cause an issue. I doubt it.
Unreadable squiggle

cadotif983
Posts: 13
Joined: Thu Feb 11, 2021 1:24 am

Re: Pico battery power (and detection)

Sat Feb 27, 2021 5:04 pm

If I were to hook up batteries to the pico how would I make sure that I wasn't supplying power through both the USB and the batteries at the same time? Would that cause problems?

blimpyway
Posts: 727
Joined: Mon Mar 19, 2018 1:18 pm

Re: Pico battery power (and detection)

Sat Feb 27, 2021 8:13 pm

You should read the manual, there-s thorough detailing upon combined/multiple power supplies.

cadotif983
Posts: 13
Joined: Thu Feb 11, 2021 1:24 am

Re: Pico battery power (and detection)

Mon Mar 15, 2021 12:27 am

DWiskow wrote:
Wed Jan 27, 2021 5:14 pm
Is is perfectly possible to power the Pico from a battery, and it is very easy to use MicroPython to detect whether the Pico is being powered from a USB cable (via VBUS) or a battery (via VSYS).

Pico on Pico Omnibus (powered by battery).gif


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..

Pico on Pico Omnibus (powered by battery - connection).gif


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

Pico on Pico Omnibus (power consumption).gif


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).
About the last bit, what if the battery power is higher voltage than the USB power when both are powering the Pico at the same time? And what if there was no diode?

PiGraham
Posts: 5128
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Pico battery power (and detection)

Mon Mar 15, 2021 10:33 am

cadotif983 wrote:
Mon Mar 15, 2021 12:27 am

About the last bit, what if the battery power is higher voltage than the USB power when both are powering the Pico at the same time? And what if there was no diode?
It would be wise to arrange for the battery voltage to be below 5V. A diode will prevent USB power from overcharging the battery.

If the battery voltage is > USB voltage current will flow into the Pico from the battery. Typically regulators don't sink current so the higher voltage will apply and supply the majority of current. But you should design to avoid this situation.

If your battery is suitable for trickle charging (NOT Li Ion/ LiPo) you could put a current limiting resistor in parallel with the diode so that only trickle current will pass from USB to battery.

User avatar
PiModules
Posts: 106
Joined: Sun Mar 03, 2013 9:20 pm
Location: Athens -Greece

Re: Pico battery power (and detection)

Sun Mar 21, 2021 10:45 pm

Hi,
We combined WIFI with Extended Power Supply (5.5-18VDC), Reset Button, WiFi , ON/OFF on any power source, simplified UPS, and Battery charger . We just started this new products line and called it Dual in-Line Package Raspberry Pi PICO.
http://dip-pi.com/piot. It is designed by PiModules (http://pimodules.com).

Best Regards
PiMaster
Attachments
DiPPi_5717.jpg
DiP-Pi PIoT
DiPPi_5717.jpg (108.07 KiB) Viewed 38161 times

GavinB-1963
Posts: 2
Joined: Fri Feb 26, 2021 2:21 pm

Re: Pico battery power (and detection)

Tue Mar 30, 2021 12:12 pm

Personally I just use a small portable phone charger - a simple 5000mAh device costs less than 10 euro and provides power for as long as I need over a short USB cable. I use one with a Pico connected to a GPS sensor (PA1010D) and a display to make a small GPS tracker device for cycle / walking trips and for a day outing I've never had a problem.

User avatar
PiModules
Posts: 106
Joined: Sun Mar 03, 2013 9:20 pm
Location: Athens -Greece

Re: Pico battery power (and detection)

Wed Apr 07, 2021 11:53 am

Hi,
Yes, you can, and seems low cost. The DiP-Pi PIOT is addressed to more professional applications i.e. Cars, Solar Panels etc. This is also the reason we implemented extensive ESD protections end others protections. Your solution for hobby is very good. DiP-Pi PIOT with WiFi costs similar to your hobby as it is mass manufactured solution.
Best Regards

alphanumeric
Posts: 3153
Joined: Tue Jan 19, 2016 2:17 pm
Location: Sydney, Nova Scotia, Canada

Re: Pico battery power (and detection)

Sun Apr 18, 2021 8:39 am

I just ordered one of these LIPO Shims for my PICO. It has built in battery charging, and Python code for monitoring battery state.
https://shop.pimoroni.com/products/pico-lipo-shim
I already have the Display Pack, and ordered the Explorer pack with it. My plan is to solder on my header, then remove the black base part off of the pins used by the shim. Then solder it on nice and close to the PICO. I should then have the full normal length of pin to use for whatever I plug the PICO into.

Return to “MicroPython”