INTERFACING OLED DISPLAY USING ARDUINO

Karkhana Makerspace
3 min readDec 6, 2018

--

Through this medium, we would see how to interface an OLED display using Arduino UNO and displaying some simple texts over it.So, lets get started.

COMPONENTS REQUIRED

(a)Arduino UNO

(b)0.96" I2C OLED display module

(c)Jumper wires

WHY USE OLED INSTEAD OF LCD DISPLAY?

OLED displays are better option in comparison to 16X2 LCD displays because they reduce the amount of wires that are needed to supply power to the LCD.

In LCD’s we need to connect more than 4 wires to get the display seen. But, in OLED’s the case is not so. OLED needs just 4 wires at minimum to set itself to work. It is so because it just needs the SDA and SCL pins to display any text or image what we wish to. So, OLED is a much more compact way of displaying as compared to LCD’s.

CONNECTIONS

Setting up connections of the OLED with the Arduino is quite simple.Plug in the VCC of the OLED to 3.3V of the Arduino. Next, connect ground of the OLED to the ground of Arduino, and the SDA and SCL to that of SDA and SCL of the Arduino respectively.

Connection of OLED with Arduino UNO

GETTING ON SOFTWARE

After the connections are made, we need to download libraries for the display to work. Without the libraries, it would not be possible to work on the OLED.

Open libraries are available on the internet, and for I2C 128X64 OLED, “ADAFRUIT” and “GTX” libraries would provide the sufficient job for us.

So, we will download the libraries.the link to download the 2 libraries are provided below-

(1) Download Adafruit_SSD1306 Library

(2) Download Adafruit GFX Library

Download the 2 libraries and add them to your Arduino IDE.

Now, Go to File — — Examples — Adafruit_SSD1306 — ssd1306_128X64_i2c

and press ok. An example code would come up. Run the code to get sure about your connections and check if the OLED diplays patterns well or not.

HEADER FILES THAT WE WOULD BE USING

<SPI.h>- Serial Peripheral Interface (SPI) is a synchronous serial data protocol used by microcontrollers for communicating with one or more peripheral devices quickly over short distances. It can also be used for communication between two microcontrollers.

<Wire.h>- This library allows you to communicate with I2C / TWI devices. On the Arduino boards with the R3 layout (1.0 pinout), the SDA (data line) and SCL (clock line) are on the pin headers close to the AREF pin. The Arduino Due has two I2C / TWI interfaces SDA1 and SCL1 are near to the AREF pin and the additional one is on pins 20 and 21.

<Adafruit_GFX.h> and <Adafruit_SSD1306.h>- These 2 libraries are a must, as they ease the job of us of writing long codes, on inclusion of these 2 header files we dont need to call to define functions distinctively.

Now, get yourself to coding.

Type the following code on the IDE :

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

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

void setup() {
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.display();
delay(2000);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println(“WELCOME TO KARKHANA”); //print your name here
display.setCursor(0, 172 ); //this sets the cursor to 0 and 172
display.display();
delay(100000);

}

void loop() {

//this space has been left blank because we do not need to run a code repeatedly, we are just displaying a name so it can be written on setup only.

}

Coding this will display the name what you ask the compiler to.

For example- I wanted to display “WELCOME TO KARKHANA” , so I printed it and the display I got was-

WELCOME TO KARKHANA

So, by this simple code you could easily quote any text on the OLED display without coding it in Hex .

Thank you for reading.

Author: Aman Rishav

Karkhana Makerspace
Visit now : karkhana.club

--

--

Karkhana Makerspace

We are a bunch of tech enthusiast who loves to make things and figure out creative hacks from other stuffs.