Power Raspberry Pi directly with Lithium Ion rechargeable batteries

From reading Adafruit’s excellent dissection of the (then new) RPi Model B+ power supply I had learnt (from the schematics) that 5V GPIO pin was directly connected to RT8020AGQW step down DC/DC converter (5v to 3.3V/1.8V) which automatically switches to a low-dropout mode.  So it should be possible to power a RPi B+ with much less than 5V at the GPIO 5v pin. Relevant excerpts from the data sheet:

Two operational modes are available : PWM/Low-Dropout auto-switch and shutdown modes. Internal synchronous rectifier with low RDS(ON) dramatically reduces conduction loss at PWM mode. No external Schottky diode is required in practical application. The RT8020 enters Low-Dropout mode when normal PWM cannot provide regulated output voltage by continuously turning on the upper PMOS.

Rds_RPi

Since I did not have the right equipment to test for this at that time I tried calculating it from the datasheet. Assuming a worst case Rds of 0.5 ohms for the PMOS at a current of 700mA (model B+, camera module, USB wireless) I get a voltage drop of 0.35V across the PMOS. So if we ideally want 3.3v at the output, then VIN should be 3.65V. At this point I should add that I am not completely sure if that is the correct way to estimate the dropout.

Now that I own an adjustable power supply I wanted to test that out. The only RPi I had on hand was a model A+ so thats what I used.

DISCLAIMER: All numbers below are from a very rough test and come with no guarantees. This means that if your house burns down or something terrible happens because of using something I said then I am not  to blame for that.

Test A:

I tried booted the RPi at 5V, with a keyboard and HDMI monitor connected. Then I launched Minecraft (wish the RPi foundation included a stability testing benchmark) and started lowering the voltage. For the short duration of time that I tested I was able to run without any brownouts at 3.5V. Going lower to 3.4v or even 3.45V would cause random reboots, which brings us to the next test.

01945a9c7fc4c34230ff0884c13f99afb23d015780

Test B:

While the RPi was rebooting I increased voltage back to 3.5V but noticed that was not sufficient and the RPi stayed stuck in a continuous reboot cycle. I was able to see the RPi booting up messages but at some point during that it was get reset. In hindsight I should have tried to make a video to figure out when exactly the reset happened. I next tried 3.6V which also did not work. I was only able to stop the reboot cycle at 3.7V.

01a07dcba2cc9da5ee10bc21b2964d116874a85c34

Test C:

Next I unplugged the keyboard and plugged in wireless dongle and again tried lowering the voltage. I was able to sustain a download over wifi with X server loaded at 3.5V.

Conclusion

The calculation was fairly accurate and as expected the model A+ was able to operate at a lower voltage than calculated because of using less current.

Coming back to the title of this post, I went down this path because I wanted to minimize components and was wondering if I could directly power the RPi for my remotely controlled home rover from the Li Ion battery. Searching for lithium ion battery discharge curves I see that at 1C rate reaching 3.5V would be somewhere in the 60% to 80% discharge capacity of the battery. So if I want to use the full battery capacity I should use a step-up converter, but if I don’t care about that I should be able to power up a Rpi with a lithium battery connected directory to Vin. Monitoring the current and voltage to the RPi might also be a good option to ensure stability to raise early warning if the voltage goes too low.

Relevant products:

Adafruit INA219 breakout to monitor current and voltage to the RaspberryPi.

CPS-3205 power supply bought from ebay

Advertisements

My RaspberryPi Config

Setup for first boot

I bought an 8GB micro SDHC card which came with a USB card reader and an SD adapter. I used the windows disk image writer for setting it up with the latest raspbian wheezy image.

Then I powered the card using a usb cable and used a ethernet cable to connect it to my router. I then setup my router to assign The RPi a reserved easy to remember IP address.

$ ssh pi@192.168.1.2

On first login its best to setup the following config using your preferences.

pi@raspberrypi ~ $ sudo raspi-config

At this point I was using ~1.5GB of the card.

Please note that the following tidbits have been scraped from various parts of the internet and I did not really have to figure out any of this myself.

Here is a good index page from the embedded linux RPi wiki for quickly looking up information.

rpi

Installing Packages

Next I upgraded all the installed packages, this takes a while to finish.

$ sudo apt-get update ; sudo apt-get upgrade

The upgrade pushes the card upto ~1.6GB.

General packages

$ sudo apt-get install vim ctags tcsh screen tightvncserver python-setuptools git

Automatically Adjust Clock speeds – Save Power

$ sudo vi /boot/config.txt

