Domino & Battery Shield Continued

This builds on what was discussed on a previous thread -

My current issue is, running on battery the status says 48%.

However the Domino will power off after about 5 minutes, it’ll slowly build up a buzzing and the power light will start to flicker before powering off. This is the first time I’ve seen it do this. The GPS chip will also do the same when attached.

So I check the battery using a MM and at first, it has a charge of 5v but when the flickering starts this drops to 0 very quickly at which point measuring the charge from the battery is 0. My assumption here is the battery is dead, kaput, empty.

Now, as I understood it I read the status pin via a voltage divider to gauge capacity. When full this is at like 4v or so, or 2.05v divided. When I check the status pin when it powers off it’s at around 1.5v which is only say half of the original voltage which would mean a 40-50% charge surely?

My battery code looks something like this:

            // Create interface to battery pin
            AnalogIn pin = new AnalogIn((AnalogIn.Pin) FEZ_Pin.AnalogIn.An1);

            // Set pin scale

            // Create somewhere to store samples
            ArrayList samples = new ArrayList();

            while (true) {
                // Check termination flag
                lock (locker) {
                    if (thread_terminate) break;

                // Read in battery voltage
                int voltage = pin.Read();

                // Adjust volate to percentage
                double voltage_percent = (voltage * 100) / 3300;

                // Add percentage to samples

                if (samples.Count >= 20) {
                    // Get copy of count
                    int count = samples.Count;

                    // Add up percents
                    double total = 0.0;

                    while (samples.Count > 0) {
                        total += (double)samples[0];


                    // Average
                    double avg;

                    if (total <= 0.0) {
                        avg = 0.0;
                    } else {                 
                        avg = total / count;

                    // Set level
                    lock (locker) {
                        level = (int)avg;

                // Sleep for a bit

            // Release pin interface

In order to equate for minor fluctuations I sample at interval, hence that code.

Am I missing something obvious here or is something else going on? This doesn’t happen off battery when using USB for example. I’m going to fully charge the battery again and see if the problem still exists there. Could be I’ve found the lower charge for empty so might have to half the value again from that pulled from the divider. But this is perplexing.

[quote]When I check the status pin when it powers off it’s at around 1.5v which is only say half of the original voltage which would mean a 40-50% charge surely?

You need to do some research on the battery chemistry your using (NiMh, Lipo, etc.) Some chemistries, like lead-acid, will have a nice slope to the discharge curve. A 12V lead-acid will be maybe 12.7V fully charges and will be at 11.9V at 50% charge. This is open circuit voltage (no load) if you are trying to measure the battery voltage when it is under load you have to take into account the internal resistance of the battery. If you discharge a battery to 1/2 of its charged voltage you will damage the battery.

Other chemistries will have different discharge curves. Some battery chemistries you can’t just use the voltage. There are battery monitoring ICs that do all of the complicated stuff for you, but I suspect that with some more research you can come up with a workable system using just the FEZ.

Yeh this is LiOn, it’s a ready made shield for the Arduino/Fez that pumps out 5v/3.3v and has a status line which gives out about 4v when fully charged.

I pass the status line through a voltage divider and into An0 so at full charge it’s actually passing up around 2v or so (seeing as analog inputs only take 3.3v).

All these measures are done once attached to the Fez through open pins on an extender shield turned on (i.e not charging).

I think my linear scale could be wrong though, I’m assuming 3.3v because this is what the pin can take but I’m pushing much less that this, 2.02v or so, should I be using 2020 instead of 3300?

No, the linear scale does not matter. It’s the scale in which you would like to measure voltage. Leave it like this, it’s fine.

Any way, did you calculate the voltage?


Battery voltage: 4v
Input via voltage divider: 2v

Scale= battery voltage / input voltage = 4v / 2v = 2v

So measuring 2 volts on the an0 pin of your fez means 2 * scale = 2 * 2 = 4v

Measuring 1 volt on the an0 pin of your fez means 1 * scale = 1 * 2 = 2v


// Read in battery voltage
int voltage = pin.Read();

// Apply scale (change 2 if you have a different scale)
double volts = voltage * 2

Didn’t you read my blog post I mentioned before?

Yes I used that as the basis of my work :slight_smile:

And I’m reading a value from the status pin fine I think, I mean I can display a scale and it does eventually charge up except the issues mentioned earlier in this thread with it powering off when the status says 48% (or should be anyhow), it’s that which has me vexed because that means the status pin is at least giving out 1v+ or so which seems odd for an empty battery.

I guess what I really need to do is find the lower end of the scale and output when the Fez simply wont power on.

Yes. Try to check when and how fez reacts to charge levels.
It’s crucial to know which scale to use.

Seems when fully charged it’s at 4.05v and when things start to spazz out it’s at about 2.98v coming direct from status before it hits the divider, so obviously on the divider it’s much less.

I guess once it dips below 3.3v things start going wrong.

Isn’t the discharge cutoff voltage something like 2.75v? Sounds like when your seeing issues, your dancing on the cutoff. What does the battery datasheet say?

[quote]Isn’t the discharge cutoff voltage something like 2.75v? Sounds like when your seeing issues, your dancing on the cutoff. What does the battery datasheet say?

That is the point I was trying to make earlier. Here is a LiPo discharge curve that I pulled up at random from the web (below). Notice how the middle of the curve is nearly flat (only about 0.2V delta) and then the voltage drops off a cliff. Notice that they show 3.0V as the critical voltage, if you discharge below that point you risk damaging the cell. By the time you reach 3.0V you have already fallen off the cliff and you have no hope of doing anything about it.

Battery monitoring ICs also keep track of current used and try to predict when you will reach the usable end of life based on the current discharge rate. Given the battery in the graph shown you would have to call 3.4V ‘dead’ to play it safe and avoid falling over the cliff.