Reducing memory usage of SSD1306 0.96" OLED SPI on UNO/atmega328

Hi, I've a similar SSD1306 0.96" 128x64 OLED SPI running on UNO / Atmega328.. http://www.electrodragon.com/oled-spi-wiring-tutorial/

I notice the memory usages are very high and after loading GPS libs and other stuff... the memory free is too low...

Is there a way to further reduce the memory usage ?

I'm using it primary to display text like lat,lng,speed, alt, sat... and not any graphics

I notice there is a BIG video buffers reserved for the splash screen logo.. can I do away or reduce with the video buffers or moved it to the flash with F() macro or something ??

I was left with 239 bytes and during runtime, only 179 bytes left and this is just my prototype to test out the OLED display...

My codes are at the link below if anyone interested ... http://pastebin.com/ksQRryLT

This is the first time I'm working on OLED display ..

Thanks

Stanley

Hey Stanley, I had the same problem. There is a library called SSD1306ASCII on github that should help you. I took that library and trimmed it a bit more and added character scaling so I could also output larger characters (up to 8 times the 5x7 single size). Using the original graphics library I created a simple “hello world” sketch that used 10.5K and 1366 bytes of ram. Replacing that with my modified ASCII library, the sketch shrunk to 5.6K and only 48 bytes of ram.

If you want my library I’ll send it to you. I haven’t finished cleaning it up but it works.

Just to be clear, you can't simply remove the 1K buffer. It isn't there to only hold the splash screen, it is the buffer that the graphics library uses. The 1306 display memory is not readable when connected via SPI so in order to do graphics you need to keep a copy of all the pixels in ram. But you don't need that buffer for text.

Yes... pls send me a copy.. thank you..

Yes, I understand there are only MOSI connected, I guess those 1k are video buffers to store all the pixel to be drawn on the screen... needed to be sent via SPI to the OLED ...

Or else I would hv to resort to adding SPI ram found at http://www.gammon.com.au/forum/?id=10979

I will PM you my e-mail addr...

Stanley: Or else I would hv to resort to adding SPI ram found at http://www.gammon.com.au/forum/?id=10979

Interesting, I hadn't seen those before.

Dear J…

Thanks a lot, really appreciate your memory saver text only libs … +1 to you …

Those SPI RAM looks interesting too…

Stanley

Those others looking for this SSD1306 SPI text only libs :-

The github links are here : Sd1306 text only library

I attached the latest version I’ve been using. Feel free to put it on github. It is faster, supports I2C as well, has some small bug fixes and also has optional larger numeric font support.

I know of a way to speed it up some more but not sure it’s worth the trouble or not. Also, I have some one inch 128x64 LCDs that use ST7565R controllers that I plan to port this code to. Someone who can really write software could take the concept of this library and generalize it. It won’t be me. :-)

OLED_text_HW_SPI_example.ino (1.26 KB)

readme.txt (1.52 KB)

SSD1306_text.cpp (14 KB)

SSD1306_text.h (4.32 KB)

ssdfont.h (14.3 KB)

Dear jboyton..

This is great news .. I hv plans to moved to SSD1306 I2C versions due to lesser pins ... This updates for the text only SSD1306 libs comes just in time...

I tried to compiled it on Arduino 1.6.3 and gets a lot of compilation errors... Could you help to look into this ?

THANK YOU

Hi Stanley,

I just saw your post. I’m using 1.0.6 but when I try to compile with 1.6.3 or 1.6.4 I get errors too. I have been hesitant to upgrade to 1.6.x. To be fair, I did not set out to write very portable code; I mainly just wanted something to work for me.

The errors I am getting in 1.6.3 are about PROGMEM variables not being defined as const. Is that what you get or are you seeing additional errors?

edit: I got the example sketch to compile (in both SPI and I2C). The new IDE requires Wire.h to be included in the sketch, even if you are using SPI. And I was apparently using a deprecated method for declaring PROGMEM variables. The old IDE didn’t mind this but the new one is less tolerant. I’ve attached the two files I modified to get it to compile. Let me know if this isn’t the whole story.

SSD1306_text.cpp (14 KB)

ssdfont.h (14.3 KB)

Dear jboyton…

Yeah I understand that you meant…

I updated the 2 files and added #include <Wire.h> to the example files…

On Arduino 1.6.3, I got the following compile errors… ( I pasted to pastebin.com )

Stanley

That's a lot of errors! :-)

It isn't finding the definition of some of the more recently added methods. Is it possible you have an older version of SSD1306_text.h?

My mistakes..

The compile work fine..

