# Electron deep sleep not working after first power up

**URL:** <https://community.particle.io/t/electron-deep-sleep-not-working-after-first-power-up/44451>\
**Category:** Troubleshooting\
**Created:** [October 9, 2018, 1:05pm UTC](https://community.particle.io/t/electron-deep-sleep-not-working-after-first-power-up/44451 "2018-10-09T13:05:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nils](https://avatars.discourse-cdn.com/v4/letter/n/d6d6ee/32.png) [@nils](https://community.particle.io/u/nils)\
**Post date:** [October 9, 2018, 1:05pm UTC](https://community.particle.io/t/electron-deep-sleep-not-working-after-first-power-up/44451/1 "2018-10-09T13:05:30Z")

</div>

This is my minimal code:

```auto
SYSTEM_MODE(SEMI_AUTOMATIC);

void setup() {
    System.sleep(SLEEP_MODE_DEEP, 10);
}
void loop() {
}

```

I would expect that the electron goes to deep sleep, wakes every 10 seconds and sleeps again immediately. When I power the electron by plugging the battery in, this seems to work. Every 10 seconds I wakes up, the led flashes for a moment. But if i measure the current consumption, I can see that sleep doesn’t work properly, the current varies between ~70mA and ~15mA:  
 ![20181009_145547](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/4/d/4de628da4a5a239171d5d1f84ce223da9f20dab5.gif)

Normal current should be 0.2mA in sleep and some higher current consumption in the short wake up time. I found several options to get this normal behaviour:

1. Just wait. After some random time (from 20s to 5min) the current consumption is normal. The time varies with every try.
2. Unplug the battery for a very short time and immediately connect it again.
3. Hold MODE while reset, when led blinks, reset again without MODE.

The only option to retrigger this behaviour is to plug the battery in after having it disconnected long enough. Is this a bug? I would like to know the reason for this behaviour to find a reliable solution.

Thank you!

---

<div class="post-metadata">

**Author:** ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)\
**Post date:** [October 9, 2018, 1:11pm UTC](https://community.particle.io/t/electron-deep-sleep-not-working-after-first-power-up/44451/2 "2018-10-09T13:11:02Z")

</div>

Yes, that won't work right. The problem is in SEMI\_AUTOMATIC mode on cold boot the modem is somewhat powered up, not fully powered and operational, but not asleep either.

Putting the modem into SLEEP\_MODE\_DEEP requires that the modem be on in order to send the AT commands to it, which is why you're not going into deep sleep.

The workarounds are listed here:

> [@Electron SLEEP\_MODE\_DEEP tips and examples](https://community.particle.io/t/electron-sleep-mode-deep-tips-and-examples/27823):
>
> It’s a little confusing getting an Electron to go into deep sleep, using the 130 µA that it should. These six annotated code examples should hopefully clear things up. All tests were run on 0.6.0 on a Electron G350. AUTOMATIC, no system thread #include "Particle.h" void setup() { } void loop() { // Results in 133 uA power consumption // Modem is turned off, full cellular resync after restart (blinking green, blinking cyan, fast blinking cyan), 5-6K of data usage System.sleep(SLEEP\_MODE\_DE…

---

<div class="post-metadata">

**Author:** ![nils](https://avatars.discourse-cdn.com/v4/letter/n/d6d6ee/32.png) [@nils](https://community.particle.io/u/nils)\
**Post date:** [October 9, 2018, 2:15pm UTC](https://community.particle.io/t/electron-deep-sleep-not-working-after-first-power-up/44451/3 "2018-10-09T14:15:46Z")

</div>

Thank you for the fast response, that solves my problem!

My modified and now working code based on the linked examples looks like that:

```auto
SYSTEM_MODE(SEMI_AUTOMATIC);
SYSTEM_THREAD(ENABLED);
STARTUP(System.enableFeature(FEATURE_RESET_INFO));

void setup() {
    if(System.resetReason() != RESET_REASON_POWER_MANAGEMENT) {
        Cellular.on();
        Cellular.off();
    }
    System.sleep(SLEEP_MODE_DEEP, 10);
}

void loop() {
}

```

When waking up after deep sleep, the resetReason is RESET\_REASON\_POWER\_MANAGEMENT. On initial power up after connecting the battery, the resetReason is RESET\_REASON\_POWER\_DOWN.

---

<div class="post-metadata">

**Author:** ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)\
**Post date:** [October 9, 2018, 2:24pm UTC](https://community.particle.io/t/electron-deep-sleep-not-working-after-first-power-up/44451/4 "2018-10-09T14:24:26Z")

</div>

Be a little careful with that sequence in SYSTEM\_THREAD(ENABLED) mode. Since Cellular.on() is non-blocking there’s no way to tell when it’s done. It’s best to insert a delay of a couple seconds after that. Since it will only be done on cold boot it won’t happen often.

Or you can use `cellular_on(NULL)`. That is blocking.

Cellular.off() isn’t as much of a problem as the System.sleep() will block until the Cellular.off() call is complete I think.

---

<div class="post-metadata">

**Author:** ![nils](https://avatars.discourse-cdn.com/v4/letter/n/d6d6ee/32.png) [@nils](https://community.particle.io/u/nils)\
**Post date:** [October 9, 2018, 2:31pm UTC](https://community.particle.io/t/electron-deep-sleep-not-working-after-first-power-up/44451/5 "2018-10-09T14:31:07Z")

</div>

Thank you for the note.

I changed it to

```auto
cellular_on(NULL);
cellular_off(NULL);

```

and it works fine.
