Hello All. I'm currently working on a project on a Nano that uses an OLED 128x32 screen, RTC and SHT21 Temp sensor.
All compiled fine well below the 30720bytes until I added code to switch between time and temperature.
The loop runs 2 functions: checkButtons and checkPane.
Compiled size without these 2 functions: 11236bytes
Compiled size with just checkButtons: 11508bytes
Compiled size with just checkPane: 24750bytes
So I would have expected a compiled size of around 25022bytes however it compiles at 34960bytes.
It appears to be the check buttons function. It increments a global variable upon pressing a button:
paneSelect = (paneSelect + 1) % PANE_END;
However if I use a local variable it compiles at 24780bytes.
Hi guys, thanks for your replies. I've stripped down the code (removing the splash screen). Which compiles as 20300Bytes. If I comment out the checkButtons function in the main loop it compiles as 14806bytes. Here is the code:
After working with it today. The largest memory usage is due to the fonts so wanted to see if I could reduce that. I was using 3 fonts which were using 3k~ each. So I've created my own font which has reduced my compiled project from 34k to 18k. Although this doesn't address the issue that causes the memory usage to jump up around 4k when altering the global values (If I compile now without altering the global values it compiles at 15k). Even its just setting them to 0, taking modular division out of the code. I wonder if arduino is allocating 4096bytes for this regardless of the complexity, which is why the memory usage is jumping up so much... who knows.
It is the link time optimizer.
When it detects that paneSelect is always PANE_TIME, it removes unused code and data corresponding to case PANE_TEMP. This includes two fonts that take about 4 kilobytes.