When you’re ready,
connect the main power
supply and the battery
pack to the UPS, and use
a suitable USB cable to
connect the UPS to your
Pi — which should
immediately begin its
boot-up process. When
your Pi has completed
booting, measure the
voltage between the two
ends of the battery pack
and make a note of it.
Next, unplug the main
power supply. The Pi
should continue to run
without interruption.
Again, measure the
voltage between the two
ends of the battery pack;
it should be significantly
lower when it’s providing power.
My battery voltage dropped from
11.3V to 10.5V, but I had already
been doing a considerable amount of
UPS testing so your voltage levels will
probably be somewhat higher. This is
an important point to keep in mind
because we will be measuring the
battery voltage when it is not
powering the Pi. Consequently, we
need to be sure to replace the
batteries well before they reach the
“spent” level of 6.3V. (I plan to
replace my batteries when they drop
below 7.5V.)
Experimenting With the
UPS Voltage-Sensing
Circuitry
Now that our UPS is functioning
correctly, we’re ready to conduct a
couple of simple voltage-sensing
experiments. Even though we won’t
be communicating with the Pi this
month (that’s still on my “To Do”
list), I used our Pi interface board
(from the August 2013 Primer) for
these experiments because we need
to power everything at 3.3V. Our Pi
interface board is a convenient way
of doing that. If you have a 3.3V
breadboard power supply, that would
work just as well.
Figure 8 is a photo of my
breadboard circuit for the following
two experiments. I haven’t included a
schematic because the necessary
connections are very simple. The six-wire ribbon cable is inserted into the
breadboard with a double-ended
three-pin male header. (You can also
use a 2x3 pin header, but it isn’t
necessary because each pair of pins
— 1 and 2; 3 and 4; and 5 and 6 —
carries the same signal.)
The other end of the ribbon
cable is inserted into the 2x3 male
header on the UPS, with pin 1 (the
red stripe on the cable) inserted into
the “B” (battery voltage) line.
Therefore, on the breadboard, the
three connections (in order from left
to right) are main power voltage
(divided down), ground, and battery
voltage (not divided). The ground
connection is made underneath the
cable, so it isn’t visible in the photo.
At this point, I need to mention
an important caution before we
proceed. The battery voltage at pin 1
(red stripe) of the ribbon cable is not
divided, so it can be as high as
11.375V. Therefore, directly
connecting pin 1 of the ribbon
cable to a PICAXE (or
Pi) I/O pin is likely to
damage or destroy the
I/O pin!
Experiment 1: Battery
Pack Voltage Sensing
We’re going to use a
simple two-resistor
voltage divider circuit,
execute a readadc10
statement to measure the
voltage at the junction of
the two resistors, and
then compute the battery
voltage. The Microchip
documentation for PIC
micro devices (on which
all PICAXE processors are
based) indicates that a
total resistance of about
10K will produce the
most accurate ADC reading.
However, the two resistors will always
be in the circuit, so they will produce
a continuous current-drain on the
batteries.
At the maximum battery voltage
of 11.375V, the current drain of a
10K (total) voltage divider would be
more than 1 mA. That might not
seem very large, but I was concerned
that over time it would significantly
reduce the life span of the batteries.
In order to determine how much
accuracy would be lost by using
larger resistors, I decided to
experiment with three different pairs
of resistors: 10K and 1K; 100K and
10K; and 1M and 100K. I chose
those values because a ratio of 10-to-
1 simplifies the programming
calculations that need to be made.
Also, in order to maintain as much
accuracy as possible, I measured the
actual value of a dozen or more
resistors for each of the above
nominal values and paired them so
the measured ratios were as close as
possible to 10-to-1.
The program that I used for this
experiment ( Pi_PS_Test1.bas) is
available at the article link. It’s fairly
straightforward and well commented,
so we won’t discuss it in detail. It
June 2014 13
■ FIGURE 8. Breadboard circuit for UPS experiments.