128×32 I2C SSD1306 OLED Display Module Screen for Arduino Review and Code

Today I review the 128×32 I2C SSD1306 OLED Display Module Screen for Arduino and provide example code.

Overview of the 128×32 I2C SSD1306 OLED Display Module

This OLED display module allows you to display any content you want on a small display screen. This unit is a single colour display. Using OLED technology this will draw slightly less power than a standard LCD display improving its use in low power environments.

The OLED display driver uses the SSD1306 driver IC which has a supported library on the Arduino. This allows easy control on the Arduino to draw and write to the screen.

The approximate size of this module is 38 * 12 mm which allows this to be a useful way to add a screen to a project while keeping the footprint low.

A final advantage to this unit is that it can easily be used with various microcontrollers as it supports both 3.3 and 5-volt power inputs. These are the two most common power levels among IC’s.

Wiring it up to the Arduino

The OLED screen has four pins, left to right these are GND, VCC, SCL, and SDA. I am going to wire GND and VCC to the Arduino’s GND and 5 volt pins respectively.

The SCL and SDA pins have to be connected to the Arduino’s I2C pins. For my Arduino Uno these are A4 (SDA), A5 (SCL). If you are not using an Arduino Uno you can find your Arduino’s I2C pins using the reference on the Arduino website.

Programming the OLED screen to display Hello World

To program the OLED screen I am using the U8glib library for monochrome displays. library. If you are using the Arduino IDE you will need to install it using the Manage Libraries feature, the library name in the Arduino IDE is “U8g2 by oliver”.

This library allows easy programming of the OLED screen allowing both text and standard graphical shapes.

#include <U8g2lib.h>

U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0);

void setup(void) {
  u8g2.begin();
}

First the U8g2lib library is imported so that its functions can be used. Then the u8g2 module is initialized for the SSD1306 OLED display module. The parameter passed to the constructor sets the rotation to the default rotation level.

There are a number of constructors for this module but this is using the I2C constructor to access the LCD display using the standard I2C pins.

Then in the setup function, the communication with the OLED display module is started.

void loop(void) {
  u8g2.firstPage();
  do {
    //keep this the same as it pages through the data generating the screen
    u8g2.setFont(u8g2_font_ncenB14_tr);
    u8g2.drawStr(0,20,"Hello World!");
  } while ( u8g2.nextPage() );

  delay(1000); 
}

In the loop function, firstPage() is called to start drawing of the OLED.  The drawing code is inside a do while loop  so that the library can efficiently page the data across to the OLED display. By including your drawing code inside the while loop you are able to adjust how the speed and RAM tradeoff.

In fully buffered mode rendering the images onto the OLED display is much faster however it will use a lot more RAM. You can change the rendering mode based on the constructor to use less RAM. However reducing the amount of RAM used for rendering will slow down the render as it will render the images in several pages which is slower.

Inside the loop I configure which font I want to use and then draw the string “Hello World!”. The first two parameters to the drawStr function are the x and y position on the screen.

Review for the 128×32 I2C SSD1306 OLED Display Module

This simple OLED display allows you to easily add a display to any project. Its low power means that this LCD display is also useful for battery powered projects.

Even though it is quite small (0.91 inches diagonally) the resolution of the OLED display is high. This means that it is easy to read the text displayed on the screen.

Overall this is a really nice small display that can be used for many different uses. I will be writing further posts about drawing more complex data to the LCD display.

Would buy again!

2 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.