Main Site Documentation

Preserve battery life on mBuino


#1

I programmed my mBuinos so they could acts as Christmas Balls in the trees (much to the dismay of my wife :wink: )… Soldered the battery holders onto the back and put in 2 batteries…

Since it are mere LEDs that are lighting up… I was expecting that they would last for a few weeks… but after a mere hour the lights started fainting and after 3 hours the batteries were completely empty :frowning: (which did bring some happiness, but not to me ;D )

Is there a way to be more economic with regards to the battery use, so I can enjoy the lights for a few days?


#2

Are you using the DeepSleep low power states? See this post for info https://www.ghielectronics.com/community/forum/topic?id=16607


#3

Were the LEDs flashing?

A standard CR2032 battery is in the 220mAh range.

Some random guesses and a check of the mbuino schematic it looks like they are driven with around 15mA. (that seems a little high but is in the correct ballpark)

Assuming 7 LEDs on 50% of the time + 13mA CPU running power = ~70mA

So a single battery would give about 3 hours if each LED is on for about 1/2 the time.
Possibly less since watch batteries are designed for low currents and you lose some of the life if running at that sort of power level.

I could have that LED current wrong by a bit, it’s not going to be much higher but could be up to 3 times lower which would increase the battery life by up to a factor of 3.

In other words you got about what I would have expected.

Low power states aren’t going to help you much, the CPU uses about the same amount of power as a single LED. Saving CPU power would certainly help a little but isn’t going to make a massive difference unless you have the LEDs off most of the time.

One trick you can use is flash the LEDs too fast for a person to tell. This saves a lot of power but due to the way eyes work doesn’t make them look much dimmer.

The code below (not tested, I just made it up, so there may be the odd syntax error etc…) should look like the LEDs are on all the time but take about 19% of the power.
(1 LED on at a time + CPU in sleep mode most of the time = 15+7mA instead of 7*15+13mA)

To change which LEDs look like they are are on use a second ticker at a far slower rate that changes the value of LED_State over time.

LED_State is a bitfield for the LEDs, e.g. 0x41 would set the two end ones on, 0x22 would be 2 and 6, 0x14 would be 5 and 3 etc…

You could save about 7mA more (about a further 30% increase in battery life) by using powerdown rather than sleep mode for the CPU and using the watchdog timer to wake up but that gets a little more complex to code.
See http://developer.mbed.org/users/AndyA/code/mBuino_Sleep/ for details on how to do that. But use the mBuino_sleep_minimal version of the library for your code, the standard one switches the LEDs off to save power :wink:


 #include "mbed.h"

BusOut LEDs(LED7,LED6,LED5,LED4,LED3,LED2,LED1); // the actual LEDs

Ticker ledCycle;

char LED_State; // holds the LEDs we want to display 

// Sets the LEDs based on LED_State but with only one on at a time.
// called every 2ms (500Hz). 7LEDs = ~70Hz flashing.
// Should look constant to the human eye.
void onTicker() { 

  static char onLED = 0; // which LED is on.

  LEDs = LED_State & (1<< onLED) ; // set the LEDs to the correct value

  onLED++;        // update which LED to light next.
  if (onLED == 8)
    onLED = 0;
}

main () {
  LED_State = 0x7f;                  // set all LEDs on.
  ledCycle.attach_us(onTicker,2000);  // attach the timer.

  while (1) {
    sleep();              // deepsleep would save more power but makes it harder to wakeup.
  }
}


#4

Thnx for both replies! I’ll combine the sleep mode & the on/off switching of the leds and will check how far it will take me! :slight_smile:

I’ll mention you both to Santa :smiley: