You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Hi Tobias,

    Well, one very simple method is to detect when the battery voltage goes below ~3v. Basically as the battery voltage lowers, the voltage regulator stops being able to supply 3.3v to the STM32 chip in Espruino - and you can detect that.

    You can use E.getAnalogVRef() to see what voltage Espruino thinks it is at, so for instance you could do:

    setInterval(function() {
      if (E.getAnalogVRef()<3.0) doSomething();
    }, 60000); // every 60 sec
    

    To go to sleep, you'll want to have called setDeepSleep(true) - but then you should probably do that anyway if running off a battery as it'll decrease power draw massively. Then, it's just a matter of making sure you don't have any calls to setInterval or setTimeout that might wake Espruino up.

About

Avatar for Gordon @Gordon started