1

Background: I have made a standalone Arduino board using Atmega328PB. I have written code for a clock which lights LEDs based on the time. After a day or so it locks up. Sometimes it reboots. I would like to get debug software that will tell me where in the code it is locking up or crashing.
It could be a memory issue - stack and heap crashing(?). Compiler tells me sketch is using 62% of 32256 bytes storage space. Global variables use 34% of dynamic memory leaving 1332 bytes for local variables of 2048 bytes total.

Question: Is there relatively cheap ( < $100) debugging software that is not very complex I could use to solve this issue?

RickH
  • 41
  • 1
  • 7
  • serial.print() instructions placed in the program and serial monitor – jsotola May 12 '20 at 17:07
  • did you use `String`? – Juraj May 12 '20 at 17:20
  • @jsotola actually that's not really debugging (but afaik the only way on an Arduino) – Michel Keijzers May 12 '20 at 17:22
  • 1
    Atmel Studio and a real hardware debugger. It's hardware you need, not software. Also remove `String` from your code. – Majenko May 12 '20 at 17:41
  • 1
    I am not using String in my code. – RickH May 12 '20 at 17:52
  • What hardware would I use with Atmel Studio? – RickH May 12 '20 at 17:53
  • 1
    @MichelKeijzers, it is a sad state of affairs with debugging the arduino .... i have been using an array of integers ... various points in the program increment one of the integers ... a button press dumps the array to serial ... it avoids time delays due to multiple serial.print() statements within the program – jsotola May 12 '20 at 18:00
  • you could use the watchdog interrupt to print some information about the state of the MCU and then let the watchdog reset the MCU – Juraj May 12 '20 at 18:05
  • I did read about the watchdog interrupt. Do you know of a good link I could learn about it and how to print the state of the MCU? – RickH May 12 '20 at 18:09
  • https://github.com/per1234/WatchdogLog – Juraj May 12 '20 at 18:14
  • Thanks Juraj! I will study that. – RickH May 12 '20 at 18:18
  • @jsotola that's approximately the same as I also did some debugging (except for the button which is a good idea). But also the lack of memory makes this hard to 'store' some data (as lack of SRAM is already an issue without this way of 'debugging'). Testing all non-Arduino related code via a separate PC program/unit tests is also a good idea, but of course you cannot test Arduino specific code this way. – Michel Keijzers May 12 '20 at 21:05
  • If you suspect there is a memory leak, you may want to Serial.println the [freeMemory](https://playground.arduino.cc/Code/AvailableMemory/) in your loop. – hcheung May 13 '20 at 01:31
  • @hcheung I will try printing free Memory. I did not know of the MemoryFree Lib. I just let it run for 14 hours with serial prints throughout and it went into a strange mode. It went to a function from Loop and just kept going through the function like it was in a while loop. Then every 7 seconds it would randomly go back to loop and go to a few other functions, and in one function went through if and else statements like they were both true, then back in the first function as if a while loop again....then repeat. I reset the board and runs fine. Lets see what FreeMemory tells me. – RickH May 14 '20 at 12:02

0 Answers0