Friday, October 3, 2014

Running The Raspberry Pi On Batteries.


Which Model Pi
This is a really easy one. Use the model A. Even with a wireless LAN dongle added, the model A still uses less power than the B. I’m struggling to think of a battery application where the model B would be a good choice. A model A runs on about 115mA vs 400mA or so for the model B.
What about under-clocking?
Don’t bother. It makes almost no difference to the Pi’s power consumption.
Any Power-Saving Tips?
You can save 20mA or so by switching off the PAL/HDMI outputs. Add this to your startup:
/opt/vc/bin/tvservice -off
I just need 5V from the batteries, right?
You could do that, but it’s probably not the best option. Doing so means you have an external regulator (battery –> 5V) and the Pi’s 3.3V regulator (5V –> 3.3V), so 2 places for the precious battery power to be lost.
This is where the 5V input on the Pi goes to:
  • The 3.3V regulator (which then feeds regulators for the remaining voltage levels
  • The USB port
  • The HDMI connector
  • A battery sense pin on the BCM2835
That’s it. So unless you’re using USB peripherals, all the 5V supply is doing is powering the 3.3V regulator. It can be much more efficient to do away with one of the regulators and just operate the Pi on 3.3V.
Even if you are using USB peripherals, they may actually run happily from 3.3V. I have a couple of WLAN dongles and both run just fine like that.
If you do feed 5V to the Pi from batteries, you need a 5V regulator between the batteries and the Pi, and most 5V regulators need in excess of 6V going into them before they can produce that 5V. So now you’ve got 6V or more from your batteries that just ends up as 3.3V on the Pi. In other words, only half the voltage you started with is doing anything useful, and the difference is lost as heat. Bottom line: it’s a waste of power and means you need much bigger batteries than you otherwise would.
So I Can Supply The Pi From 3.3V Only?
Correct. It’s entirely possible to ditch the 5V supply and run the Pi from 3.3V only, using a single regulator between the batteries and the 3.3V line. You still need some voltage on the 5V line, to keep the BCM2835 happy via its VSense line, but 3.3V is plenty for that.
OK, How?
Using an separate voltage regulator, bypassing the Pi’s own 3.3V regulator. There are two options – a linear regulator (as on the Pi, but better) or a switching regulator.
Linear Regulator
Linear regulators are cheap and simple, and produce no EMC (radio interference), but are usually less efficient than switching regulators. The reason is in the process of dropping the input voltage down to the output voltage, the difference is lost as heat. For example, suppose you are using 4 AA batteries to run your Pi. Those produce around 6V together (depends on the type of battery, and the current being used, and how much charge they have left) but this is a typical figure. With 6V from the battery and 3.3V powering the Pi, the efficiency of the regulator is 100 * 3.3/6 which is 55%. Not very good. What does happen though is that as the battery voltages goes down, this loss reduces and the efficiency goes up.
When you choose a regulator, an important thing to look for is the “dropout voltage”. When the difference between the input (battery) voltage and the output voltage drops below this figure, the regulator stops regulating. At that point the output voltage will start dropping and the Pi will soon stop running.
Many regulators are advertised as “LDO” which stands for “Low Drop Out”. Early linear regulators had a dropout voltage of 2V and anything less than this seems to be regarded by the manufacturers as “low”. I disagree. For example the 3.3V regulator on the Pi has a dropout of 1.2V, meaning that the 5V line has to stay above 4.5V (3.3 + 1.2) at all times. With so many dodgy USB power supplies on the market this requirement isn’t always meant, thus causing random crashes and other effects.
much better LDO is the MCP1825S. This has a dropout voltage of less than 0.2V. So, using one of these to supply the 3.3V line, you only need a battery voltage of 3.5V. If you’re using 4 AAs then they will be almost completely flat by the time they drop this low. So, using a good LDO the Pi can continue to work until the batteries are very flat indeed. This is a good thing as it extends the run time.
With the above in mind, what happens if you add more batteries in series? Say you use 6 AAs instead of 4. The voltage to the LDO is higher, which makes it less efficient. All you’re doing is heating up the regulator! The run time will be virtually identical. To get more run time with more batteries in series, you need a switching regulator.
Switching Regulator
Switching regulators aren’t so simple, but these days they are very cheap. They do produce some EMC (radio interference), but in my experience not enough to cause a problem with my trackers. Your mileage may vary. Their big advantage though is efficiency – at least 70% and often higher, compared to typically 50% or so with a linear regulator.
A common switching regulator chip is the LM2596. You can buy these as modules on ebay for just over £1, and they are very simple to use. They are adjustable so you MUST adjust to 3.3V BEFORE connecting to a Pi. That done, they are simply wired to the batteries on the input side and the Pi on the output side.
The dropout voltage for these devices is quoted at about 1V, and efficiency (at full load into 5V) at 73%. So, would these be a good choice for running from 4 AA batteries? Probably not, because the efficiency then is not that much higher than a linear regulator, and the relatively high dropout voltage means that the Pi will stop before the batteries are actually flat. For more AAs, or for running from a 12V lead-acid battery, these are clearly the best option.
How Long Will My Device Run on Batteries?
You can calculate this for a linear regulator from:
Time = Battery_Capacity / Load_Current
and from a switching regulator from:
Time = (Battery_Capacity * Efficiency * Battery _Voltage) / (100 * Load_Current * Pi_Voltage)
Some examples then. My radio trackers typically use around 200mA, an AAA battery has a capacity of 1200mAh (can supply 100mA for 12 hours for example), and an AA is 3000mAh. A switching regulator is about 70% efficient. So:
4 AAAs and linear regulator = 1200/200 = 6 hours
4 AAs and linear regulator = 3000/200 = 15 hours
6 AAs and switching regulator = (3000 * 70 * 6 * 1.5) / (100 * 200 * 3.3) = 28 hours
Notice that adding just 2 AAs and changing to a switching regulator nearly doubles the run time!
For my balloon flights, weight is often an issue. A switching regulator adds weight and, more importantly, it means I have to use at least 1 more battery (because of the higher dropout voltage). Hence I often use a linear regulator even though it’s less efficient. I don’t need a very long run-time I just need it running for long enough for me to find it!
Step By Step – Linear Regulator
This is how I do it; you may wish to do it slightly differently – for example applying power via the GPIO connector. I prefer to wire direct to the Pi, starting with a 0V wire going to the 0V test point (TP2):
P1080209
Next, you need to take out that existing 3.3V regulator. All you really need to do is cut the legs so it’s out of circuit:
P1080210
However I prefer to remove it completely (it saves a bit of weight!). After cutting the legs, hold the board vertically (so the regulator can fall off easily), get a nice hot soldering iron with a large bit, apply some solder to the bit (to help with conduction) and apply to the tab at the top of the regulator:
P1080214
If you’re doing it properly the regulator should fall off after a couple of seconds. Do nothold the iron there for more than about 4 seconds – you may lift the pad off the board altogether. Once the regulator has gone, desolder the bits of leg that are left so the 3 pads are all clear. Next, cut off the capacitor to the left of the regulator – this is the large round metal component. It’s not needed and it’s in the way.
Now, solder a short piece of wire between the large pad and the small one to the right. What you are doing here is connecting the 5V and 3.3V rails together.
P1080218
Next, prepare the regulator. This is the MCP1825S 3.3V regulator I mentioned earlier. If you use a different model check the pinouts – they will probably be different!. We aren’t connecting to the tab, just the 3 pins. From left to right, they are Vin (battery +), GND (0V) and Vout (3.3V). bend the Vout pin down and make a right-angle as shown below. Cut the other pins short (cut at the shoulder), and tin all the pins (apply some solder):
P1080220
The bent pin will be soldered to the large pad. This places the new regulator above an unpopulated part of the Pi, however to be safe place some insulating tape on the board so there’s no danger of shorting anything out. Apply some solder to the large pad on the board, then hold the regulator on the board so the bent pin is on that pad. It should now take just a moment with the soldering iron bit on that pad to solder the regulator to the pad. Once it’s in place, solder the centre pin to the remaining pad vacated by the old regulator – this is the GND connection. Finally, solder a flexible wire to the remaining pin – this is the +ve line from the battery.
P1080225
I strongly suggest you fix this wire down so that no force can be applied to the regulator if the wire is moved. I like to tie a knot in the wire then run it through the mounting hole in the middle of the Pi.
And that’s it!
Step By Step – Switching Regulator
  • Remove the regulator as above
  • Solder the 3.3V and 5V lines together as above
  • Connect the “OUT-” pad on the regulator to the TP2 (GND, 0V) hole on the Pi
  • Connect the “OUT+” pad on the regulator to the TP1 (5V and now 3.3V) hole on the Pi
  • Connect the “IN-” pad on the regulator to the “-” terminal on the battery
  • Connect the “IN+” pad on the regulator to the “+” terminal on the battery
What If I Do Need 5V?
Well, first, check that you do. My USB WiFi dongles don’t – they run just fine on 3.3V.
If you do need 5V, you have 2 options:
  • Leave the 3.3V regulator in place, and supply 5V to the Pi as usual (preferably using a highish battery voltage – 12V say – and a switching regulator
  • Use TWO switching regulators, one for 3.3V and one for 5V. You do then need to remove the Pi 3.3V regulator as above

1 comment:

  1. Hello sir, by just light reading this blog, you seem the right person to ask this newbie question. I just got me a raspberry pi2 model B. I am thinking of powering it with a USB powerbank via micro usb port of the pi2. Will a 1A, 2A or both port of a powerbank on the market a good buy for booting up my pi2 model B straight out of the box without any hard modding it or any board attachments. I don't want to damage it and it is very hard to get

    ReplyDelete