Pages: [1] 2   Go Down
Author Topic: Arduino plus LCD crashing when printing on LCD  (Read 577 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

Thanks!   
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12483
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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

posting your code might give you a more elaborated answer
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Sr. Member
****
Karma: 12
Posts: 380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Do not IM me. I will not respond. Ask questions in the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The display either shows random things or just shuts down. 
Logged

Offline Offline
Sr. Member
****
Karma: 12
Posts: 380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Do not IM me. I will not respond. Ask questions in the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

More specific nothing happens in the serial port.
Logged

Offline Offline
Sr. Member
****
Karma: 12
Posts: 380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Do not IM me. I will not respond. Ask questions in the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 
Logged

Offline Offline
Sr. Member
****
Karma: 12
Posts: 380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, I think this is your problem:

http://arduino.cc/en/Tutorial/Memory

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.
« Last Edit: October 07, 2013, 03:27:48 pm by arduinodlb » Logged

Do not IM me. I will not respond. Ask questions in the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.27 KB - downloaded 7 times.)
Logged

Offline Offline
Sr. Member
****
Karma: 12
Posts: 380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Do not IM me. I will not respond. Ask questions in the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Im going to try it !
Logged

Israel
Offline Offline
Sr. Member
****
Karma: 4
Posts: 278
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Pages: [1] 2   Go Up
Jump to: