Power / battery / sleep

Posted on
  • I'm new to battery-powering. A few questions I hope you can help me with

    The docs say that the Pico will not enter deep sleep while on USB power. Will it wake from deep sleep when USB power arrives, or can it be configured to do so?

    If I comnect both battery and USB I presume this is safe but will there be zero draw from the battery while USB is connected?

    Next two questions are probably electronics ones which I am again new to:

    When deep sleep is entered, sounds like 3.3V output on the Pico will be off. Therefore to create a "wake on push" button, I would plan to wire the button directly between battery and a pin I can monitor, but I am unsure how to wire this so that it won't interfere with the "normal" circuit.

    Lastly, if I want to use both VBat and 3.3V outputs, can the circuits share the same ground? I would assume not, but maybe it is safe to ground through another pin set to 0v? And if I just set a pin to 1 using digitalWrite, I assume that is a 3.3 v output, and if so how does it differ from the main 3.3V output, other than that the latter is always on?

    Saw the very helpful tip on another thread about measuring incoming battery voltage through E.getAnalogVRef in another thread - thanks Gordon.

  • Hi,

    Will it wake from deep sleep when USB power arrives, or can it be configured to do so?

    Yes, it should do that automatically.

    If I comnect both battery and USB I presume this is safe but will there be zero draw from the battery while USB is connected?

    Absolutely - just make sure you connect the battery using either the JST connector that you can solder to the bottom, or via the BAT_IN wire. There's special circuitry in there to handle the switchover of power sources.

    When deep sleep is entered, sounds like 3.3V output on the Pico will be off.

    Nope, it's actually fine. The GPIOs keep working (including pullups/etc) - just use the button like you would do normally and it'll keep working with deep sleep.

    Lastly, if I want to use both VBat and 3.3V outputs, can the circuits share the same ground?

    Absolutely - in fact that's the best way of doing it.

    if I just set a pin to 1 using digitalWrite, I assume that is a 3.3 v output, and if so how does it differ from the main 3.3V output

    It might not be quite 3.3v because of the circuitry in the IC, but it'll be close. Also you'll only be able to draw around 20mA from it. If you're using the 3.3v you could draw near 400mA (for short periods of time).

    Saw the very helpful tip on another thread about measuring incoming battery voltage through E.getAnalogVRef in another thread

    Only thing I'd say with that is E.getAnalogVRef() is measuring the voltage on the regulated 3.3v line - so realistically you'll only ever see that value change when the battery voltage is higher than 3.3v. It only starts to drop when the voltage gets near or lower than 3.3v and the regulator can't keep the voltage high enough...

    But that's often fine - the STM32 will run down to something crazy like 2 volts, so you've got a lot of time below 3.3v before you have problems.

  • Really helpful answers and everything is really thought through on power. Now officially an Espruino fan-boy! Since I live in Oxford you'd better be careful I don't start stalking you :->

  • :) Thanks!

    Have you ever been to the IoT Oxford or JS Oxford stuff? I'm not going to the JS Oxford one tonight, but generally I have been trying to go the events that they do.

  • I know quite a few people from JSoxford mostly the White October crowd - I've worked with Ben Foxall a few times. However only recently am I doing more JS myself at work. Good prompt about the IoT group, I've signed up for that and expect I'll see you there some time.

    It was partly fringe involvement in the Oxford Flood Network (I offered to host a sensor and relay its data) that got me into this though my current project has nothing to do with that.

  • Just a follow-up question on deep sleep - if 3.3v pin and GPIO pins stay on during deep sleep, presumably I am better powering sensors from a controllable GPIO pin so as to minimise draw during deep sleep, something like the code below.

    For larger stuff that needs more current than a controllable pin can supply, presumably I need a transistor connected to 3.3V, the controllable pin and common ground in order to switch them off during deep sleep?

    // button will be wired from 3.3V pin to A8.
    // other sensors will be wired with +ve to power pin B1 and their own ADC pin to read
    var powerPin = B1, btnPin = A8;
    var watch;
    
    function doStuffAndSleep () {
      setDeepSleep(0);
      //power up sensors 
      digitalWrite(powerPin,1);
      //check sensors...
      //...check completed
     //shutdown power and go to sleep
      digitalWrite(powerPin,0);
      setupWatch();
      setDeepSleep(1);
    }
    function setupWatch () {
      setWatch(doStuffFromSleep, btnPin, { repeat:false });
    }
    
    doStuff();
    
    
    
  • Yes, that's a good idea. For maximum power saving, actually turn the pin into an input with digitalRead(powerPin) to turn it off (then you're not using power pulling it down to 0).

    However I'd look at the datasheet for the device to make sure. Some of them can be put into low power modes using software, so you could save a bit of wiring :)

    Just so you know - setDeepSleep actually only sets a flag that says "go to deep sleep when possible". You don't actually need setDeepSleep(0); and setDeepSleep(1); - you just need to call setDeepSleep(1); once, at some point in your code :)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Power / battery / sleep

Posted by Avatar for Moray @Moray

Actions