Interfacing 0.96″ OLED Display with Arduino UNO

Time to interface a 0.96″ graphical OLED I2C Display with a Arduino Uno! This tiny OLED Display is useful in displaying various data from sensors, graphics and many more. In this tutorial, I’ll be showing you how you can use 2 different libraries to interface a I2C OLED Display with the Arduino Uno, therefore you have an option to choose either 1 of the library to use.

ard_096disp_p1

What are the libraries?

There are 2 libraries for available for interfacing the OLED Display, which is:

I’ll be writing 2 seperate tutorial for the respective library, starting off with the adafruit library, later going on to the U8glib library. A great thanks to Adafruit & u8glib for their graphic libraries.

 

Parts required

  • Arduino Uno x 1
  • 0.96″ I2C OLED Display x 1
  • Jumper Wires x 4
  • Breadboard x 1

 

Adafuit Library: ssd1306 & GFX library

adafruit_logo

Demo

 

Steps

1) Download the following libraries below. Both libraries are required to interface the Arduino to the OLED Display.

 

2) Extract the Adafruit_SSD1306-master.zip. Rename the extracted folder to Adafruit_SSD1306. Place the Adafruit_SSD1306 folder inside your <arduinosketchfolder>/libraries/ folder. (Which is most likely found in “My Documents/Arduino”). If there is no such folder, create one.

 

3) Repeat step 2 for the Adafruit GFX library.

 

4) Wire the arduino as shown below. Please note that if you are using an revision 3 Arduino Uno board, you have 2 options: wire it at the analog input area or the pins beside the AREF pin. For UNO boards that are before revision 3, you can only wire it one way: which is at the analog input area. For the power supply of the Display, you can either power it at 5V or 3.3V.

ard_oled_disp_old  ard_oled_disp_rev3

Why wire the SDA and SCL to (Analog pin) A4 & A5? Since the Adafruit library uses the Wire Library, the pins for the SDA & SCL pins are defined to be at A4 & A5 for I2C communication. For more information about the Wire library, visit: http://arduino.cc/en/reference/wire.

 

5) Start the Arduino IDE. Select File>Examples>Adafruit_SSD1306>”ssd1206_128x64_i2c”. I would be using the Adafruit sample code with a minor tweak, since the address of my OLED Display is different from the one used in their sample code.

ard_096disp_back

Therefore, change the address from 0x3D to 0x3C before uploading the code onto the Arduino board. Alternatively, you can copy the code below. Upload the code.

 

u8glib Library

Universal Graphics Library for 8 Bit Embedded Systems

u8glib

 

Demo

Steps

1) Download the u8glib library from https://code.google.com/p/u8glib/. Download the “Arduino” version.

 

2) Extract the zipfile (e.g u8glib_arduino_v1.16.zip). Rename the extracted file as “u8glib”. Place the “u8glib” folder inside your <arduinosketchfolder>/libraries/ folder. (Which is most likely found in “My Documents/Arduino”). If there is no such folder, create one.

 

3) Wire the arduino as shown below. Please note that if you are using an revision 3 Arduino Uno board, you have 2 options: wire it at the analog input area or the pins beside the AREF pin. For UNO boards that are before revision 3, you can only wire it one way: which is at the analog input area. For the power supply of the Display, you can either power it at 5V or 3.3V.

ard_oled_disp_old  ard_oled_disp_rev3

Why wire the SDA and SCL to (Analog pin) A4 & A5? Since the Adafruit library uses the Wire Library, the pins for the SDA & SCL pins are defined to be at A4 & A5 for I2C communication. For more information about the Wire library, visit: http://arduino.cc/en/reference/wire.

 

4) Start the Arduino IDE. Select File>Examples>U8glib>”GraphicsTest”. Uncomment the “U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);” code. (Which is located at line 88). Alternatively, you can copy the code below. Upload the code.

 

Displaying Bitmap Image

If you want to display any image onto the OLED Display, you can use the following software to do so:

Download

The software is to convert a bitmap image into a binary image. (Meaning your image will become 1s & 0s)

Steps

  1. Extract the file. Open lcd-bitmap-converter-mono.exe.
  2. Go to Edit > Options in the menu bar. Select the Image & Font XSLT files in (File Directory)/Xslt respectively. These files should be in *.xslt format. Exit the Options Dialog.
  3. To convert an image, the image have to be in BMP format and in the dimension of the screen (128×64). To do so, go to File > New Image. A new tab should appear. Click on import… & select the BMP Image.
  4. Another dialog will appear. Adjust the slider in the centre to adjust the contrast of the output binary image. The left side is the original picture, the right side will be the output image that you will see in the display.
  5. To export the binary file, go to Edit > Convert… and save the file as a txt file (meaning add a .txt behind the file name!).
  6. Open the txt file in the location you have saved in any word editor. (I would recommend Notepad++) Scroll down the file till you find a line like “b_00000000”. Copy until you see ‘ }; ‘. Capture
  7. Open the Adafruit example code. Paste the code into “static const unsigned char PROGMEM logo16_glcd_bmp[]”. You can rename it to anything you want. Used the following code to display the image:
  8. And viola! Your image should appear when you call it.

 

Troubleshooting

#error (“Height incorrect, please fix Adafruit_SSD1306.h!”) – Adafruit

If you have this error, this means that the selected size of the screen in the header file is wrong.

Open up Adafruit_SSD1306.h and scroll to the display definition line. You might see somthing like this:

As you can see, the display file resolution was set to 128*32, but what we want is 128*64. (The size of our display!) Therefore, we will uncomment the #define SSD1306_128_64 & comment out #define SSD1306_128_32.

 

Share this post:

You may also like...