Arduino clock and OLED display part 2

See this post here for a Joystick controlled Weather Clock with OLED display.

Although using the Adafruit libraries with the OLED was easy it uses a large amount of dynamic memory, about 90%. The code takes up just over 50% of the available memory, so there would not be much room for more code to run.

I found another library, U8GLIB that seemed to be less memory hungry, but perhaps a little slower. With this project speed is not a problem and the added advantage of this library is that it supports a wide range of display devices.

Getting the code to work with this library caused me a few headaches, but I eventually got it to go. The size of the code is almost identical to that used by the Adafruit version, but the dynamic memory usage was reduced to 48%. This would allow more code to be added later.

This library is not as simple to use as the Adafruit one, but is flexible and supports so many display devices and is well worth considering. Take a look at the website at and download the code. There is a comprehensive wiki available.

The code for this project can be downloaded from my Github page at

This version uses a smoother font (profont15) and allows the analog clock to be moved on the screen by changing to variables, clockCentreX and clockCentreY. I looked at two ways of printing numeric variables as u8g.drawstring will only display strings. You can use u8t.print, but you must first fix the print position with u8g.PrintPos(x,y). A second method, which although it looks more complicated in fact uses less program memory and that is first to convert to a const char* as follows

const char* thisTemp = (const char*) thisTemp1.c_str()

Then display using

u8g.drawStr(100,10, thisTemp)

The print position being the first two numbers 100,10.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: