# \[SOLVED\] Clear EEPROM @ first boot

**URL:** <https://community.particle.io/t/solved-clear-eeprom-first-boot/23525>\
**Category:** Troubleshooting\
**Created:** [June 7, 2016, 6:26am UTC](https://community.particle.io/t/solved-clear-eeprom-first-boot/23525 "2016-06-07T06:26:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gecko](https://avatars.discourse-cdn.com/v4/letter/g/c4cdca/32.png) [@Gecko](https://community.particle.io/u/Gecko)\
**Post date:** [June 7, 2016, 6:26am UTC](https://community.particle.io/t/solved-clear-eeprom-first-boot/23525/1 "2016-06-07T06:26:16Z")

</div>

Hi, I am storing different variables in the EEPROM of the Electron. My Aim is that this variables survive the DEEP\_SLEEP I call at the end of my loop(). But I don´t want the variables in the EEPROM to survive if the device is powered off. I know there is the `EEPROM.clear()` function. But is there a way I can call that function only when the electron boots for the first time?

---

<div class="post-metadata">

**Author:** ![Moors7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/moors7/32/588_2.png) [@Moors7](https://community.particle.io/u/Moors7)\
**Post date:** [June 7, 2016, 6:51am UTC](https://community.particle.io/t/solved-clear-eeprom-first-boot/23525/2 "2016-06-07T06:51:26Z")

</div>

Before you sleep, set a bool in EEPROM to indicate whether or not you’ve just slept. If you sleep, set that value to 1 to know you’ve slept. Then, if it wakes up, it checks that value. If it’s a 1, set it back to 0 and go on your way. if it’s 0, then you’ve not made it to sleep for whatever reason and you should reset all data.

Would that work?

---

<div class="post-metadata">

**Author:** ![Gecko](https://avatars.discourse-cdn.com/v4/letter/g/c4cdca/32.png) [@Gecko](https://community.particle.io/u/Gecko)\
**Post date:** [June 7, 2016, 6:56am UTC](https://community.particle.io/t/solved-clear-eeprom-first-boot/23525/3 "2016-06-07T06:56:41Z")

</div>

Thank you for your answer! But I think it won´t work since my device is in deep\_sleep for the most time. If some1 now removes the power while in deep\_sleep(which is the case the most time) the EEPROM won´t be cleared with the next bootup since the indicator is set to 1.

---

<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:** [June 7, 2016, 9:35am UTC](https://community.particle.io/t/solved-clear-eeprom-first-boot/23525/4 "2016-06-07T09:35:43Z")

</div>

On the Photon, use retained memory (backup SRAM) instead of EEPROM. It’s preserved in deep sleep, even without a battery connected to VBAT. If you are not using a coin cell battery, however, be sure to connect VBAT to GND. It’s counter-intuitive, but otherwise the retained memory won’t be reset to 0 when USB/VIN power is restored if you let VBAT float.

[https://docs.particle.io/reference/firmware/photon/#backup-ram-sram-](https://docs.particle.io/reference/firmware/photon/#backup-ram-sram-)

You can use retained memory on the Electron, but **do not** connect VBAT to GND on the Electron!

---

<div class="post-metadata">

**Author:** ![Gecko](https://avatars.discourse-cdn.com/v4/letter/g/c4cdca/32.png) [@Gecko](https://community.particle.io/u/Gecko)\
**Post date:** [June 7, 2016, 10:33am UTC](https://community.particle.io/t/solved-clear-eeprom-first-boot/23525/5 "2016-06-07T10:33:02Z")

</div>

Thank you I solve my problem with the help of your post! 👍
