EmbDev.net

Forum: µC & Digital Electronics Data section exceeds available space in board


von Cliff W. (cliff)


Rate this post
useful
not useful
I'm making a small game on LCD from Stone recently and I want to use 
Arduino UNO to do it. My code compiles without problems, but when I 
upload it, I get an error like the one shown in the picture, is it 
because I have too many variables defined?
Can someone please tell me how to fix it?
1
Arduino:1.8.12 (Windows 10), Development board: "Arduino Uno"
2
3
The project uses 6336 bytes, which occupies (19%) of the program storage space. The maximum is 32256 bytes. data section exceeds available space in board
4
5
Global variables used 3046 bytes, (148%) of dynamic memory, leaving -998 bytes for local variables. The maximum is 2048 bytes.
6
There is not enough memory; visit the following URL to follow the instructions to reduce memory usage.
7
http://www.arduino.cc/en/Guide/Troubleshooting#size
8
Error while compiling for development board Arduino Uno.
9
10
Turn on in File -> Preferences
11
"Show detailed output during compilation" option
12
This report will contain more information.

: Edited by User
von Cliff W. (cliff)


Rate this post
useful
not useful
And I don't know why the code looks like this, I added it according to 
the format of the website.

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Cliff W. wrote:
> Global variables used 3046 bytes
Thats the actual problem: you have one or some big (text) arrays or 
pictures or something else with need for RAM in your code.

Attach your code as a file, then its easy to say where the problem is 
located.

> And I don't know why the code looks like this
Some kind of rendering problem since the last change of the forum 
software.

von fop (Guest)


Rate this post
useful
not useful
Maybe you can leave some constant data in flash space. PROGMEM is the 
magic word. But without source code no one could tell.

von Cliff W. (cliff)


Attached files:

Rate this post
useful
not useful
I added the code file as an attachment.

von flip (Guest)


Rate this post
useful
not useful

von flip (Guest)


Rate this post
useful
not useful
reduce redundant text strings inside println statements or transfer 
these strings into program mem.

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Lothar M. wrote:
> you have one or some big (text) arrays
As expected: those "constant" strings are located in RAM. Each of the 44 
strings is over 90 chars long and so its easy to see, that they sum up 
to nearly 4k. The whole magic is here, that the compiler does some 
optimizations to reduce that size to only 3k...

flip wrote:
> transfer these strings into program mem.
Thats the best way, because even when you keep them in RAM they are in 
the program mem also, as they are needed to initialize the RAM at 
startup.

But I would not stupidly transfer those strings to FLASH/PROGMEM. 
Instead I would look for similarities and doubles and place them only 
one time in the FLASH/PROGMEM.

So the strings

"ST<{\"cmd_code\":\"set_enable\",\"type\":\"widget\",\"widget\":"

and

"ST<{\"cmd_code\":\"set_image\",\"type\":\"image\",\"widget\":"

are used throughout the whole program several times. Its enough to 
define them only once.
Or even more: those two parts of that strings are the same:

"ST<{\"cmd_code\":\"set"

and

"\",\"type\":\"widget\",\"widget\":"

so only the two parts "enable" and "image" must be changed.

: Edited by Moderator
von Cliff W. (cliff)


Rate this post
useful
not useful
>
> So the strings
>
> "ST<{\"cmd_code\":\"set_enable\",\"type\":\"widget\",\"widget\":"
>
> and
>
> "ST<{\"cmd_code\":\"set_image\",\"type\":\"image\",\"widget\":"
>
> It's enough to define them only once.

I think what you are saying can be implemented, except that I need to 
modify the code to add loops or arrays? I'll try following your 
direction.

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Cliff W. wrote:
> except that I need to modify the code
For sure.

> to add loops or arrays?
Why loops?

Try it somehow like that:
1
char str_enable[] = "ST<{\"cmd_code\":\"set_enable\",\"type\":\"image\",\"widget\":";
2
char str_image[]  = "ST<{\"cmd_code\":\"set_image\",\"type\":\"image\",\"widget\":";
3
:
4
:
5
    Serial.print(str_image);
6
    Serial.println("\"image2\",\"image\":\"circle\"}>ET");
7
:
8
:
9
    Serial.print(str_enable);
10
    Serial.println("\"button1\",\"enable\":false}>ET");
11
:
12
:
13
    Serial.print(str_image);
14
    Serial.println("\"image1\",\"image\":\"circle\"}>ET");
15
:
16
:
17
    Serial.print(str_enable);
18
    Serial.println("\"button2\",\"enable\":false}>ET");
19
:
20
:



Of course also you cold simply look for the F() macro and use it in the 
Serial.println() function call.

: Edited by Moderator
von Cliff W. (cliff)


Rate this post
useful
not useful
Ok, thanks for your patience, I tried the F() method and managed to 
upload it to the board! I'll try to make the code shorter later too.

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.