The amazing Linux Duracell CPU load monitor The amazing Linux Duracell CPU load monitor

The amazing Linux Duracell CPU load monitor

Turning an AA on-battery tester into a CPU load monitor for Linux

You probably know those onboard testers found on Energizer and Duracell batteries : press the two white dots printed on the wrapper, and magically the battery's state appears on a yellow bar. No need for a separate battery tester, everything is included on the battery itself. While not very precise, it's good enough to know if a battery is brand new, so-so, or completely dead.

These throwaway testers are quite clever : they use a layer of conductive ink that heats up when an electrical current runs through it, in combination with a layer of thermally-activated dye that turns transparent when heated up, revealing a third layer of colored ink underneath. Because the layers are printed with varying thickness from "0%" to "100%", parts of them become yellow before others, creating a bargraph effect that varies with the current applied, the battery's body itself sinking the heat produced by the conductive ink. Informative details about those testers can be found here :

HowStuffWorks
The Duracell Battery Tester
AA Battery Tester

Here are instructions to turn such a tester into a not-so-precise analog display to monitor the CPU load on a Linux system, controlled by a serial port. You can build two variants of the display:

- A simple display, with the battery tester on the control circuit
- A more precise and less finicky display, with the battery tester mounted on a heatsink

What you need

- An AA Duracell battery with a tester. Energizer testers should work too, but I haven't tried. I got a pack of Duracell Ultra M3 batteries, product code LR6-MN1500.
- 1 x 3V power cube
- 1 x 2 KOhm resistor
- 1 x 4.7 KOhm resistor
- 1 x 10 KOhm resistor
- 1 x 4N25 or CNY17 optocoupler
- 1 x BC547A or 2N2222A transistor
- 1 x TIP41C transistor
- 2 x 1N4004 diode
- 3 x ON/OFF switche
- 1 x female DB9 connector
- 1 x breadboard (get it somewhat large if you build the simple display)
- 1 x clear plexiglas CD case
- 1 x Socket-7 heatsink (if you want to build the more precise display)
- 4 x 10x3mm wood screws (if you want to build the more precise display)
- patience

Instructions to make the simple on-circuit display

Cleanly unwrap the tester off the AA battery. Be careful not to pull on any one side too hard, or you'll warp it and it'll be that much harder to connect on the breadboard. Personally, I lift both corners, gently unroll it on 3/4 mm, then use a knife and my thumb to finish taking it off the battery with an even pull. Here's what it should look like, before trimming the warped bit of the packaging :



Here's the really hard bit : making a somewhat reliable connection between the tester's conductive ink points and the rest of the circuitry. To do that, place the tester on the breadboard, near the upper edge, and mark out precisely the breadboard holes the wrapper's white dots fall on. Spend some time aligning the right white dot (on the "minus" side), as the patch of conductive ink there is very thin and right on the edge of the tester. The dot on the left ("plus") side is less problematic.



To make the connectors, solder bits of "hairy" copper wire (like that found on common mains electrical cords) in the holes you marked, and leave the "hairs" sticking out where the tester will be installed. They'll help make a correct electrical contact with the tester's conductive ink. Cut out a piece of clear plexiglas from the CD case, tape one edge to the upper edge of the breadboard, and punch a small hole near the bottom edge. This makes a window to hold the tester and press it flat against the breadboad and the connector.

Solder the circuit's components at the bottom of the breadboard, under the window (there should be about 3 cm worth of breadboard left there). Here's the circuit's schematic:



Notice the 2 switches around the 1N4004 diodes : those diodes are there to reduce the voltage fed to the tester, but depending on the individual tester and the quality of the contacts with the conductive ink, you might need to overload the tester a bit to reach 100%, or make it more reactive. With the switches, you can short one or both diodes, adding 0.6V per shorted diode.

Once the circuit is done, feed it 3V and close all the switches. Then carefully align the tester on its connectors, flip the window closed and short pins 4 and 5 of the optocoupler : if the connections are good, the display should very quickly turn completely yellow. If it does, unshort the pins quickly or you'll fry the tester (and possibly the window's plexiglas). Aligning the tester on the connectors is not easy to do, take your time to avoid stripping the conductive ink. Once you have good connection, insert a small metal wire through the hole at the bottom of the window and through the breadboard, and twist it, to close the window permanently.

The end result should look something like this:


Then, open both switches around the diodes and re-test the display by shorting the optocoupler's pins again : if it goes all the way up to 100% in a reasonable amount of time (less than 10s), you're good. Otherwise, short one diode and try again.

The hardware is finished! Now switch the power supply off and connect the circuit to your computer's RS232 port. Leave the power off whenever you don't run the control software, as the RTS line on an RS232 is high at idle, and so you'd run the tester at full blast all the time and eventually could damage it.

Instructions to make the more precise display with a heatsink

