Sleeping for less than a second

Is it possible for an electron to sleep for less than 1 second? I actually would like to sleep for 10 milliseconds and for about 500 milliseconds.

The reason behind it is that is use the electron mainly in a offline loop, that reads all 500 milliseconds from I2C sensors and displays them locally. For each measure loop I will wake up the sensors, then waiting/sleep for 10 milliseconds before reading them and then put them back to sleep until the next measurement. I will only enable the cellular module all 2 or 4 hours to publish some stored average values.

I want to use an electron in a small off-grid solar power system so I would really like to sleep and save power for the time it just waits.


@bittailor, milliseconds sleep is not supported for any sleep mode. You could, however, do a (pause) sleep with [wake-on-pin](http://System.sleep(wakeUpPin, edgeTriggerMode, seconds):wink: and have an external timer (eg. low power 555
configured as one-shot) change the specified pin state to wake the device. You could trigger the timer with another GPIO pin just before sleeping.

Iā€™m just not sure you will gain much from 10ms and 500ms sleeps though you did mention that cellular will be off most of the time. The best power saving benefits come from deep sleeping.


Thanks for the reply and inputs. I would like to avoid additional external components/timers.

I started reading the STM32F205xx Datasheet. There are 3 Low-power modes described:

  • Sleep mode
  • Stop mode
  • Standby mode

And as I understood in Stop mode and Standby mode only the RTC timer runs so, as you mentioned there is no way to wake up faster (<1s) from an internal timer.

There is still the Sleep mode which I think could be used for busy waits to actually sleep and save a little bit of power.

So I came up with this

void msSleep(unsigned long ms) {
   unsigned long start = millis();
   while(millis() - start <  ms) {

The idea is that it checks if the the sleep time is over if not goes to sleep to be waken up by the SysTick to again check if the sleep time is over.

So I tested this in my setup with the compromise to extend the measure loop to 1s instead of 0.5s. So I use the Stop mode to sleep for 1s and then my Sleep mode sleep to sleep for the 10 ms.

With this I see that during the 10 ms I use my sleep the current goes down from 40-55 mA to ~28 mA.

With delay(10):

With msSleep(10):

So I wonder if there are issues when using my msSleep() instead of delay() when running offline, because I think it could still make sense to use it to save a little bit of power.

Thanks for any insights and recommendations on using the Sleep mode of the STM32F205RGT6 microcontroller.