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.

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 large-ish breadboard
  • 1 x clear plexiglas CD case
  • 100 x patience

    Instructions to make the 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.

    Running the CPU load monitor

    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 (it 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:

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

    Improving on the design

    Gluing the tester at the back of an old Pentium-1 heatsink seems to improve the stability and precision of the display quite a bit, and the range of pulse widths usable to go from 0% to 100% is wider too. As it is now, the tester's heat is dissipated solely by the breadboard and the window's plexiglas, which isn't very good. The result is that, when the tester is asked to display something for too long, the yellow bar slowly rises as the temperature hikes up. A heatsink dissipates that heat much better, and so the display stays stable.

    The big problem with a using a heatsink is that the latency is even worse than it is now, and also there's the problem of making contacts with the conductive ink under the tester. I probably could have made something, but I've spend way too much time on this thing already.

    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.