ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

Display Image on OLED Screen Using Arduino

Updated on November 21, 2019
timothy-malche profile image

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

Source

Recommended Reading


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.

/*******************************************************************************
* image
* filename: unsaved
* name: cola
*
* preset name: Monochrome
* data block size: 8 bit(s), uint8_t
* RLE compression enabled: no
* conversion type: Monochrome, Threshold Dither 128
* bits per pixel: 1
*
* preprocess:
*  main scan direction: top_to_bottom
*  line scan direction: forward
*  inverse: no
*******************************************************************************/

/*
 typedef struct {
     const uint8_t *data;
     uint16_t width;
     uint16_t height;
     uint8_t dataSize;
     } tImage;
*/
#include <stdint.h>

static const uint8_t image_data_cola[1024] = {
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf1, 0xf0, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0x80, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x1f, 0xfe, 0x1f, 0xff, 
    0xff, 0xff, 0xfe, 0x0f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x0e, 0x38, 0x07, 0xf8, 0xdf, 0x3f, 
    0xff, 0xff, 0xf8, 0x3f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x39, 0x3e, 0x03, 0xf1, 0xde, 0x7f, 
    0xff, 0xff, 0xf0, 0x7c, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x73, 0x3f, 0x80, 0xe3, 0xbc, 0xff, 
    0xff, 0xff, 0xe0, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xe7, 0x7f, 0xc0, 0xc7, 0xf1, 0xff, 
    0xff, 0xff, 0x83, 0xf9, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc3, 0xcf, 0x7f, 0xf1, 0x8f, 0x03, 0xff, 
    0xff, 0xff, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x9e, 0x7f, 0xff, 0x18, 0x0f, 0xff, 
    0xff, 0xfe, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x0f, 0xbe, 0xff, 0xfe, 0x30, 0x3f, 0xff, 
    0xff, 0xfc, 0x0f, 0xf8, 0x7f, 0xc7, 0xf8, 0xc7, 0x1c, 0x1f, 0x3d, 0xff, 0xfc, 0x65, 0xff, 0xff, 
    0xff, 0xf8, 0x1f, 0xe1, 0x3f, 0x0b, 0xf0, 0x0e, 0x18, 0x3f, 0x79, 0xff, 0xf8, 0x7f, 0xff, 0xff, 
    0xff, 0xf0, 0x3f, 0xc7, 0x3e, 0x39, 0xc3, 0x0c, 0x38, 0x7e, 0xf3, 0xff, 0xf0, 0xfb, 0xff, 0xff, 
    0xff, 0xf0, 0x7f, 0x87, 0x3c, 0x73, 0x87, 0x1f, 0xf0, 0x7e, 0xe7, 0xff, 0xf1, 0xf7, 0xff, 0xff, 
    0xff, 0xe0, 0x7f, 0x0f, 0x70, 0xe3, 0x0e, 0x1f, 0xe0, 0xfe, 0x0f, 0xff, 0xe1, 0xe7, 0xff, 0xff, 
    0xff, 0xe0, 0xfe, 0x07, 0x61, 0xc6, 0x1e, 0x3f, 0xc1, 0xff, 0x3f, 0xff, 0xc3, 0xcf, 0xff, 0xff, 
    0xff, 0xc1, 0xfc, 0x32, 0x43, 0xfe, 0x3c, 0x7f, 0x83, 0xff, 0xff, 0xff, 0x87, 0x9f, 0xff, 0xff, 
    0xff, 0x81, 0xf8, 0x7c, 0x03, 0xfc, 0x38, 0x7f, 0x83, 0xff, 0xff, 0xff, 0x8f, 0x3f, 0xff, 0xff, 
    0xff, 0x83, 0xf8, 0x7c, 0xc7, 0xf8, 0x78, 0xff, 0x07, 0xff, 0xff, 0xff, 0x0e, 0x7f, 0xff, 0xff, 
    0xff, 0x03, 0xf0, 0xf9, 0x87, 0xf0, 0xf0, 0xef, 0x07, 0xc3, 0xfe, 0x1f, 0x1c, 0xf1, 0x8f, 0xff, 
    0xff, 0x07, 0xf0, 0xfb, 0x0f, 0xe0, 0xe1, 0xde, 0x0f, 0x89, 0xf8, 0xde, 0x19, 0xc2, 0x0f, 0xff, 
    0xfe, 0x07, 0xe1, 0xf7, 0x0f, 0xe1, 0xe3, 0xbe, 0x0e, 0x1d, 0xf1, 0xcc, 0x37, 0x86, 0x1f, 0xff, 
    0xfe, 0x0f, 0xe1, 0xe7, 0x0f, 0xc1, 0xc3, 0x3c, 0x1e, 0x3d, 0xe3, 0xdc, 0x2f, 0x0e, 0x3f, 0xff, 
    0xfe, 0x0f, 0xe1, 0xce, 0x1f, 0x81, 0x86, 0x7c, 0x1c, 0x7d, 0xc3, 0xd8, 0x1e, 0x1c, 0x3f, 0xff, 
    0xfe, 0x0f, 0xe0, 0x9e, 0x0e, 0x61, 0x04, 0xf8, 0x38, 0x79, 0x81, 0xd8, 0x3c, 0x38, 0x7f, 0xff, 
    0xfe, 0x1f, 0xe0, 0x3e, 0x00, 0xc0, 0x01, 0xf8, 0x38, 0x7b, 0x0c, 0xb0, 0xf8, 0x78, 0xff, 0xff, 
    0xfe, 0x1f, 0xe0, 0x7f, 0x03, 0xc1, 0x87, 0xf0, 0x78, 0xfb, 0x1e, 0x00, 0xf8, 0xf0, 0xff, 0xff, 
    0xfe, 0x1f, 0xf1, 0xff, 0x87, 0xe3, 0xcf, 0xf0, 0x73, 0xf6, 0x1f, 0x61, 0xf0, 0xf1, 0xff, 0xff, 
    0xfe, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x77, 0xe6, 0x3e, 0x61, 0xe1, 0xe1, 0xdf, 0xff, 
    0xfe, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x7f, 0xec, 0x3e, 0xe1, 0xe1, 0xc3, 0xbf, 0xff, 
    0xfe, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x7f, 0xdc, 0x7d, 0xc3, 0xc3, 0xc7, 0x7f, 0xff, 
    0xfe, 0x0f, 0xff, 0xff, 0xf0, 0x00, 0xff, 0xf0, 0x7f, 0x98, 0x79, 0xc3, 0x83, 0x86, 0x7f, 0xff, 
    0xfe, 0x07, 0xff, 0xfe, 0x00, 0x00, 0x3f, 0xf0, 0x7f, 0x38, 0x73, 0xc3, 0x03, 0x0c, 0xff, 0xff, 
    0xff, 0x03, 0xff, 0xc0, 0x7c, 0x00, 0x0f, 0xf8, 0x3c, 0x78, 0x07, 0xc2, 0x00, 0x01, 0xff, 0xff, 
    0xff, 0x80, 0xf8, 0x1f, 0xff, 0x00, 0x03, 0xf8, 0x01, 0xf8, 0x0f, 0xc0, 0x81, 0x03, 0xff, 0xff, 
    0xff, 0xe0, 0x01, 0xff, 0xff, 0xc7, 0xf9, 0xfc, 0x03, 0xf8, 0x3f, 0xc1, 0x83, 0x0f, 0xff, 0xff, 
    0xff, 0xfc, 0x7f, 0xff, 0xff, 0xef, 0xfe, 0xff, 0x1f, 0xfc, 0xff, 0xe7, 0xef, 0x9f, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
const tImage cola = { image_data_cola, 128, 64, 8 };

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.

Arduino Code

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

static const unsigned char PROGMEM image_data_Cola[] = {
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf1, 0xf0, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0x80, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x1f, 0xfe, 0x1f, 0xff, 
    0xff, 0xff, 0xfe, 0x0f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x0e, 0x38, 0x07, 0xf8, 0xdf, 0x3f, 
    0xff, 0xff, 0xf8, 0x3f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x39, 0x3e, 0x03, 0xf1, 0xde, 0x7f, 
    0xff, 0xff, 0xf0, 0x7c, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x73, 0x3f, 0x80, 0xe3, 0xbc, 0xff, 
    0xff, 0xff, 0xe0, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xe7, 0x7f, 0xc0, 0xc7, 0xf1, 0xff, 
    0xff, 0xff, 0x83, 0xf9, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc3, 0xcf, 0x7f, 0xf1, 0x8f, 0x03, 0xff, 
    0xff, 0xff, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x9e, 0x7f, 0xff, 0x18, 0x0f, 0xff, 
    0xff, 0xfe, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x0f, 0xbe, 0xff, 0xfe, 0x30, 0x3f, 0xff, 
    0xff, 0xfc, 0x0f, 0xf8, 0x7f, 0xc7, 0xf8, 0xc7, 0x1c, 0x1f, 0x3d, 0xff, 0xfc, 0x65, 0xff, 0xff, 
    0xff, 0xf8, 0x1f, 0xe1, 0x3f, 0x0b, 0xf0, 0x0e, 0x18, 0x3f, 0x79, 0xff, 0xf8, 0x7f, 0xff, 0xff, 
    0xff, 0xf0, 0x3f, 0xc7, 0x3e, 0x39, 0xc3, 0x0c, 0x38, 0x7e, 0xf3, 0xff, 0xf0, 0xfb, 0xff, 0xff, 
    0xff, 0xf0, 0x7f, 0x87, 0x3c, 0x73, 0x87, 0x1f, 0xf0, 0x7e, 0xe7, 0xff, 0xf1, 0xf7, 0xff, 0xff, 
    0xff, 0xe0, 0x7f, 0x0f, 0x70, 0xe3, 0x0e, 0x1f, 0xe0, 0xfe, 0x0f, 0xff, 0xe1, 0xe7, 0xff, 0xff, 
    0xff, 0xe0, 0xfe, 0x07, 0x61, 0xc6, 0x1e, 0x3f, 0xc1, 0xff, 0x3f, 0xff, 0xc3, 0xcf, 0xff, 0xff, 
    0xff, 0xc1, 0xfc, 0x32, 0x43, 0xfe, 0x3c, 0x7f, 0x83, 0xff, 0xff, 0xff, 0x87, 0x9f, 0xff, 0xff, 
    0xff, 0x81, 0xf8, 0x7c, 0x03, 0xfc, 0x38, 0x7f, 0x83, 0xff, 0xff, 0xff, 0x8f, 0x3f, 0xff, 0xff, 
    0xff, 0x83, 0xf8, 0x7c, 0xc7, 0xf8, 0x78, 0xff, 0x07, 0xff, 0xff, 0xff, 0x0e, 0x7f, 0xff, 0xff, 
    0xff, 0x03, 0xf0, 0xf9, 0x87, 0xf0, 0xf0, 0xef, 0x07, 0xc3, 0xfe, 0x1f, 0x1c, 0xf1, 0x8f, 0xff, 
    0xff, 0x07, 0xf0, 0xfb, 0x0f, 0xe0, 0xe1, 0xde, 0x0f, 0x89, 0xf8, 0xde, 0x19, 0xc2, 0x0f, 0xff, 
    0xfe, 0x07, 0xe1, 0xf7, 0x0f, 0xe1, 0xe3, 0xbe, 0x0e, 0x1d, 0xf1, 0xcc, 0x37, 0x86, 0x1f, 0xff, 
    0xfe, 0x0f, 0xe1, 0xe7, 0x0f, 0xc1, 0xc3, 0x3c, 0x1e, 0x3d, 0xe3, 0xdc, 0x2f, 0x0e, 0x3f, 0xff, 
    0xfe, 0x0f, 0xe1, 0xce, 0x1f, 0x81, 0x86, 0x7c, 0x1c, 0x7d, 0xc3, 0xd8, 0x1e, 0x1c, 0x3f, 0xff, 
    0xfe, 0x0f, 0xe0, 0x9e, 0x0e, 0x61, 0x04, 0xf8, 0x38, 0x79, 0x81, 0xd8, 0x3c, 0x38, 0x7f, 0xff, 
    0xfe, 0x1f, 0xe0, 0x3e, 0x00, 0xc0, 0x01, 0xf8, 0x38, 0x7b, 0x0c, 0xb0, 0xf8, 0x78, 0xff, 0xff, 
    0xfe, 0x1f, 0xe0, 0x7f, 0x03, 0xc1, 0x87, 0xf0, 0x78, 0xfb, 0x1e, 0x00, 0xf8, 0xf0, 0xff, 0xff, 
    0xfe, 0x1f, 0xf1, 0xff, 0x87, 0xe3, 0xcf, 0xf0, 0x73, 0xf6, 0x1f, 0x61, 0xf0, 0xf1, 0xff, 0xff, 
    0xfe, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x77, 0xe6, 0x3e, 0x61, 0xe1, 0xe1, 0xdf, 0xff, 
    0xfe, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x7f, 0xec, 0x3e, 0xe1, 0xe1, 0xc3, 0xbf, 0xff, 
    0xfe, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x7f, 0xdc, 0x7d, 0xc3, 0xc3, 0xc7, 0x7f, 0xff, 
    0xfe, 0x0f, 0xff, 0xff, 0xf0, 0x00, 0xff, 0xf0, 0x7f, 0x98, 0x79, 0xc3, 0x83, 0x86, 0x7f, 0xff, 
    0xfe, 0x07, 0xff, 0xfe, 0x00, 0x00, 0x3f, 0xf0, 0x7f, 0x38, 0x73, 0xc3, 0x03, 0x0c, 0xff, 0xff, 
    0xff, 0x03, 0xff, 0xc0, 0x7c, 0x00, 0x0f, 0xf8, 0x3c, 0x78, 0x07, 0xc2, 0x00, 0x01, 0xff, 0xff, 
    0xff, 0x80, 0xf8, 0x1f, 0xff, 0x00, 0x03, 0xf8, 0x01, 0xf8, 0x0f, 0xc0, 0x81, 0x03, 0xff, 0xff, 
    0xff, 0xe0, 0x01, 0xff, 0xff, 0xc7, 0xf9, 0xfc, 0x03, 0xf8, 0x3f, 0xc1, 0x83, 0x0f, 0xff, 0xff, 
    0xff, 0xfc, 0x7f, 0xff, 0xff, 0xef, 0xfe, 0xff, 0x1f, 0xfc, 0xff, 0xe7, 0xef, 0x9f, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
    };
 
void setup() {
  Serial.begin(115200);
 
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }
  delay(2000); // Pause for 2 seconds
 
  // Clear the buffer.
  display.clearDisplay();
  
  // Draw bitmap on the screen
  display.drawBitmap(0, 0, image_data_Cola, 128, 64, 1);
  display.display();
  delay(5000);
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 1);
  display.println("Welcome to CocaCola.");
  display.display();
  
}
 
