Sketch Files is to big

Sketch uses 38268 bytes (118%) of program storage space. Maximum is 32256 bytes.
Global variables use 273 bytes (13%) of dynamic memory, leaving 1775 bytes for local variables. Maximum is 2048 bytes.

Can someone give a hint how to reduce size other than changing the code? does upload in hex file will do it?

If you're not prepared to make code changes, your best bet is to buy more capable hardware.

may be you could try to use gzip to compress the binary file... That will definitely reduce the size.

:innocent: :crazy_face:

No, because Its not possible.

the requirements are incomplete :slight_smile:

it is possible, but it won't run anymore... would that be an issue?

1 Like

How about turn to hex file?

that does not mean anything.

what you upload is compiled, it's binary code that the micro-controller can understand.

I've never double checked what's the default optimisation compile flag, there is the -0s that is optimization for code size (but this is likely what's already used)

not knowing your code at all it's really hard to give an advice that makes sense, but anyway....take look at included libraries in your declare section, maybe there are libraries you wont fully use so you can use other libraries optimized for your main code.
if you do not want to modify your code.... there are no a magic solutions other than get bigger hardware

The code being uploaded to the arduino is already a hex file that has been generated by the compiler.

Modifying the code is the only way to reduce the code size, and exactly which modifications are needed will depend on the code (if a size reduction is even possible). If you post the code you will get more specific suggestions.

there are compile options that have impact on the generated code but I think it's already optimized for size (-Os)

As far as I recall that is correct.

The OP did not say which Arduino they were using.

With the mini core (ATmega328P) for instance you can turn link time optimisation (LTO) on\off, so it could have been off in the example given, so turning it on would probably reduce program size, but that then would be ' changing the code'.

I think it's safe to assume OP meant source code, and that regenerating the binary was OK.

@danieltianussan, your topic has been moved to a more suitable location on the forum.

Does your sketch have a very large number of string printing instructions?
If you have, you can modify their use.
Using instructions rationally does not mean changing the essence of the sketch.

RV mineirin

The OP could clarify, so we dont have to assume.

Unless it is incredibly unusual code, NO compiler optimization is going to reduce size by anywhere near 18%...

Thanks all usually the code can be modified just want to check is there other ways to work efficiently. Thank you all

Sometimes it is possible to replace code with a table. A small piece of code will do what is in the table.
Sometimes it is possible to replace a library with a smaller library.

However, if you have a lot of different sequences for a ledstrip, then there is not much that can be done.

If you use the newest Arduino IDE, then the optimization for size and the "LTO" optimization are already turned on. That means the compiler can already put an incredible amount of code into the Arduino flash memory.
If you want more than "incredible", that is not possible.

Nevertheless, if you show your sketch and tell for which Arduino board it is, then we might help to reduce the code here and there and perhaps we can advice which parts can be removed.

yea i have optimize the file into the requirement under 32k byte, but I curious about the LTO optimization is it apply in all arduino?