Arduino plus LCD crashing when printing on LCD

Hey Guys

We are a couple of dudes who have a big problem. We are creating an interface of several menus using the LCD Library but we have now reached a limit for how many different printlines we can have in the source code. We are not printing these lines in the on the same time, but if we create too many different printlines the program simply chrashes, even though the added printlines arent even the one being loaded. We still have a lot of space left on the Arduino. So any ideas to what can be wrong or a solution to the probelm?


remove the String class from your code and/or google for the F() macro.

posting your code might give you a more elaborated answer

Our code is plus a 1000 lines long so it won´t make much sense posting it when the problem is not a specific code but adding any more code of lcd.print(" ......"); which causes the chrash.

Sounds like a general program size issue more than a specific LCD.print("...."); issue.

When you say the program crashes, does the Arduino crash? Or the download crashes? Or the compile crashes?

The display either shows random things or just shuts down.

Which display? The LCD display?

So, the download works fine and the Arduino starts up? Random things on the display doesn't sound like a crash necessarily.

Have you tried replacing all the lcd.print() with Serial.print()? That should let you know if it's a size issue, and if the "random" characters are the same out the serial port.

We are printing on a simple 20x4 LCD display, we are not printing in the serial port. So yeah it is the LCD display that prints, some times different prints on the same time mingled into each other (when it fails), or it prints nothing but squares (when it fails).

The same thing happens if we try using the Serial.print("").

More specific nothing happens in the serial port.

Yes, but if you replace all calls to lcd.print() with Serial.print() and you still have the problem, then it's a probably a general size issue. Plus, you get to see what order the prints are coming out in, and where it might be going wrong.

What size is the sketch download saying the total filesize is?

When i tried changing all the lcd to serial prints nothing happened if there were "too many" prints but if i commented 2 prints out again it worked just fine.

THe sketch size is around 16.000 bytes right now. The maximum size for the arduino should be around 32.000 bytes, so the general size shouldn´t really not be a problem

OK, I think this is your problem:

There's only 2k of static ram on an arduino uno. Each use of "..." in a print takes up static ram. You need to either combine then into a function call, or put the strings in PROGMEM and use the variable in the print instead.

It is the last two blocks in the code in the bottom (which is commented out because they causes the error).

DrunkBot_07_10_13v2.ino (37.3 KB)

Yep it definitely looks like the static memory problem.

I would put all your strings in a table in PROGMEM. That'll free up static memory, but it will also make your code a lot simpler as you won't be duplicating all your LCD setup commands.

Thanks Im going to try it !

The simplest solution would be to use PROGMEM as suggested above. If you are using Arduino IDE 1.0, you can replace lcd.print("your text"); with lcd.print(F("your text")); F() is a macro to ease the use of PROGMEM and give it a more natural feel.

Does this method F() also apply to the Arduino 1.0.4 ?

Yes, it was introduced in 1.0, and available in the newer versions too.