OLED 128x64 vs. 128x32 / SSD1306.h size of sketch ?

Aloha,

I can't get to the bottom of this problem. I have a sketch loaded on an Arduino nano. Connected are two digital temp sensors (DS18B20) and one OLED 128x64 i2C.

When I set in SSD1306.h the value to #define SSD1306_128_32 = I can see 4 lines of text.
( display.setTextSize(1); )

Compiler states : Sketch uses 24156 bytes (78%) of program storage space. Maximum is 30720 bytes.
Global variables use 1649 bytes (80%) of dynamic memory, leaving 399 bytes for local variables. Maximum is 2048 bytes. Low memory available, stability problems may occur.

When I set in SSD1306.h the value to #define SSD1306_128_64, which would give me a the biggest display resolution with a lot of lines possible....

Compiler states : Global variables use 2161 bytes (105%) of dynamic memory, leaving -113 bytes for local variables. Maximum is 2048 bytes.
Not enough memory

So that means the nano is running out of memory because there is no space anymore to run a bigger better display resolution ?

OK I did again additional testing.....and compiler states this :

#define SSD1306_128_32

Global variables use 1027 bytes (50%) of dynamic memory, leaving 1021 bytes for local variables. Maximum is 2048 bytes. (without any code for sensors...)

#define SSD1306_128_64
Global variables use 1539 bytes (75%) of dynamic memory, leaving 509 bytes for local variables. Maximum is 2048 bytes. (without any code for sensors...)

So I am right ! Running an OLED 128x64 on a Arduino nano sucks already 75% of it's memory !!!!!

Which library are you using?
Which example?

Most SSD1306 libraries keep a buffer in SRAM e.g. 128x64 monochrome needs 1024 bytes plus a few bytes for library housekeeping.

Your Nano has 2048 bytes of SRAM. Providing you are careful, the remaining 1024 bytes will be fine for your other variables, stack etc.

The first job is to see where you are wasting SRAM. It is wise to keep anonymous strings in Flash memory e.g. with the F() macro. And to use appropriate types and sizes of variables.

The memory size warnings need common sense. You can safely have 100.0% Flash usage. Dynamic memory is more critical. If you have recursive code or large arrays in local variables it uses up SRAM.

Conventionally written programs are generally "safe" with 80% dynamic memory usage.

David.

Hi David !

Correct !! I am running out of memory for my project and I recognized that #define SSD1306_128_64 in SSD1306.h pushed it over the edge.

I downloaded and used the "Adafruit SSD1306" library.

Is there a smaller one ?

Georg

Get a bigger chip. 1284P based modules have 16K SRAM, plenty for several images.