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.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
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:
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 tosetInterval
orsetTimeout
that might wake Espruino up.