This Instructable is for the design/prototyping of the custom power supply, power management, monitoring and interfacing electronics design for PInebox (a portable Raspberry PI computer )
The design process went from lots of bits of paper with design fragments, through LTSpice simulation for some testing and tweaking, before a few cycles of schematic drawing in EagleCAD, breadboard building, testing, re-tweaking, and lastly PCB layout.
I'll skip past the paper scribbles and multiple revisions, and jump straight forward to clips taken from the current Eagle schematics and original LT Spice simulations.
The project is split across three 10x8cm PCBs, with some additional smaller PCBs (all on a 10x8cm panel), and is broken down here into functional sections. There's a lot of small but individually useful parts to this, so let's get stuck in!
EDIT DEC 2015: Some corrections have been made to the design as a result of the actual PCB build -- so check all component values etc. with the version linked here ...
Step 1: Requirements
Collectively, this project/boards provide all this ...
- Flexible power input (wide voltage range, AC or DC) for wall power
- Low cost NiMH batteries for ease of charging and cost reduction
- Simple integrated DC-DC boost battery charger with temperature-rise cutoff
- Efficient DC-DC buck converter down to 5V from any available power source (external power takes priority)
- Overvoltage protection on 5V rail.
- Hardware and software power-saving methods for non-essential peripherals/processes (case lid closed/battery getting low)
- Hardware power cutoff in event of battery depletion
- Power on/off/suspend and system reset switches
- Indicators for power/battery/charge status
- Indicators to expose wired network, wifi network, USB memory and system SD card activity lights
- IO expansion for the Raspberry Pi to preserve Pi's own IO pins, with which ...
PI monitors request for power off/shutdown/suspend from user
PI can turn off its own power at shutdown
PI knows if the case lid has been closed (power saving, and side-view-camera rotation)
PI is warned of low battery, and can monitor pack voltage
PI can know whether it's on external power/battery power
PI senses camera "spinner" direction and drives 2 x LED flashes for pictures/video
- Pass through access of GPIO port for further project development (with boosted 3v3 rail and boosted/protected 5v rail)
- LIRC (Infra red) TX and RX (for remote control of camera and other uses) with selectable PI GPIO usage (or pass these pins through)
- RS232 Serial port, selectable PI GPIO usage (or pass these pins through)
- Pass through of 2 audio jacks (from USB soundcard line in and HDMI PI line out) to rear panel.
The upper and lower boards are interconnected with a 26 way IDC flat flexible lead that passes through the hinge, additionally the Raspberry Pi's IO port is brought from the upper case section, into the lower, with a 40 way IDC lead.
Step 2: Power Requirements
To work out the battery size required, select appropriate DC-DC converters, and to select appropriate FETs for switching, it's a good idea to have some idea of the current drawn by various components on the +5V rail. These are all measured, unless otherwise stated.
- Raspberry PI B2 (bare board): Off = 66mA, Idling = 206mA, Low usage = 300mA, Full 4 core hammering = 420ma (web)
- Camera Module (Activity LED disabled): 160mA = stills (web), 260mA = video (web)
- HDMI PI Screen: On = 1.12A
- USB Fixed Devices: 16G Memory stick = 54mA, WIFI dongle = 150-200mA, Audio = ???mA
- USB Switched Devices: 4 port hub = 52mA, Wireless Mouse = 30mA, Wired Keyboard = 11mA
- LED Flash: Front = 100mA, Rear= 32mA
- LIRC: Transmitting = < 100mA
All of the above are provided by a 3A 5V DC-DC buck converter from the battery or external power supply.
For a 12V external input, assuming a max 2.5A load on the 5V rail, that's about 1A max drawn from external power.
For the 19V/2900mAh internal battery pack proposed, that would instead be a maximum draw of 660mA, and give a minimum runtime of just over 4 hours.
Of course, with power saving, especially turning off the display, this increases.
Additionally, when the internal battery is charging, the external power supply will be powering the charger's DC-DC boost converter too, so how much to add?
Using a 12V external power supply to test the DC-DC converter's behaviour/efficiency :-
- Internal battery flat, charging at C/10 (300ma in battery) = 840mA external draw
- Internal battery full, charging at C/40 (60ma in battery) = 240mA external draw
So an external power supply should be about 12V/2A. For higher voltages, lower currents will be drawn, and vice-versa.
Note: I chose NOT to use a commercial Lithium based "power bank" unit -- for a number of reasons.
- They are more expensive than equivalent capacity NiMH batteries.
- Very few can charge AND allow the connected load to run.
- They mostly provide no means to monitor the available power/voltage, so no warning that the battery is about to expire.
- The output voltage is fixed at 5.0V -- really needs to be higher.
- And worst, the "mAh capacity" is always quote as that of the single cell inside, at 3.1V. Which means that a "10,000mAh" pack (3.1V) works out to be more like 6200mAh at 5.0V (or less)
The proposed pack above (19V/2900mAh) is about 11000mAh equivalent at 5V. Big enough!
Step 3: Parts List
The pictures above show the DC-DC converters and batteries used.
The red PCB is an 8-23V to 5V buck converter, to provide the main power rail, from eBay.
Below it is a non-functional piece of junk, a fake knockoff of one of these with down-rated components (the output high-current Schottky diode is replaced with a 1A cheap diode, poor quality silkscreen, and most importantly -- non working due to main IC being internally shorted, output voltage always the same as input voltage!). I bought two of these, both were the same. And that's the downside of eBay ...
A different module (second picture, also from eBay) was used instead. At least this one works!
The batteries were own brand NiMH batteries from 7dayshop.com fitted into a couple of 8xAA battery holders.
The FETs selected were chosen for their low Vgs (switch on) voltage -- they must work at 5.0v, for their low RdsOn (resistance when switched on, to avoid losses), and for adequate current rating.
A full parts list is attached below, which has had changes made in the final version linked here
Step 4: SMD Breakout Board
As some of the parts are SMD, it's difficult to use with breadboards. I have no commercial "breakout" boards, so used the saltwater etching technique from this instructable combined with laser-toner-transfer using a glossy magazine.
In EagleCAD, I designed a breakout board to hold 2 x 14 pin SMD ICs and 5 x SOT-23 plus 5 x SOT-223 FETs, brought out to 0.1" pads that can take pins or wires. I then exported the copper side image, and using GIMP, flood filled the non-track areas, mirrored and printed it. Flood filling the non-track areas reduces the amount of copper to be etched.
Having scrubbed down some scrap copper PCB with abrasives to get it clean, then wiped it over with isopropanol (IPA), the transfer paper was ironed on, soaked in water and gently brushed to remove the paper, and then electrolytically etched in saltwater, using a current limited bench supply.
One electrode is soldered to the PCB, the other is a large copper wire wrapped in cloth to prevent it shorting to the board, and this is used as a brush over the board.
After etching, once the toner is cleaned off, and any shorts checked/cleared, the holes can be drilled (hand held dremel, fine drill bit).
It's a bit rough. OK it's very rough. But it works. Now I can fit SMD FETs onto a breadboard!
Step 5: External Power
This DC/AC universal input charges the internal battery when external power is present, and also powers the main computer in preference to batteries.
Because of the bridge rectifier at the input, J201, a 2.1mm DC Jack, takes 10-18v DC (any polarity) or 9-15V AC to allow versatility in use of external power supplies. I didn't want to be tied to a particular PSU.
Typical current required here (at 12V) on a quick test in prototyping, draws 400mA for Raspberry PI, camera and screen together. 270mA of that is just the HDMI PI screen!
The battery charger draws an additional current of 240-840mA (again at 12v) when operating.
Step 6: Battery Power
This runs the computer when used as a portable device. The battery pack was first charged and conditioned on a Pro Peak NiMH charger during testing, and comes out about 2700mAh cycle capacity, which should increase with a few more cycles. This charger was also used as a 500mA load to simulate a load on the battery in testing.
By using this higher voltage pack, and converting down to 5.0V, it means that the 5.0V rail can be maintained over the whole useful capacity of the battery. Also, every extra cell adds to the capacity of the pack: Higher voltage here means lower current drawn by the DC-DC converter to achieve 5V
Using 16 x AA 2900mAh NiMH batteries gives an operating voltage range of 16.0-23.0v, which is just within the input range of the buck converter (max 23-24V).
2900mAh at 19V approx = 55WH (watt-hours) capacity, which could provide 5V at 1A for about 10 hours.
To protect this battery, at 1.0V/cell (16.0V) a "low battery" circuit will drop unneeded loads to preserve battery life, and initiate an "imminent" shutdown.
At 0.9V/cell (14.4V) a hardware under voltage lockout (UVLO) will operate to stop the buck converter and cut power completely. More on this later.
A polyfuse (self-resetting fuse) is placed in line with the battery to provide protection against short circuits, value 1.1A
Step 7: DC-DC Boost Charger/Current Limiter
This is the NiMH charger. It takes the available external input voltage, boosts it to 29.0V, then current limits at C/10 into the battery pack. As soon as the battery pack starts to become noticeably warmer than ambient temperature, charging is reduced to C/50. This can continue indefinitely, keeping the battery topped off.
LM2577 Boost Module specs: Input: 3.5-30V, 3A Max draw. Output: 4-35V.
In this application: Input: 10-18v DC. Output: 29V
Warning: Initially power the module at a low (5V) input to discover the output set point. To increase the voltage, I had to turn the trimmer anti-clockwise while measuring the output, and set it to 29V. Only then recheck it with a 12V supply, if it's still 29V then it can be connected into circuit. Otherwise it is possible to damage the module, if you start with a higher input voltage and pot is at the wrong end.
The current limiter is the standard LM317-as-current-limit circuit, with an additional couple of transistors to change the current limit.
IC202 maintains 1.25V across "out" and "adj", which means 1.25V across "R" when 300mA (or 60mA, trickle) is flowing.
Using V=IR, or rather, R=V/I
R=1.25/0.3 (4.16 Ohms) or R=1.25/0.06 (21 Ohms).
As a test, with a discharged battery pack connected, calculate and check that R201 at 4.1 ohms provides about 290-300mA constant current into the battery pack. This is the C/10 rate, which can be maintained for 10-12 hours maximum.
Then with a fully charged battery pack connected, now check R202 (which should be about 17 additional ohms), so that R201+R202 in series provide 50-60ma constant current, this is the C/50 rate, which can be maintained continuously.
R201/R202 need to be 1W resistors, as they dissipate some heat.
D201 is important, as it prevents leakage from the battery back into the charger, when the charger is unpowered. Measured at < 1uA leakage.
IC203A/TH201/TH202 provide the temperature cutoff, by sensing the battery temperature vs. ambient temperature.
When the battery pack is fully charged, it will start to warm up. This means the charger needs to stop. TH201 must be in physical contact with a cell in the battery pack, and TH202 should be away from any hot components, sensing the "air" temperature in the case.
The temperature trip point is set for ambient temperature + 13'C (which is quite conservative). Due to hysteresis (that's R207), the charger cannot restart until the battery temperature falls to about 10'C BELOW ambient -- which is impossible! Without R207, the charger would cycle in and out, keeping the batteries hot. Bad.
Due to C208 being larger than C209, which causes an imbalance at power-up, the charger will always start in C/10 (bulk) mode when power is applied. If the batteries are already fully charged, the charge cycle will stop quite quickly. If the batteries are still warm, it will stop within seconds.
IC203B is purely to drive the charging LED403 (not shown here), which indicates bulk charging is taking place. It goes out when trickle mode begins.
To set the trip point, set VR201 to the high temperature end (fully CCW -- not CW as previously written), and monitor the charging battery pack temperature vs ambient temperature (with two thermometers). When the target temperature is reached (e.g. ambient temperature + 13'C), turn the pot back slowly until charging just stops. This should be around the centre of the trimmer's range.
In my prototype, with an ambient temperature of around 24'C, pin 3's reference voltage for "trickle mode" is 11.2v, and in "charge mode" 17.4v. This means that if the voltage at pin 2 (battery temperature) goes under 11.2V it will restart charge, or goes over 17.4V it will stop charging.
Without the hystersis, it would cycle in and out around 14.5v! Bad.
Note: To get P2 down to 11.2V = 14'C which is battery below ambient. Batteries can't get colder than ambient.
You can dab a discharged 1uF cap from pin 3 to ground, briefly, to force trickle-charge during testing to discover and check the two reference voltages at pin 3, to get some idea of where the cut in and out points will be. Also bridging the battery thermistor with a 10K resistor forces trickle charging (by making the battery appear hot!)
Attached: Table of behaviour of the charger ... this is using this charger circuit and temperature cutoff, once the cutoff was correctly dialled in.
Step 8: Power Isolator
Switch S101, mounted in the base of the computer, is to stop the battery draining into the startup supply/DC-DC converter if the computer is not in use for a longer period (days/weeks). There is a small leakage (low mA) always present when the computer is "Off" otherwise.
It is NOT intended to be used to power off the computer in normal use! This is why the physical switch is recessed in a depression under the computer.
EDIT: The battery can not be charged with this switch in the "off" position. Because if the battery can be charged with the switch in the off position, the 29V feed no longer reaches the CMOS power supply. This accidentally prevents it running on external-power-only should the battery fail. Fixed in the final build.
Step 9: CMOS/Startup Supply
I needed a power supply (with low drain) to be used just for powering the on-off circuitry (all CMOS). The battery (range: flat 14.4v, to 27v when being charged) is dropped to a non-critical 9-15V rail. This is always connected to the battery, so must not waste power. Leakage into this is typically low uA's when on battery alone, which is what matters.
Input Leakage Output Condition
26.5v 265uA (14.4v out) Battery disconnected, charger running (abs max)
23.7v 14.4uA (14.4v out) With charged battery, charger running (max)
15.2v 0uA (7.5v out) With "dead" battery (abs min)
ZD101 (value adjusted later) scrubs off most of the excess voltage, to leave ZD102/Q101 regulating the rest.
Step 10: Power Source Detect/Select
The buck converter has maximum input of 23V, which is exceeded when the battery is being charged (possibly up to 29V if the battery gets disconnected). Also, it's hard to control charging current INTO the battery if it's also being drained by a DC-DC converter. And finally, it's pointless charging batteries from an external source (boost) only to have to convert (buck) back down.
For all of these reasons, when external power is available, the battery pack is disconnected from the load, so that the battery only charges.
Q102 detects external power is available, Q103/Q104 cut the battery off. D105/D106 passes the higher of the two voltages on to the DC-DC converter.
Note that no matter what voltage is passed externally, it is automatically "higher" than the cut-off battery! So external power take priority, always.
A signal is sent to the PI that we are on external power, so we can know whether to do software based power saving stuff that only applies when on battery. This signal is TTL compatible (0.0V/4.2V) which is fine for the 5V tolerant IO chip I'm using.
IC101B (spare gate) is used to drive the External power LED. ZD103 is to stop it dimly lighting the LED when on battery (annoying!)
EDIT: About 10V for external power will be detected -- was 5V but that was fixed in the final build.
Step 11: On/Off/Suspend/Halt Switching
The starting point for this module is the Press ON - Hold OFF latching circuits app note here.
P10/12 of IC101 activate the power switching line (circuit shown later)
A momentary action button S402 (not shown -- on the keyboard) connects SWT_!PWR to ground.
For the first 10 seconds after battery power is applied, it will remain switched off and will not switch on.
A brief press will turn the power on.
Subsequent brief-short-medium presses will not change the power state, but can be sensed by the RPi in software, by GPIO, to request suspend (short) or shutdown (medium) operations. This TTL compatible GPIO input from power switch ranges: 0V to 4.9V
Pressing and holding S402 for over 4 seconds will force the power to turn off (with possible consequences for SD card/Memory stick corruption, not normally needed, but if it's crashed ... )
Once the RPi has noted a suspend/shutdown request, all handled in software, it will signal that the power should be turned off in its final shutdown scripts. See "Soft off". There also needs to be a hardware delay to prevent an immediate power-off during shutdown.
An AC drive signal is used, so that no accidental "hi" or "low" GPIO output cuts power in error. C108-Q107 detects and accumulates an AC signal, if it lasts long enough.
Two monostables (IC102A-D) implement the delay: Mono 1 is 60 seconds, and Mono 2 is 0.1 second, so that about 60 seconds after the Pi signals, a brief cancel pulse (0.1 sec) is applied to the power latch through D108.
LED401 (not shown) shows that power is on, it is connected across the 5V rail.
Step 12: DC-DC Buck Converter Mods
This KIS3R33 module is based on the MP2307DN chip, and is widely available on eBay.
Specification: 4.75V-23V input, 3A max output current. In "shutdown" current drops to just 1uA.
In this application, I'm using 8v-23v range on input.
Both of these mods are based on techniques in the MP2307/KIS3R33 datasheets.
As supplied, the module provides 5.0V. For the Raspberry PI, 5.25V is recommended. Further, as this has to pass through an FET or two (with a small loss), plus connectors etc. I decided to increase the voltage. An extra wire is attached to the module to bring out the voltage-adjust pin, and a resistor (R125) is connected to ground to raise the voltage.
There is an internal adjustment resistor, which I can't see or measure, so finding this value was "experimental".
Starting high e.g. 200K in parallel, and working down, I measured the output voltage into a non-critical load. An additional 62k gives 5.27v offload.
This may need further tweaking later to ensure 5.25V measured at the Raspberry PI. This way there's no "low voltage rainbow square" on the PI, which indicates low voltage
As supplied, the module is always powered on. There is an "enable" leg available, which has dual purpose: If grounded, it stops the module (disable/shutdown -- technically this raises the UVLO so high that the module cannot operate, so it stops). Having said that, it also controls the under-voltage lockout (when floating, almost any voltage is acceptable). I brought this out on an extra wire too. This will be useful in a moment!
Step 13: Shutdown/UVLO Settings
With the DC-DC converter's "enable" leg freed above, it's now possible to electronically enable and disable the power by stopping the buck converter -- this is driven from the power on-off latch chip via Q106.
The Under Voltage Lockout (UVLO) stops the DC-DC converter from operating if the battery is depleted, or the external input voltage is too low. There are two different levels selected. One for battery power, and one for external power. On battery: 14.4V (0.9V/cell), on external power: 8V
The MP2307 datasheet shows the UVLO calculations, which are repeated on the schematic.
- R114 is used when on external power: 43K=(8.1V minimum at input).
- R114+R113 in parallel via Q105 when on battery: 43K paralleled with 36K gives (14.4v at battery)
Note: UVLO as measured at the DC_DC converter input is not the battery actual voltage/external input voltage due to losses in FETs/diodes so should be adjusted for 14.4V at the battery and 8V at the DC input.
Setting/checking these is best done with an external variable PSU, in place of the battery/actual PSU.
C103/C104 prevent glitching when switching from external to internal power and back, by "slugging" this point to slow its reaction to the changeover. Otherwise the converter drops out momentarily!
Step 14: Overvoltage Protection
This is designed to open up the power rail to all 5V items if the output of the buck converter rise to 6V or above. A failure of the buck converter could deliver over 14V to the PI/display and other expensive smoke generation components ...
ZD104/D109 set the cutoff voltage.
D109 adds approximately 0.3-0.4V to the Zener voltage, plus a further 0.7V for Q108's b-e junction.
Q109/Q110 are paralleled for increased current capability. FETs share loads nicely when paralleled, much better than bipolars.
The cutoff voltage is best checked with a variable PSU input instead of messing with adjusting the buck converter, so that the cutoff point can be found accurately. The cutoff voltage is subject to tweaking if the DC-DC output voltage is raised further (see above). In theory, this circuit should never see action ...
Step 15: Power Saving (hardware)
When the case lid is closed, certain items can be fully powered down in hardware, increasing battery life. Q112 and Q113 are operated in parallel, but not fully paralleled, it's just to split the load. I may link them together in future with a PCB mod. EDIT: I did decide to link these to share the load here.
Q112: General 5v cutter: Cuts powered USB hub and any rear USB peripherals, cuts power to USB keyboard (can't access it with lid closed), and USB wireless mouse receiver (no use, can't see the screen). Also cuts power to camera flash.
Q113: Cut power to HDMI PI screen (can't see it with case closed)
Q111: Cuts off some of the keyboard LEDs to save power, as they can't be seen if the case is closed.
Note that the HDMI Pi screen will return to its "on" state automatically when power is re-connected.
Step 16: USB Hub Mods
The four port USB hub used can be powered either via the USB host lead (top left) OR via an external jack (bot left). I modified this hub so it is only powered via the DC jack -- this is so that the Raspberry PI does not attempt to continue to power the hub and peripherals. It also means that it will not back-feed the PI with 5V, an unwanted feature.
Without this mod, it would be impossible to "power save" the USB keyboard/mouse/hub, as the RPi would continue supplying 5V.
The mod is simple, just open the USB hub, and "cut the red wire". This is the 5V feed from the PI, and needs to be insulated and tucked out of the way. Now power is only supplied from my switching FET above, via a flying lead, into the jack.
Step 17: PI-3v3 to RS232 Adaptor
This is the classic MAX232 converter circuit, but using a MAX3232CPE which is 3.3V logic compatible. The output levels are +/- 6V.
The standard Raspbian configuration is a serial console login tty, set for 115200 baud/8 bits/No Parity/1 Stop bit, which can be changed in software to free the port up to be used by user software.
Step 18: 3V3 Supply
This provides a 250mA 3V3 supply for parts of my logic, the LIRC module, RS232 port etc.
Rather than load up the Pi's own 3V3 supply, which has limited current, I've used a separate regulator from my 5V supply. This also has some spare capacity to provide 3V3 for prototype boards attached to the 40 pin GPIO connector, in place of the PIs supply.
No polyfuse protects this 3V3 line.
Step 19: Speaker/Audio In/Out Jacks
This brings the two audio paths down to jack sockets on the rear of the computer.
1) HDMI Pi screen's stereo audio output, which drives the internal speakers OR external headphones.
2) The USB soundcard's line in.
The USB soundcard's mic input is connected directly to a mic in the lid, so is not shown here.
EDIT: Picture should should show "USB LINE IN", not out ... design changes ...
Step 20: Raspberry PI IO Passthrough
A 40 Way IDE lead passes the whole RPI GPIO connector down to the lower board, via the hinge, to CN201, where it re-appears as a 40 way plug CN202. This is for development projects to be plugged onto when the keyboard is removed for access.
Connector CN204 steals power (5V via polyfuse F102 -- value to be decided but probably around 250ma, and also 3V3) from the lower power board. These are used to provide boosted/protected 3V3 and 5V rails for the IO connector.
Solder jumpers are provided to reassign IOs unavoidably used by Pinebox (anticipating an IO clash for other projects!). These are joined one way or the other, depending on whether the Raspberry PI IO pin is to be used for a PInebox function, or to be passed through to another project.
Pi Func Pi Pin JumperLbl "Right/Up 2-3" "Left/Down 1-2"
GPIO14 8 ST14/201 GPIO14 RS232 TXD
GPIO15 10 SR15/202 GPIO15 RS232 RXD
GPIO17 11 LT17/203 GPIO17 LIRC TX (Default)
GPIO18 12 LR18/204 GPIO18 LIRC RX (Default)
GPIO23 16 LT23/205 GPIO23 LIRC TX (Alt)
GPIO24 18 LR24/206 GPIO24 LIRC RX (Alt)
Warning: Don't set both LIRC TX (203 with 205) or both LIRC RX (204 with 206) options at once or GPIOs will be bridged together.
Step 21: GPIO Expansion
To save on using up valuable built in IO pins on the main PI IO port, I borrowed the Pi's I2C port, and used two expander chips. This is pretty much straight off the app-note examples for these chips.
Support for these chips is built into Raspbian, and they both run on 5V and are therefore 5V tolerant, and can connect to a 3V3 I2C port.
Digital I/O: MCP23008: 8 bit port, with programmable input/output/pullups Supported by the "WiringPi" library for testing
Used for: Power Control (4 inputs, 1 output), Flash control (2 outputs), Camera direction sense (same 2 as inputs), leaves 1 spare digital I/O (on Pad 316)
To avoid clashes with other I2C devices, the I2C address by default here is 0x27. Solder pads SJ303=b0/304=b1/305=b2 can be bridged to alter the address over the range (0x20-0x27), bridging the jumper changes one address bit from 1 to 0.
Analog I/O: PCF8591: 1 ADC, 1 DAC, 4 input mux Supported by the "WiringPi" library for testing
Used for: ADC1: Battery Voltage. ADC2,3,4 spare (Pad 318,319,320) and DAC1 output spare (Pad 317)
To avoid clashes with other I2C devices, the I2C address by default here is 0x4F. Solder pads SJ306/307/308 alter the address, as above, over the range (0x48-0x4F)
Step 22: Software Battery Monitor
Battery level monitoring is performed in software. This circuit drops the battery voltage down, then scales it for the ADC (range 0-5V)
The scaling has been chosen so that an input (battery) voltage of 14V is 0.79V at the ADC, and 25V is 4.3V at the ADC. This best covers the range of the battery from flat to charging, with a little room at the ends for over/under.
Calibration will be done in software.
I know that monitoring pack capacity by voltage is not the most accurate way, but it gives a simple indication. My plan is to calibrate the battery from "fully charged" to "low battery" into a fairly constant load, and record the voltage vs time to estimate remaining battery life.
This can be done in software, recording the voltage every (x) seconds, starting from when external power is removed, until shutdown.
This table of results would then be stored and used for future battery calculations,and would be repeated as the pack ages, or if the cells are replaced.
Step 23: Hardware Low Battery Detect/Power Save
When the battery level starts to get "low" (1.0v/cell = 16V) this circuit detects this. Non-essential loads are ditched to preserve remaining battery power, and the Raspberry Pi is signalled so it knows to begin a timed shutdown (e.g. halt in 5 minutes). The "Low bat" GPIO input ranges 0.9V to 4.4V
Other software techniques could include reducing the number of cores in use, altering the clocking speed of the PI, suspending certain tasks, shutting off wifi, anything to save power!
Additionally, a "low battery" LED (LED404 not shown) is lit to explain why the screen and keyboard just dropped off!
Hysteresis (R308) is added to stop the power cycling in and out when the loads are removed. It may need adjusting further ...
Measured: With voltage falling: 16.0V "LOW Battery" triggered, voltage rising 17.9V "Power OK", which gives 1.9V hysteresis. Enough?
Adjust VR301 pot for 16.0V cutoff (when falling), again an external bench PSU is used to adjust this, instead of batteries.
Connecting an external power supply will override the "Low Battery" warning. The charger will easily raise the battery voltage to over 18V. This change will be detected by the GPIO line, and an impending shutdown can be cancelled in software. The screen/keyboard will also be re-powered, and other software changes undone.
Also connected here is the "case lid closed" reed switch S403 (not shown). Closing the case will drop the same loads off, but is signalled separately to the PI -- closing the case won't trigger a shutdown, and could probably also avoid dropping WIFI etc?
Case close switch GPIO ranges 5.2v to 0.0v. Near enough to be TTL compatible.
Step 24: Camera Direction/Flash
Two GPIOs are used to drive the front and rear flashes/lights for the camera spinner/module. The same GPIOs are used as inputs to sense two micro switches for camera-direction sensing. (Front, back, side, off)
By default, these pins are left as outputs, state=0, to keep the lights off.
To read the camera direction switches, you flip to input, read them, set as output again.
To fire flash, set state=1, wait, reset to state=0,
As inputs: Weak pull ups (47K, R411/R412, not shown here) are used so that switch position (open/closed) does not interfere with LED drive (forcing it on or off!): Voltage swing measured as inputs as 0.0v (switch open), 3.5v (switch closed)
As output: Zener ZD303/304 provides a voltage drop/differential so the transistor b-e junction doesn't drag down voltage at GPIO node to 0.7v (low) all the time!
The visible components of the flashes are on two small helper boards mounted facing out of the case, as are the pullup resistors and camera spinner switches.
Step 25: LIRC Driver
This is a LIRC driver, based on the circuit on that linked page, by "Tamas Tevesz". It uses the TSOP4838 receiver module.
It's used to send and receive infra red control signals, e.g. to trigger the camera or remotely operate features using an existing spare IR remote control.
Series resistor R320=30R is selected for high current into the 2xLEDS, C310=220nF in parallel allows for larger pulses but ONLY if being actively driven. This protects against the transistor getting stuck on due to rogue GPIO drive.
The visible components are on a small helper board mounted facing out of the case.
It's driven by two GPIOs on the actual Raspberry PI -- not my expansion chips. Which GPIO? Well, that's selectable with the solder jumpers in step 20.
Step 26: LED Repeaters/Hardware Mods
Activity LEDs are very useful, but sadly they are all tucked away on the PI and peripherals in the lid. Four LED signals have been collected and brought out here.
To get the needed signals from the PI means hijacking some test points into a small 5 way connector (part of a turned-pin IC socket). While I was in there, I stole the I2C bus signals too, for the DIO/ADC chips above.
- 1: Net "Green" (PP22): Off 3.3v, On 1.4v "Activity"
- 2: Net "Yellow" (PP23): Off 3.3v, On 1.4v "Link/Speed"
- 3: SD Activity (from PP13): Off 3.3v, On 1.9v "SD Activity"
- 4: I2C DA (IO Conn pin 3) "I2C data"
- 5: I2C CL (IO Conn pin 5) "I2C clock"
EDIT: SD Activity actually taken from LED other side, in final design!
To get the needed signals from the Memory stick and WIFI adaptor needs similar hacks, fortunately only a single pin. You will have to find these signals for yourself, I tested both sides of the LEDs in mine to see which gave a useful voltage variation, and which way round was "active". It depends whether the LED is connected to +5V or ground, where the series resistor is, and whether the light is "on, but blinks off for activity" (like memory stick) or "off, blinks on for activity" (like for wifi).
- Memstick: On 0.1v, Off 3.3v -- this is a usable swing!
- WIFI: On: Low (briefly) Off 2.6v -- as is this.
If another WIFI/Memstick is used that works differently (SJ301, SJ302) may need to be bridged/unbridged to reverse the LED sense. That's why the jumpers are there.
The necessary signal is brought to a single pin, using a fine insulated wire, and mounted into the plastic case of the device. A dot of glue holds the pin in place -- it's pushed in from outside, then the wire soldered. These pins are a just a single pin removed from a turned-pin IC socket. The mating "plug" will be made in the same way.
To drive my repeated LEDs, I used a 3V3 74LVC86 (Quad XOR) chip. This allows the sense of the memstick and WIFI LEDs to be reversed, a trick I've used before when designing for handling signals with unknown/liable to change sense.
The SD card activity light (and network lights) have known, fixed behaviour on the Pi, so have no pads to invert them.
Also the XOR function is needed to sort out the RPi network LEDs so that activity is indicated on a single LED :-
- Link Active My LED
- 0 0 0 OUT (link and active = plugged, but idle)
- 0 1 1 LIT (link, no active led = active (because active LED blinked out)
- 1 0 1 LIT: Actually don't care, not possible (no link, but active?!)
- 1 1 0 OUT (no link, no active = dead)
The LED resistor values are marked as TBD, as these need to be adjusted for reasonable brightness of the LEDs.
Step 27: Keyboard PCB
This goes just behind the main USB keyboard, and provides switches and LEDs additional to the PInebox's operation.
Reset Switch (S401) connects through to the Raspberry PI reset pins. This will be recessed behind a small hole, to be used for emergencies only. Resetting a running PI can corrupt the SD card and USB file systems.
Power on/off/suspend Switch (S402) drives the CMOS latch/GPIO shown earlier.
Case closed switch (S403) senses that the lid has been lowered and signals that power saving can be done, described earlier.
- LED401 Power On (5V rail) *
- LED402 External Power (An external source is overriding battery) *
- LED403 Battery Charging (At C/10 or "bulk" charge - goes out for trickle)
- LED404 Battery Low Warning (16.0V)
- LED405 SDHC Active (RPi SDHC card r/w activity) *
- LED406 MEMSTK Active (USB Memstick r/w activity) *
- LED407 Wired Active (RJ45 Network activity) *
- LED408 WIFI Active (WIFI Dongle activity) *
* These will all extinguish if case is closed or battery gets low.
Step 28: Prototype: Main Power Bits
While all that designing and drawing was going on, this rather untidy prototype came into being. It actually works, despite appearances, and suffered much modding, poking and prodding.
Neatness is overrated.
The little module in the top left, first picture, is a "pseudo-raspberry PI" to create the 500Hz soft-off signal. It's a little 4047 based oscillator on a PCB.
You can also see the SMD breakout board hovering in mid air, and a diagnostic piezo buzzer (blue) monitoring the CMOS monostables.
None of this was connected to a PI at any point, it's all dummy loads (fat resistors, low wattage bulbs).
Failure is always an option, when you're only smoking resistors.
Step 29: Prototype: Extras
The temperature cutoff section was a late addition to the above, on a little grey breadboard.
The closely PI-connected I2C parts were prototyped on yet another two yellow breadboards (you can't have enough of these things!), held together with some plywood, pins, elastic bands, and an IDE ribbon cable. To pick off the connections from the IDE cable, I disassembled a damaged molex connector for the pins and made these jumpers.
Despite the apparent error, the IO connector pin-out reminder IS the correct way round, given that the connector is facing up at this end, not down! (Left-right mirrored!)
Talking to the I2C chips (in testing, to make sure they worked) was easy using the wiringpi gpio command line utility, e.g.
- gpio -x mcp23008:100:0x27:0 mode 100 out (Set first pin on DIO as output)
- gpio -x mcp23008:100:0x27:0 write 100 1 (Write it as 1)
- gpio -x mcp23008:100:0x27:0 mode 100 in (Set first pin on DIO as input)
- gpio -x mcp23008:100:0x27:0 read 100 (Read it)
- gpio -x pcf8591:110:0x4f:0 aread 110 (Read first ADC channel 0-255)
- gpio -x pcf8591:110:0x4f:0 awrite 110 180 (Write DAC output with (180/255) of full scale
Step 30: PCB Layout
There are many tutorials on laying out boards with EagleCAD, so I'll skip that step.
There are some mechanical considerations as to where things must be regarding connectors, mounting holes and tall components (that may need to lean off/lie horizontally off the board). Some parts may end up being installed on the wrong-side of the PCB, for convenience.
Other than that, the 10x8cm limitation of the free version of EagleCAD, and the small space in a portable device, means that the layout is spread over 3 (well, 4) boards, and in places is quite tightly packed in.
The layout may not be perfect, but if that messy prototype above worked, it stands a good chance! And there's always mod wires if needed.
Power and signal traces are as wide as possible before routing becomes hard/impossible.
I turned on the ability to route in any direction on any layer, to maximise chances of a successful route.
I added some "keepout/restrict" zones around the solder jumpers to keep tracks from passing through the middle -- although solder mask is supposed to be there, I wouldn't push my luck on that one.
In some spare space on the fourth PCB I included an "official" slightly modified version of the SMD breakout board. It costs nothing extra ... throw it in.
These designs are currently with a board house, and the final stage of building and tweaking will take place when the PCBs come back ... but that's for another instructable, at which point a corrected full schematic/parts list will be included.
Step 31: Connector Designations
This is the pinout for all the connectors/wire pads in the project.
Back to top level Pinebox project