arm_freq_min=100
force_turbo=0

Install the cpufrequtils package, which allows control over the CPU speed based on demand and reboot:

$ sudo apt-get install cpufrequtils
$ sudo cpufreq-set -g ondemand
$ cpufreq-info
...
...
  current CPU frequency is 100.0 MHz.

GPIO packages

$ sudo apt-get install python-dev
$ sudo apt-get install python-rpi.gpio

Packages for OS X screen and file sharing

$ sudo apt-get install netatalk avahi-daemon
$ sudo update-rc.d avahi-daemon defaults

Miscallaneous setup

OS X File and Screen sharing

$ sudo vim /etc/avahi/services/afpd.service
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
 <!DOCTYPE service-group SYSTEM "avahi-service.dtd">
 <service-group>
 <name replace-wildcards="yes">%h</name>
 <service>
 <type>_afpovertcp._tcp</type>
 <port>548</port>
 </service>
 </service-group>

$ sudo vim /etc/avahi/services/rfb.service
<?xml version="1.0" standalone='no'?>
 <!DOCTYPE service-group SYSTEM "avahi-service.dtd">
 <service-group>
 <name replace-wildcards="yes">%h</name>
 <service>
 <type>_rfb._tcp</type>
 <port>5901</port>
 </service>
 </service-group>

Note that rfb port 5901 implies :1 display.

$ sudo /etc/init.d/avahi-daemon restart

I2C

sudo vim /etc/modules

and add these two lines to the end of the file:

i2c-bcm2708
i2c-dev

Next for python support:

sudo apt-get install python-smbus
sudo apt-get install i2c-tools

And finally try the following to test:

sudo i2cdetect -y 1
sudo i2cdetect -y 0

Setup config files

~/.vimrc

 set expandtab "et"
 set sw=4 "shiftwidth"
 set smarttab "spaces for tabs ?"
 set ts=4 "tabstop
 set shiftround
 "Indentations and line numbers
 "set number "nu"
 set autoindent
 set cindent "ci"
 set incsearch "incremental search
 set hlsearch "highlight search
 "line break - causes word granularity wrapping
 set lbr
 set wrap
 "Folding
 syntax on
 syntax sync fromstart
 set foldmethod=indent
 filetype plugin indent on
 syntax enable
 "set invlist
 set showmatch "sm"
 set smartcase "scs no ignore case when pattern has uppercase
 set backspace=2 "bs how backspace works at start of line
 filetype on "filetype detection on
 "dont indent when pasting with middle clicks
 set paste
 " Make shift-insert work like in Xterm
 map  
 map!  
 set nocompatible "dont emulate bugs
 " configure command line completion
 set wildmode=list:longest,full
 " setup status line
 set statusline=%F%m%r%h%w\ [%{&ff}]\ [%Y]\ [%07l,%07v][%p%%]\ [%L]
 set laststatus=2 " always show the status line

~/.cshrc

 set prompt="%~ %# "
 bindkey -v
 set history = 5000
 set savehist = (5000 merge)
 set histfile="$HOME/.tcsh_history"
 history -L
 # Make command history (arrow keys) use history search operations
 bindkey -k down history-search- forward
 bindkey -k up history-search-backward
 setenv MANPAGER less
 alias l ls -lh
 alias cls clear
 alias vi vim -p
 alias vim vim -p

Disable root ssh

$ sudo vi /etc/ssh/sshd_config

Change to following:

PermitRootLogin no

Measure Core Temperature

$ /opt/vc/bin/vcgencmd measure_temp
temp=45.5'C

For other options possible with this command run:

$ /opt/vc/bin/vcgencmd commands

Serial port setup

Remove the following text from the /boot/cmdline.txt file:

console=ttyAMA0,115200 kgdboc=ttyAMA0,115200

And comment out the following from /etc/inittab file:
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

You also might want to install minicom for monitoring:

$ sudo apt-get install minicom

To setup the serial port packages required for use with python:

$ sudo easy_install pyserial

Reboot time

As per my rough measurement it takes around 90-120 seconds for the raspberry pi to be able to accept ssh connections after initiating a reboot. I suspect that this is partly because of my slowish class 4 memory card. I was getting much quicker boot times with the 45MBps UHS-I SD card from my camera.

Change hostname

Update it in the following files and reboot:

$ sudo vim /etc/hostname /etc/hosts

And lastly

Once you are happy with your config remember to make a backup img of your card which you can restore if anything goes wrong.
A useful suggestion I found here was to zero out the free space to get better compression.

# cat /dev/zero > /zeroes ; rm /zeroes