What the heck is my Arduino doing?

Recently I was working on a program where I needed to write a ton of information to the serial monitor.

Well... all of a sudden some super weird things started happening. If statements wouldn't execute sometimes, other times, the program would appear to just stall.

After ripping out what little of my locks of love which I have left (aka hair on my head), I turned on verbose mode in the Arduino compiler.

PS- to turn on verbose mode, aka tell me all the gory details about what the compiler is doing, go to File\Preferences then click on verbose mode.

Well, well, well... what did we see there?


But how could it be, my program really wasn't doing anything aside from a bunch of printf's.

After some digging, I realized that whenever you call Serial.print it's storing that in SRAM of which we have precious little in our beloved Arduino Uno which uses the Atmega 328p chip.

UGH.. what now?

Well after consulting the great google, I realized that there is a workaround.

Instead of using the serial monitor like this

Serial.println("Hi, I used up all of Dr.Duino's memory");

Just change it to

Serial.println(F("Hi, I used up all of Dr.Duino's memory"));

What does that lowly F do? Great question.

It tells the compiler to use your flash memory which you have tons of instead of your RAM.

and TADAAAAA.... my program compiles again and isn't acting all squirrely.

Well.. thought I'd share that nugget of love with you as I only have a few sprigs of hair left and that was driving me nuts.