Serial Monitor garbage when printing LESS text

Hi everyone,

I've been having this issue (not for the first time, but now it's unbearable) where my arduino nano will crash, auto reset, print partial messages or just garbage to the Serial Monitor.

  • Baud rate in Serial Monitor matches the Serial.begin(9600)
  • it randomly prints good and bad, with no changes in the code (just modifying, undoing and re flashing)
  • commenting or ADDING Serial prints / writes may FIX the issue.
  • tried the printing with F()
  • the program may work very properly, not work at all, or work partially (for example, it may loop, print stuff, but not make proper digital / analog writes).

So this not only affects the Serial Monitor, but the execution of the program.
That being said, I suspect it may be a memory overflow (as I'm working with several objects, pointers and arrays), but it's being very difficult to find where that is happening (i try doing freeMemory() but as the Serial Monitor works whenever it wants, it's kind of unusable).

I attach 2 images: same code, but if I print less, it crashes (chinese weird output). If I print MORE, it works...

It's like I need to add Serial Prints in order to "unclog" it and continue the execution, otherwise it dies.
Sometimes it executes twice or three times the Setup, and only then goes to the loop.

Any idea what can be happening?
Thanks!

you'll get more help if you post your code (follow the sticky with instructions)

Ok, the problem seems to be memory related.

It seems this thing starts messing up completely when it runs out of memory. So the moral of the story is: if you start running out of pins and your system is getting big, go for a Mega. And save as much memory as you can.

diegosynth:
Ok, the problem seems to be memory related.

If you want help please post your code so we can study it,

When posting code please use the code button </>
codeButton.png

so your code 
looks like this

and is easy to copy to a text editor See How to use the forum

Also please use the AutoFormat tool to indent your code for easier reading.

...R