How to tell deep sleep wake up reason between rising signal on wake up pin and RTC clock time out?


How to tell deep sleep wake up reason between rising signal on wake up pin and RTC clock time out?
I can not find RTC_IRQHandler().
From particle Doc find resetReason() API,But it does not describe deep sleep wake up reset reason.

Anyone know a way to find out deep sleep wake up reason?

Returns a code describing reason of the last device reset. The following codes are defined:

RESET_REASON_PIN_RESET: Reset button or reset pin
RESET_REASON_POWER_MANAGEMENT: Low-power management reset
RESET_REASON_WATCHDOG: Hardware watchdog reset
RESET_REASON_UPDATE: Successful firmware update
RESET_REASON_UPDATE_TIMEOUT: Firmware update timeout
RESET_REASON_FACTORY_RESET: Factory reset requested
RESET_REASON_SAFE_MODE: Safe mode requested
RESET_REASON_USER: User-requested reset
RESET_REASON_UNKNOWN: Unspecified reset reason
RESET_REASON_NONE: Information is not available



  1. The way I did it here, is to get right before going to sleep, and then right after waking up. If less time elapsed than the timeout, then I assumed it was the pin. It works reliably for me.

  2. Another possibility is to read the state of the pin you are triggering on right after waking up. If you are waiting for a high or rising edge, and the pin is high, then you were probably awoken by the pin. However, I’m told this may not be reliable. I tested this method too, and it seemed reliable.

Anyway, I settled on using the first method above, and it has worked for me every 15 minutes for over 100 days now without getting it wrong.

  • Rich


Timer wakeUpButtonDetect(50, wakeUpButtonDetectTimeOut);

bool checkForButtonPress(){

    int buttonDetects = 0;
    int reads = 0;
        // take the intergral
        buttonDetects += pinReadFast(WKP);
        reads += 1;
        delay(5); // or what ever you please
    Serial.print("Read wkp pin ");
    Serial.println(" number of times");
    Serial.print("Detected button was pushed ");
    Serial.println("number of times");
    if(buttonDetects > reads/2){
        // if more than 50% are pushes
        return true;
        return false;

But you have to be in Manual Mode or Semi-Auto so that your code kicks off at asap. The STARTUP() macro may do the tick to.

But surely there is a better way as this wastes 50ms at the start.


Read state of pin can work when Photon is sleep,Not sure If it will work when Photon is DEEP will not reset after wake up from deep sleep?


I think there are some news in this field and didn’t want to create a new thread - that is why I revive. I think there has been some work done in 0.8.0 for us to know what was the reason Photon/Electron woke up.

I read about it here : Particle Firmware Updates Thread:

If you read some more on Github you might see that even deep sleep was mentioned.
So the questions is (@peekay123 could you help since I’ve seen your comments in that conversation on github?) : do we (since 0.8.0-rc.2) have a new tool for Photon and Electron to know what was the reason for the device to wake up from deep sleep, or I misinterpreted something? If that is true, could somebody please share some method for using this? I would be grateful since I have to solve exactly this problem for Electron right now, and don’t know should I use all of the DIY alternative methods, or is there an actual flag for knowing why Electron woke up from deep sleep, thanks.


I think log RTC stamp to backup RAM before fall into deep sleep it is the only way to tell wake up reason


@ethelder, release 0.8.0-rc.3 includes the wake-by-pin and wake-by-rtc in System.sleepResult(). Take a look at the test app:

Particle Electron know the wakeup cause

Thanks!But there are some issues,I can not move to 0.8.0 now.