Greetings to all arduino Gurus. Recently i was developing a project, by using Arduino Uno as the base, integrate with Ethernet+SD shield and a LCD shield. The objective is to use LCD as the Menu, buttons to navigate through Menu pages, and to select the .ini file read from the SD card. Whenever any of the .ini file is selected, it will read that .ini file to find the Section/key and send the values/data by Ethernet via TCP. Hope I had gave you the rough idea on how it work now.
I had it minimized the RAM memory utilization. But problem came when it run for a few Menu navigate, or after sending the data to Ethernet. Sometimes it shows "Buffer too small" error in Serial (debugging), and always the characters show in the LCD is distorted (sometimes it hang and arduino restart itself!).
The weird part is, FreeRam() shows it still has around 600bytes available!
Attached the code below: (sorry that it has 29800byte size and messy coding :~)
Where did you get this idea? A C-style string uses a fixed amount of memory, that you determine. Thus, if there is enough memory now, there always will be.
I do really had lost and no clue at all to fix this right. So perhaps i think the arduino Uno doesn't fit my project.
Just a basic read data from SD and serial, concatenate the data and put it into a buffer, send via Ethernet TCP and lastly, navigate Menu and display information on LCD. Is these too much for an Uno? :~
I will try to rewrite my code to avoid using string, thanks for your advice. I'm not pointing the fault at Uno, just maybe or I thought I had consume all the memory in some way as you said (but how do i determine that? FreeRam() shows sufficient).
Besides, could you share some lights on how or under what circumstance, the memory is depleted/insufficient?
}else if (x==0){
lcdDisplayBtm(B10100000," BTN2",B01111110);
}else{
lcdDisplayBtm(B01111111,"BTN1 BTN2",B01111110);
There's another 70.
Can i ask a silly question, does the RAM always increasing when it loop? Or is it allocated a fix size for them?
In my loop(), i use FreeRam to monitor the memory changes. But it constantly feedback the same amount (~600b), despite I navigate the Menus, or reading and sending data via Ethernet. So I assumed I still have free memory.
What I understand of fragmentation is the computer program request block of memory, holds it and when finish, it release back the memory in chunk. Eventually the chunk is chopping into different sizes, thus, at the end the program could not request a larger chunk of memory. That's leads to data fragmentation. Please correct me if I'm wrong.
If that so, how do we overcome this problem?Fragmentation.
Remember that memory is used temperarily by the stack when calling functions,
and depends on the function called - unless you leave a generous amount free
you won't have peace of mind that the same code will always run safely, since the
arguments to a function can affect its pattern of calling and thus maximum stack
use.
I recommend making as much of the big memory gobblers statically allocated/declared
so that there are no surprises later on. You can then be reasonably confident that
the free memory measured at the end of setup() represents most of what's available
to the stack for the rest of the sketch.
Sometimes you can't do this because of the way a library has been implemented
of course.