16x2 LCD with Arduino UNO

:disappointed_relieved: :disappointed_relieved: :disappointed_relieved: :disappointed_relieved: :disappointed_relieved: :disappointed_relieved:
I need some advice on coding something is strange
I have written couple of apps using the LCD and never had this issue
i’m not sure if my app is getting too big for the Uno or not
but there seems like i reach some point then the arduino does funny things
but as soon as i remove 1 line for the LCD
it works. There are other lcd.Print code lines which all work fine, but I really do not know what is going on.

Perhaps it’s my structures or the way i initialize them. Can someone help?

Heard of anything like that?

You will see i have attached two files. one with code that is working, the other with code that is not working. The only difference is in the Non Working code i enable the following line

lcd.print(“Loading done…”);

But the Arduino resets before this line and restarts.

Working_Code.txt (13 KB)

Non_Working_Code.txt (13 KB)

I need some advice on coding something is strange

Hey, you've come to the right place. We're experts on coding strange stuff.

The only difference is in the Non Working code i enable the following line

lcd.print("Loading done..");

When you add a function call containing a static string,that string is stored in SRAM. When adding one more causes your program to stop working, it's a clear sign that you have run out of memory.

You'll need to reduce the number of strings, the size of the strings, or use PROGMEM to store (some of) the strings.

Your code is pretty neat! I don't see this very often, although you included liquidcrystal twice. My analysis:

1.You used up about 1K SRAM on your variables, mainly on your structs. 2.You also have lots of string outputs to serial and lcd, with hundreds of bytes also unfortunately in SRAM. 3.You also use some SRAM to manipulate strings in calls so your stack is fluctuating as you perform calls and one of the calls can end up crashing the stack with the hash.

Like Paul said, use PROGMEM keyword to store strings in FLASH so your #2 is in control. All you need is one buffer to copy strings from FLASH and then dump the string to serial or lcd the same way you do it with string literals.

Besides, my blog post may help a bit: http://liudr.wordpress.com/2011/03/07/optimizing-your-program/

You may like this too: http://liudr.wordpress.com/2011/04/15/organize-your-code-big-ascii-art-font/ One question: what is the compiled size of your code as reported by arduino IDE?

Hey Paul and Liudr,

Thanks a mil for the advice. (ah yeah, i saw the double lcd inclusion) I will definitely follow it. Will let you know how it went.

May take a couple of days.

http://www.arduino.cc/en/Reference/PROGMEM

Good place to start you 2 day journey :)

Hey All,

Sorry I'm only posting now....a bit buzy. :) :D

It worked....an it made me simplify my code even more.

Thanks all.