Tim is currently doing research in Internet of Things (IoT). His desire to spread the concept, ideas, and experience of IoT.
The OLED screen which I am using in this tutorial supports 128X64 pixels. There are many OLED screen available in market. I this article I have used OLED 128x64 I2C display SSD1306 which has its screen split in two colors, yellow (16 pixels from top) and sky blue (next 48 pixels).
The following figure shows structure of OLED Screen.
You first need to connect OLED screen to Arduino. Please use following schemetic to connect the screen to Arduino.
The OLED screen is connected to A4 and A5 pins of Arduino as these pins serves as I2C interface.
I2C is Short for Inter-integrated Circuit which is a protocol that allow multiple slave digital integrated circuits (chips) to communicate with one or more master chip. I2C uses two lines to send and receive data i.e. a Serial Clock pin (SCL) and a serial data pin (SDA). Arduino has twice SDA and SCL because A4 can be used as SDA and A5 as SCL.
See following diagram
In the example below I am simply displaying Coca Cola logo for five seconds as the Arduino boots and after that a welcome message is displayed. This kind of example can be used when you are making a commercial device and you want to display your company logo as the device boots and after that an interface should be displayed.
Just watch following video.
In following section I'll show you how you can display any image with 128X64 resolution to the OLED display.
To display a logo, a Coca Cola logo in my example, you need an image.
Just do a Google search for Coca Cola image as follows.
save the coca cola image that you like. Now open the Photoshop and create a new image file with 128X64 resolution as follows.
Insert the image that you downloaded in Photoshop and resize it to fit to your 128x64 canvas the go to Mode->Grayscale to convert image to grayscale as shown below.
The image is now converted to grayscale. Save this image as jpg file.
Next open the paintbrush application on windows and in paintbrush application open the jpg file that you just saved. After the file is opened in paint, save it again as monochrome bitmap file using paintbrush as shown below.
The image will be converted to monochrome bitmap as shown below.
Now before we can use this image in our Arduino code in order to display it on OLED display, it should be converted to C Programming array. To do this I am using LCD image converter software.
Open the LCD image converter and create a new image and named it cola as shown below.
After creating the image file, import the cola.bmp bitmap image to LCD image converter image as follows.
The imported image will be shown as below.
Now go to Options->Conversion...
The following dialog box will be shown.
In the following dialog box select Preset as Monochrome and under Prepare tab select type as Monochrome and Threshold Dither, also under Image tab in same dialogbox select Block Size as 8 bit. Follow the instructions in images below.
Go to File->Convert... and save the file as cola.c.
The created cola.c source file looks like following.
The source code of cola.c file is following.
We will use the array initialization from above C source file into our Arduino code below.
Now copy the following Arduino code and compile & upload it to your Arduino board which has OLED display connected.
The following output will be displayed
Just try my another example given below. I will show you how you can display simple text and image together at different coordinates.
For this example I have created a battery image of 20x10 pixels with white foreground and black background.
Second Example Code
Following will be the output of above code.
This article is inspired by OLED Guide by RandomNerdTutorials. For more details on installing libraries and different library functions to draw text, shapes and images please visit Guide for I2C OLED Display with Arduino.