The battery tester being a thermal display (its hue changes with the temperature), when it is sandwitched between two pieces of plastic like in the simple display, the heat it generates isn't very well dissipated and tends to stay trapped. As a result, the display rises over time, and if it is run long enough, it ends up displaying 100% all the time eventually.

To alleviate this problem, it is necessary to sink the heat produced by the conductive ink. This prevents the display from accumulating heat, therefore making it more stable. It also makes the yellow bar drop more quickly, since the temperature goes down faster when the power running through the tester is reduced. In this version of the display, the battery tester is mounted a socket-7 heatsink (like those found on old Pentium-I processors).

First, as with the simple display, peel off a battery tester from an AA battery as cleanly as you can. Cut it to size by making it about as wide as the heatsink, and 10 to 15mm shorter than the heatsink vertically (to leave room for the screws).

Drill four 3mm holes, one at each corner of the heatsink. It is crucial that the holes end up exactly between two fins on the other side, as the screws' threads will find purchase on the walls of the fins. Then, drill two 3mm holes where the battery tester's contact points will press against the connectors (be careful, the right-hand side hole is very close to the edge).

Before installing the connectors, use the heatsink as a guide to cut a piece of clear plexiglass of the same size, with matching holes at each corners. That piece of plexiglass will press the battery tester against the heatsink and serve as a window.



Now for the tough bit: you need to pass connectors through the holes without making a short circuit with the heatsink's metal. To do this, apply several layers of nail polish around the holes on both sides, and inside the holes themselves. I personally use black nail polish to see what I'm doing, but the transparent kind will do as well. Then, pass a piece of common 3mm electrical appliance cord through each hole (this should be hard to do, if it isn't, your cord isn't big enough), then with an exacto knife or a sharp cutter, carefully cut and strip the electrical cord's sleeve flush with the heatsink. The idea is to make only the copper "hair" emerge out of the heatsink without touching the heatsink's metal.

Once you've installed both wires in the holes and you've checked there's no short, drop some Superglue in the areas where the wires go through the heatsink, between the fins, on the other side, to set them permanently, and run the wires between the fins to lock them in place. Cut the copper "hair" to 5mm or less.



Finally, carefully align the battery tester's contact points over the connectors on the heatsink, gently apply the plexiglass window over it and install the screws very loosely. Test the connection with the tester by measuring the resistance between the two wires : if you find less than 6 Ohms (ideally 3/4 Ohms), clamp down the tester further by tightening all four screws slowly and evenly. Retest regularly as you tighten the screws. Don't overdo it, or you'll splinter the plexiglass. Eventually, you should have the tester completely flat against the heatsink, and the contacts should still be good. When you think you're done, make one last check by connecting the AA battery's poles to the wires and see if the display goes up. If it does, you're through with the hardest part.

However, if at any point during the tightening procedure, the contact seems flaky, undo everything, remove the tester, put the copper "hair" back in shape and start over. It can take some time to do right unfortunately.

The result should look like this:



At this point, you have a working display head. Make the same control circuit as the simple display described above (leaving out the upper part of the breadboard, with the tester and the plexiglass window of course) and connect the display head you've just made between the 1N4004 diodes and the transistors. As with the simple display, adjust the base voltage fed to the tester using the switches around the diodes, and never power the circuit when the control software isn't running.

Running the CPU load monitor

First of all, download it here, untar it and type "make" : this should produce a "duracell_cpumon" executable. If needed, configure /dev/rtc as explained in the source code.

You then need to calibrate the display, so that the control software knows which pulse widths correspond to loads between 0 and 100. To calibrate your display, invoke:

./duracell_cpumon /dev/ttySx -c

(replace "/dev/ttySx" by your serial port, ttyS0, ttyS1 ...)
Remember to switch off the display as soon as the software stops!

Once the display is calibrated (the software should produce a "duracell.cal" file), finally run the CPU load monitor by invoking:

./duracell_cpumon /dev/ttySx

and switch on the display. The display should show the average CPU load, but because it's so slow, if your CPU load is usually not very high, try running tasks that load up the CPU for at least 10/15s to get it to move, especially when it starts out cold. Starting OpenOffice or Mozilla is a good test on slower machines.

This is how the display looks with some load on my system:



Here's a video where I start a 50% load, then stop it. Notice on the monitor the KDE load monitor in red, and how the Duracell display follows the load showed by kcpuload (albeit with a lot of lag, due to the ink warming up):


There you have it : the most imprecise, slow, power-hungry, finicky and unreliable CPU load monitor in the world. Aren't you happy ? :-)

Disclaimer

- I don't own any Duracell or Energizer stock, and have no vested interest in either of these companies. It just so happens that I used Duracell batteries for this hack, and I had to find a name for the project.

- This is just an experiment, you should know what you're doing before attempting to make a similar device using the above instructions. I am NOT responsible for any damage you do to your computer, or if you set fire to your house with it, or if the software wipes your hard-drive, etc... YOU'RE ON YOUR OWN.


© Pierre-Philippe Coupard / 2004

Hits since 08/02/03

Mailbox Email