void loop() {
  
}

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

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

static const unsigned char PROGMEM image_data_battery[] = {
    0x1f, 0xff, 0xc0, 
    0x20, 0x00, 0x20, 
    0x20, 0x0d, 0xa0, 
    0xe0, 0x0d, 0xa0, 
    0x80, 0x0d, 0xa0, 
    0xe0, 0x0d, 0xa0, 
    0x20, 0x0d, 0xa0, 
    0x20, 0x00, 0x20, 
    0x1f, 0xff, 0xc0, 
    0x00, 0x00, 0x00
    };

void setup() {
  Serial.begin(115200);
 
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }
  delay(2000); // Pause for 2 seconds
 
  // Clear the buffer.
  display.clearDisplay();
  
  // Draw bitmap on the screen
 
 display.drawBitmap(108, 0, image_data_battery, 20, 10, 1);
  
 display.setTextSize(1);
 display.setTextColor(WHITE);
 display.setCursor(0, 0);
 display.println("3:50PM");
 display.setTextSize(2);
 display.setTextColor(WHITE);
 display.setCursor(20, 25);
 display.print("Welcome");
 display.setTextSize(1);
 display.setTextColor(WHITE);
 display.setCursor(20, 45);
 display.print("Arduino Is Fun");
 display.display();
}
 
void loop() {
 
}

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.

Is this article helpful?

See results

Comments

    0 of 8192 characters used
    Post Comment

    No comments yet.

    working

    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, hubpages.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: https://maven.io/company/pages/privacy

    Show Details
    Necessary
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
    Features
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Marketing
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Statistics
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)
    ClickscoThis is a data management platform studying reader behavior (Privacy Policy)