Electron Reset Pin Advice


Some advice please. I use the RST Pin to force the Electron out of deep sleep with an normally open switch. Is it possible to detect how long the user press the switch. I would like to use one switch for two functions


Instead of connecting the switch to RST, you can connect the switch between WKP and 3V3. A pull-down resistor to GND is also a good idea.

WKP will wake the Electron out of SLEEP_MODE_DEEP. Unlike RST, you can read the status of the WKP pin like any other digital input using digitalRead(WKP), so you can treat it like a regular button when not in sleep mode.

Thanks. What would be the best way to measure how long the switch was pressed if the Electron was sleeping ?

The rising edge on WKP will wake the device virtually immediately, if your code starts running instantly (e.g. SYSTEM_THREAD(ENABLED) and/or SYSTEM_MODE(SEMI_AUTOMATIC)) you can use the STARTUP() macro to pinReadFast(WKP) to check how long WKP stays HIGH.
There are multiple ways of doing that, which greatly depend on your use case.

The IMO simplest but least elegant way would be like this

uint32_t pressed = 0;
void readPressTime() {
  pressed = millis();


To all. Thanks a lot. Works 100% and also in manual mode.


How can I re-assign the WKP pin (after coming out of sleep mode) to function as a RST button while the program is running ?


@jamesza, you can treat the pin like a regular GPIO pin when no in deep sleep.

There’s no way to make WKP be a hardware reset like the RESET pin. However, you can make it a software reset.

You could just read WKP out of loop and call System.reset() when pressed. That’s easy.

If you wanted to get fancy you could do it from a separate thread. I would probably do that. You can’t call System.reset() from an ISR, so you can’t do it from an interrupt handler using attachInterrupt.

Tx. In my case a loop will be a good option.