Sketch uses 7,208 bytes (22%) of program storage space. Maximum is 32,256 bytes. Global variables use 275 bytes (13%) of dynamic memory, leaving 1,773 bytes for local variables. Maximum is 2,048 bytes.

I tried to compile it for I2C with the following:-

#define I2C 1
#define RESET_PULSE 0
#define HW_SPI 0

// Hardware SPI pins include D11=Data and D13=Clk
#define OLED_DC 5
#define OLED_CS 6
#define OLED_RST 9
SSD1306_text oled(OLED_DC, OLED_RST, OLED_CS);

I can get it to compile and uploaded to the Arduino UNO with I2C OLED ..

but nothing was displayed on the screen...

DO you hv an example for I2C ??

Is that snippet supposed to be taken from your sketch? If so then you are compiling it in H/W SPI mode.

You must define I2C equal to 1 in SSD1306_text.h, not in the sketch file.

In your sketch you have to use the appropriate constructor. You have the H/W SPI constructor above. There is no DC or CS with I2C. The I2C constructor takes either one parameter, the reset pin, or zero parameters, depending on how you define RESET_PULSE in the .h file. If you try to use the wrong constructor you will get a compile error.

It's a little clunky, I admit. The Adafruit code does it a little more smoothly. It uses the constructor type to select the interface. That way you don't have to edit the .h file in the library. But it doesn't come for free, unfortunately. There is some cost in code/RAM. Or maybe I did it wrong, I'm not sure.

Using the examples with the following changes :-

#include <Wire.h>
#include <SPI.h>
#include <SSD1306_text.h>

SSD1306_text oled();

I’ve also edited the SSD1306_text.h with the follow :-

#define I2C 1
#define HW_SPI 0
#define RESET_PULSE 0

Compiling it , I got the following errors, pls help… :-

OLED_text_I2C.ino: In function 'void setup()':
OLED_text_I2C.ino:12:10: error: request for member 'init' in 'oled', which is of non-class type 'SSD1306_text()'
OLED_text_I2C.ino:13:10: error: request for member 'clear' in 'oled', which is of non-class type 'SSD1306_text()'
OLED_text_I2C.ino:16:10: error: request for member 'write' in 'oled', which is of non-class type 'SSD1306_text()'
OLED_text_I2C.ino:19:10: error: request for member 'setCursor' in 'oled', which is of non-class type 'SSD1306_text()'
OLED_text_I2C.ino:20:10: error: request for member 'setTextSize' in 'oled', which is of non-class type 'SSD1306_text()'
OLED_text_I2C.ino:21:10: error: request for member 'write' in 'oled', which is of non-class type 'SSD1306_text()'
OLED_text_I2C.ino:25:10: error: request for member 'setCursor' in 'oled', which is of non-class type 'SSD1306_text()'
OLED_text_I2C.ino:26:10: error: request for member 'setTextSize' in 'oled', which is of non-class type 'SSD1306_text()'
OLED_text_I2C.ino:27:10: error: request for member 'print' in 'oled', which is of non-class type 'SSD1306_text()'
OLED_text_I2C.ino:30:10: error: request for member 'setCursor' in 'oled', which is of non-class type 'SSD1306_text()'
OLED_text_I2C.ino:31:10: error: request for member 'sendData' in 'oled', which is of non-class type 'SSD1306_text()'
OLED_text_I2C.ino:32:35: error: request for member 'sendData' in 'oled', which is of non-class type 'SSD1306_text()'
OLED_text_I2C.ino:33:10: error: request for member 'sendData' in 'oled', which is of non-class type 'SSD1306_text()'
OLED_text_I2C.ino:34:10: error: request for member 'setCursor' in 'oled', which is of non-class type 'SSD1306_text()'
OLED_text_I2C.ino:35:10: error: request for member 'sendData' in 'oled', which is of non-class type 'SSD1306_text()'
OLED_text_I2C.ino:36:35: error: request for member 'sendData' in 'oled', which is of non-class type 'SSD1306_text()'
OLED_text_I2C.ino:37:10: error: request for member 'sendData' in 'oled', which is of non-class type 'SSD1306_text()'
Error compiling.

Remove the parentheses in your constructor:

SSD1306_text oled;

Thanks... that was easy...

Hi,

The compile works fine and I hv uploaded to the Arduino UNO with a working I2C SSD1306 OLED module..

Nothing was showing on the 0.96" OLED display... Pls help...

Another questions, doesn't the code below in the sketch overwrite the header files ??

#define I2C 1
#define HW_SPI 0

No, it doesn't. I wish it did!

Does your I2C display work with a different library?