Electron - Won't stay in Sleep mode

I’ve tried several of the examples in the tutorials as well as as “solutions” from various threads on this subject. The only way I can get the Electron to sleep (and wake up as expected) is if I specify “time”, but I want to specify a wakeup pin and NOT “time”. When specifying a WKP, the Electron does appear to shutdown, but then immediately starts up again. I have a momentary contact switch on D3. In order to make sure that I’m not getting some residual “bounce” from the switch, I put out a message and then pause for 3 seconds and then a second message before issuing the System.sleep() command. The code is:

        Serial.print("Preparing to go to sleep1.....\n");
        delay(3000);    // Switch debounce (longer than it needs to be for testing)
        Serial.println("Sleeping.....");                  
        System.sleep(D3,CHANGE,SLEEP_MODE_DEEP);

Although it appears to shutdown and restart, most of the time I have to press the “reset” switch to get it to connect (pulsing Cyan) as it seems to get stuck at the medium flashing blue (it eventually does connect - some of the time) However, once I do the hard reset it connects right away.

I’ve tried specifying "RISING, “FALLING” as well as “CHANGE” with the same result.

Have you got a pull-up or pull-down resistor to prevent a floating pin from triggering the wake?

But more importantly, where does this syntax come from? It doesn't make sense in multiple dimensions.
The third parameter should be a sleep period value or an additional flag (e.g. SLEEP_NETWORK_STANDBY) not SLEEP_MODE_DEEP.
Additionally if you wanted to use deep sleep, that would be the first parameter.
And also SLEEP_MODE_DEEP can only wake on a rising edge on the WKP pin (not CHANGE nor D3).

And there actually is a documented syntax for that here
https://docs.particle.io/reference/device-os/firmware/electron/#sleep-sleep-

1 Like

Thanks for your reply. I know the syntax (having read it several times) - or thought I did. There is also this:

System.sleep(uint16_t wakeUpPin, uint16_t edgeTriggerMode, SLEEP_NETWORK_STANDBY);
System.sleep(SLEEP_MODE_DEEP, long seconds);
System.sleep(SLEEP_MODE_DEEP,60);
System.sleep(SLEEP_MODE_DEEP, 60, SLEEP_DISABLE_WKP_PIN);

It also says: “Wake up by WKP pin may be disabled by passing SLEEP_DISABLE_WKP_PIN option to `System.sleep()”, but I couldn’t find anywhere that it says how you set WKP so assumed that was the wakeUpPin referred to in the various syntax for the various sleep modes. The documentation for the Electron provides a list of pins that can be used, which includes D3 - which is what I used.

I also went back into various threads on this board and stackoverflow where I’ve seen other various uses, but nothing that led to a successful outcome, unfortunately.

I had been using only RISING (because that’s what I wanted to use - not because I saw it documented anywhere) until that last attempt where I tried both CHANGE and FALLING. I can’t find anything in the documentation that says it can only work with RISING - the prototype statements all say “edgeTriggerMode”.

I suspect part of the answer lies with the fact that I initialize the pinMode as INPUT_PULLUP and assumed that would work (as the switch pulls the pin low). I can add a pullup resistor, which was what I was going to try today.

Using your response syntax will put the Electron in STOP mode and I want to put it into DeepSleep mode. I haven’t been able to find any examples that specifically show how to use anything but TIME for SLEEP_MODE_DEEP and yet an interrupt should be able to be used and I’ve read various threads that talk about it, but perhaps I’m wrong; Is TIME the only thing that can wake the Electron up from SLEEP_MODE_DEEP? If not, then what am I missing? Thanks again.

@chucka, there is only one pin which can wake the Electron from deep slee and ONLY on a RISING edge and that the WKP pin. This is dictated by the STM32 hardware so that's why it is not user definable. In addition, the pin MUST be LOW when you go to deep sleep or it will never wake on the pin going HIGH. As such, either a pull-down (ie not floating) or a LOW condition must be present on the pin when going to deep sleep. With DeviceOS 0.8.0 or later you can DISABLE the WKP pin altogether to prevent false (eg. from floating pin) wakeups.

The documentation doesn't really punch out enough the WKP pin being the only way to wakeup from deep sleep via a pin:

The device will automatically wake up after the specified number of seconds or by applying a rising edge signal to the WKP pin.

Since 0.8.0: Wake up by WKP pin may be disabled by passing SLEEP_DISABLE_WKP_PIN option to System.sleep() : System.sleep(SLEEP_MODE_DEEP, long seconds, SLEEP_DISABLE_WKP_PIN) .

1 Like

Thanks for clarifying that. I looked more closely at the data sheet and found that A7 is also WKP. I have the full page pinout diagram of the Electron and WKP is not called out on A7; just TIM5_CH1 and ADC0, but I now see on the (difficult to read because of blue ink on black) silkscreen that it does say WKP! It wouldn’t hurt to include that fact in the “Sleep” documentation - unless I’m the only person that’s found this confusing - as well as adding it to the Electron PDF with all the pin functions.

I knew about the SLEEP_DISABLE_WKP_PIN, but just didn’t know where (or what) pin it was.

So now I can (hopefully) put its to sleep and wake it back up again using A7.

Thanks very much - that mystery is solved.

While it may not be clear and could be documented better, it's still documented and this statement isn't really true

Both WKP and A7 are mentioned right next to the pin on that pinout diagram

And some auxilary link
https://docs.particle.io/datasheets/cellular/electron-datasheet/#pin-description

Wow, I need a printer with better color differentiation! But, as you say, there are references, and now that I know what I’m looking for I have found them and the SLEEP_MODE_DEEP works as advertised. Thanks for your help.