Main Site Documentation

Low power / DeepSleep on mBuino


#1

I played a bit tonight with my new mBuino toys that just arrived today. So far everything is working very nicely and I really like it. I was also pleasantly surprized to find that my mBuino’s included the battery holder.

Of course now one of the first things I wanted to do is to put a working mBuino on my keychain that flash a different LED very briefly every second. It was quite easy to do, but the “Wait” command I’m currently using is obviously not the best choice for ultra low power consumption. I tried using deepsleep in code as shown below, but the problem was that it simply never wakes up from deep sleep. Any advise?


 #include "mbed.h"
 #include "WakeUp.h"
 
DigitalOut myled(P0_7);
 
int main() {
    //The low-power oscillator can be quite inaccurate on some targets
    //this function calibrates it against the main clock
    WakeUp::calibrate();
   
    while(1) {
        //Set LED to zero
        myled = 0;
        
        //Set wakeup time for 2 seconds
        WakeUp::set_ms(2000);
        
        //Enter deepsleep, the program won't go beyond this point until it is woken up
        deepsleep();
  
        //Set LED for 1 second to one
        myled = 1;
        wait(1);
    }

}


#2

The e dice uses deep sleep so you can use that as a reference. We will be posting the code and other details in the coming weeks


#3

I put a CR2025 and only got about a day’s worth of blinking

… (the timing was different than the default firmware.bin - mine was just red/yellow - an embellishment to an iron man costume). ahem… .NERD!!!


#4

Thanks for that info Gus, However, I have no idea where the source code for the e-dice is. I had a look on mbed and found some examples of dice code for the mBuino itself (like the one from Valentin Ivanov), but that use the normal wait command. I could not find the source code of the official e-dice anywhere.


#5

Oops, sorry, I see now that I did not read your reply properly. Ok, no problem… I’ll wait until the code is posted.


#6

I just saw this:

http://mbed.org/questions/4524/mBuino-not-waking-up-from-sleep/

and based on this created this:

http://mbed.org/users/wernert/code/mBuino_low_power_led_flasher/


#7

I included the same deep sleep code from that post in my project (see mbed.org /users/maxint/code/mBuino_Dice/ ).
It’s working great! I’ve attached a tilt-switch with interrupt routine to my mBuino and even small movement is enough to trigger the routine which will wake mBuino from deep sleep.

Next project idea: add sirene and (waterproof) housing to create tiny anti-theft bike-alarm.


#8

Just a quick update… Someone posted a fix that gets the Powerdown mode down to 3uA at http://mbed.org/forum/electronics/topic/5138/?page=1#comment-25350

It had to do with unconfigured GPIO pins default to having the internal pullups enabled. The board has a pull down on pin P0_3. This conflict was causing the extra power draw in sleep mode.

Here is the code snippet to get current down to 3uA:


 #include "mbed.h"
 
DigitalIn progMode(P0_3);
 
void enterPowerDown() {
    LPC_PMU->PCON = 0x2;
    SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
    LPC_SYSCON->PDAWAKECFG &= 0xFFFFF800;
    __WFI();
}
 
int main () {
progMode.mode(PullNone);
 
enterPowerDown();
}




#9

@ KiwiSaner - I believe it was AndyA

https://www.ghielectronics.com/community/forum/topic?id=16720


#10

The mbed library here: http://mbed.org/users/AndyA/code/mBuino_Sleep/
provides a single function call that makes it easy to access any of the possible sleep modes and also takes care the power sucking pullup and shutting off the LEDs before sleeping.