# Photon Crashes After Setup Function

**URL:** <https://community.particle.io/t/photon-crashes-after-setup-function/56919>\
**Category:** Firmware\
**Tags:** photon\
**Created:** [July 8, 2020, 6:47pm UTC](https://community.particle.io/t/photon-crashes-after-setup-function/56919 "2020-07-08T18:47:07Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrewb1230](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@andrewb1230](https://community.particle.io/u/andrewb1230)\
**Post date:** [July 8, 2020, 6:47pm UTC](https://community.particle.io/t/photon-crashes-after-setup-function/56919/1 "2020-07-08T18:47:08Z")

</div>

Hi Everyone,  
I have been working on a school project using 2 Photon devices to monitor water pressure and toggle a water pump. I was having no issues with the project before, but for reasons I cannot understand, my code will only execute until the end of void setup, then it will crash the Photon’s firmware and blink the red SOS message (10 red blinks in between meaning “Assertion Failure”). Then after a few seconds, the photon will restart and run the program from the beginning. I have had this problem about a month or so now, and I cannot figure it out. Any information about why this is happening would be extremely helpful! My photon is currently running version 1.5.2 and runs other programs just fine. [Here is a video link (iCloud Mail Drop link) showing the error happening.](https://www.icloud.com/attachment/?u=https%3A%2F%2Fcvws.icloud-content.com%2FB%2FAb20nkH3lOIYrDxHmZ1ZHkIC03UmAZmB4AF3ZBgsHHzvyIyfajho49SE%2F%24%7Bf%7D%3Fo%3DAjMuFjAE-MLDv4qxiW2v39RUsBS8Psn-RjxAprntIsnE%26v%3D1%26x%3D3%26a%3DCAoghtXfTk5hl0873fKZA8YNU4UnneRDsIkOscU_0h0u6e8SdxDY47z9si4Y2PO30bwuIgEAKggByAD_CGUjwFIEAtN1JloEaOPUhGomMIBB5bDQYi138BFKmwj8F2rAM0bdthoebnLWJn2s1wxOSGZRqlJyJpATYXswem5aMky_AYilRJkeUsj63pxHRrsoa15VoF1MFutO3put%26e%3D1596824877%26fl%3D%26r%3DBA03B98D-897C-458F-9728-D6289039A276-1%26k%3D%24%7Buk%7D%26ckc%3Dcom.apple.largeattachment%26ckz%3DA6514048-8F8C-4DED-8272-1C5BC589DB90%26p%3D34%26s%3DXU4c-0QmuQsxki7Cj2qhDw-wVh4&uk=lbCh2TQyYwE60_aU9j2l-w&f=IMG_0856.MOV&sz=184988685)  
and [Here is a link to my code in GitHub](https://github.com/Andrew123098/GEEN_2400/blob/master/Code/PressureMonitor/src/PressureMonitor.ino)

My code compiles just fine. So far I have tried using a different photon board and resetting my photon to factory settings.

Please let me know if I can provide any other information.  
Sincerely,  
Andrew Brown

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [July 8, 2020, 7:11pm UTC](https://community.particle.io/t/photon-crashes-after-setup-function/56919/2 "2020-07-08T19:11:07Z")

</div>

> [@andrewb1230](#):
>
> it will crash the Photon’s firmware and blink the red SOS message

When seeing an SOS panic it's always good to _ **also** _ state the number of slow red blinks between the two SOS signals - this will offer some hint for potential causes.

The video shows it's and SOS+10 (assertion failure)  
[https://docs.particle.io/tutorials/device-os/led/photon/#red-flash-sos](https://docs.particle.io/tutorials/device-os/led/photon/#red-flash-sos)

These are the more obscure kind of errors as they often indicate some branch in the device OS that wasn't actually meant to be executed.

---

<div class="post-metadata">

**Author:** ![andrewb1230](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@andrewb1230](https://community.particle.io/u/andrewb1230)\
**Post date:** [July 8, 2020, 7:16pm UTC](https://community.particle.io/t/photon-crashes-after-setup-function/56919/3 "2020-07-08T19:16:38Z")

</div>

Thank you! I have updated the original post! It blinks red 10 times between the SOS messages.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [July 8, 2020, 7:19pm UTC](https://community.particle.io/t/photon-crashes-after-setup-function/56919/4 "2020-07-08T19:19:10Z")

</div>

After the display shows `DONE!` there is some time before the SOS+10 happens.  
Can you add some debug statements (e.g. on LCD or via `Serial.print()`) to better locate the code line that may be causing the panic?

---

<div class="post-metadata">

**Author:** ![andrewb1230](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@andrewb1230](https://community.particle.io/u/andrewb1230)\
**Post date:** [July 8, 2020, 7:28pm UTC](https://community.particle.io/t/photon-crashes-after-setup-function/56919/5 "2020-07-08T19:28:42Z")

</div>

Yes, I will do this a bit later today, thank you so much for your quick responses. I really appreciate it:)

---

<div class="post-metadata">

**Author:** ![friedl\_1977](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/friedl_1977/32/22930_2.png) [@friedl\_1977](https://community.particle.io/u/friedl_1977)\
**Post date:** [July 8, 2020, 7:36pm UTC](https://community.particle.io/t/photon-crashes-after-setup-function/56919/6 "2020-07-08T19:36:40Z")

</div>

Hey @andrewb1230 -

Welcome to the Particle forum, I see @ScruffR is helping out, which means you are in good hands.

_ **EDIT** _: See next post.

Regards,  
Friedl.

---

<div class="post-metadata">

**Author:** ![friedl\_1977](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/friedl_1977/32/22930_2.png) [@friedl\_1977](https://community.particle.io/u/friedl_1977)\
**Post date:** [July 8, 2020, 8:53pm UTC](https://community.particle.io/t/photon-crashes-after-setup-function/56919/7 "2020-07-08T20:53:32Z")

</div>

Hi @andrewb1230 -

ok… I spent more time going through your code trying to debug. I don’t have all the hardware required, but I put several digitalWrite checks to see whether I can fin out where things go wrong i.e.:

```auto
        digitalWrite(D7, HIGH);
        delay(200);
        digitalWrite(D7, LOW);
        delay(200);

```

Ok, so what I have found is that if I comment out all your LCD code, the sketch seems to run smoothly and keep running. As soon as I implement the LCD code, it passes through `void setup();` but never enters `void loop();`. This seems to correspond to your video.

[Here is a link](https://www.icloud.com/iclouddrive/0Mw89fzldFjdEgieHagQQKGcQ#temp) to the code that seems to be runnign smoothly with two ‘debug checks’ on D7 LED. First one in `void setup();` (fast blinking LED) and then slower blinking LED when `void loop();` is executing .

**If it was me** , would see whether the pumps are being controlled as intended without the LCD code present and monitor your events in Particle Cloud. If this is indeed the case, the bug is somewhere in the LCD code.

I| a not sure what the cause is, but at least it is a start 😉

Regards Friedl.

---

<div class="post-metadata">

**Author:** ![andrewb1230](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@andrewb1230](https://community.particle.io/u/andrewb1230)\
**Post date:** [July 9, 2020, 1:41am UTC](https://community.particle.io/t/photon-crashes-after-setup-function/56919/8 "2020-07-09T01:41:23Z")

</div>

Hi @friedl_1977,

Thank you so much for going through my code and figuring that out! I will use that knowledge to try and troubleshoot further and find a solution. @ScruffR I am going to do some testing over the next few days and see what I can figure out.

Thank you both so much for helping me!  
-Andrew Brown

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [July 9, 2020, 5:03am UTC](https://community.particle.io/t/photon-crashes-after-setup-function/56919/9 "2020-07-09T05:03:51Z")

</div>

I have seen one point that may cause issues when reworking your code some time in the future  
You have defined `const int numData = 30` but [here](https://github.com/Andrew123098/GEEN_2400/blob/master/Code/PressureMonitor/src/PressureMonitor.ino#L194) you are using `30` as literal.  
The issue will arise if you ever decided to change `numData` to something less than 30 which would result in a hard fault.

You also seem to be using an _ **always** _ uninitialised `takeDataDelayTime` in your `loop()` - I can’t imagine this is intentional.  
I guess you’d rather want this

```cpp
  static unsigned long takeDataDelayTime = 0;

```

BTW, we also advise _ **against** _ the use of `String` and rather opt for C-strings (aka character arrays).  
And the comment here is not correct

```cpp
 int interval = (6 * 1000); // Interval between readings (First number is minutes)

```

The first number is _seconds_ not _minutes_

---

<div class="post-metadata">

**Author:** ![friedl\_1977](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/friedl_1977/32/22930_2.png) [@friedl\_1977](https://community.particle.io/u/friedl_1977)\
**Post date:** [July 9, 2020, 6:05am UTC](https://community.particle.io/t/photon-crashes-after-setup-function/56919/10 "2020-07-09T06:05:29Z")

</div>

I will look bit further today. Good luck!!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/3/2/3291e3c9351789fe8620ae5bcec8d3fec67ff221.png) [@system](https://community.particle.io/u/system)\
**Post date:** [January 7, 2021, 6:05pm UTC](https://community.particle.io/t/photon-crashes-after-setup-function/56919/11 "2021-01-07T18:05:37Z")

</div>

Closed on January 7, 2021, 6:05pm UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
