-1

Following some changes my Arduino sketch became unstable, it only run 1-2 hours and crashes. It's now a month that I am trying to understand but do not make sensible progress: the main difficulty is that the slightest change make it run apparently "ok" for days...

The program is ~1500 lines long

Can someone suggest how to progress?

Thanks in advance for your time

g2c
  • 1
  • 2
  • you can use `setDefaultUncaughtExceptionHandler ()` have a look here, http://stackoverflow.com/questions/19897628/need-to-handle-uncaught-exception-and-send-log-file implement this, and in `handleUncaughtException ()` let it save the exception in a file or something you can view later and find out whats going on. – Yazan Nov 06 '16 at 07:44

1 Answers1

0

Well, the embedded systems are wery well known for continuous fight against Universe forth dimension: time. It is known that some delays must be added inside code - this does not imply the use of a sistem delay routine always - just operation order may solve a lot. Debugging a system with such problem is difficult. Some techniques could be used:

a) invasive ones: mark (i.e. use some printf statements) in various places of your software, entry or exit of some routines or other important steps and run again - when the application crashes, you must note the last message seen and conclude the crash is after that software step marked by the printf.

b) less invasive: use an available GPIO pin as output and set it high at the entry of some routine and low at the exit; the crasing point will leave the pin either high or low. You can use several pins if available and watch the activity with an oscilloscope.

c) non invasive - use the JTAG or SWD debugging - this is the best one - if your micro support faults debugging, then you have the methods to locate the bug.

Yoan
  • 161
  • 3
  • 8
  • @Yazan: your link refers to Android, the o/p refers to Arduino, less resourcefull . Do not downvote. – Yoan Nov 06 '16 at 08:17
  • I do have traces output to the monitor and the manifestation of the breakdown has ALWAYS the same trace signature. yet It is not clear way the program crashes. As the code continues to execute while the trace is output, I don't know for sure where it breaks. I do suspect one function called immediately after the last printed trace but when reading the code I find nothing abnormal and the function -apparently- well 10 times or so before the crash – g2c Nov 06 '16 at 08:57
  • How big is your stack? Try to increase it, printf function uses a lot of stack, 2k would be a start value. Try also a pin as suggested, inside that function. – Yoan Nov 06 '16 at 09:47
  • Suspected function does NOT execute to its end! Also I found a mistake but am not sure how this can be the reason of the crash I have a global array a, the suspected function f, the caller function c Boolean f(const char* a){// this redefines a erroneously … SerialPrint(a); clientPrint(a); … }// when code crashes nothing get sent to the server Void c(){ … SerialPrint(“posting bla ”); If f(“bla”)SerialPrint(“posted bla ok”);//when code crashes nothing get printed Else SerialPrint(“failed posting bla”); //when code crashes nothing get printed … } – g2c Nov 07 '16 at 17:22
  • What type is your "a" array? (char/int/float/other) and what do you mean with expression "SerialPrint(a)"? If your function does not use any micro peripheral, then you can make a PC console program and try to debug it there (needs some tools..) or. better, as suggested, do real debug, not just serial. – Yoan Nov 07 '16 at 20:21
  • Is there a eay to post a snippet? To post more than 256 chars? – g2c Nov 07 '16 at 20:38
  • Maybe just start another new thread with the offending function(s). Take care also there is a special section for Arduino micros. – Yoan Nov 07 '16 at 21:21