Random Nerd Tutorials
Shares

Guide for 0.96 inch OLED Display with Arduino

Shares

This post shows how to use the small 0.96 inch OLED display with the Arduino board.

Introducing the 0.96 inch OLED display

The OLED display is the one in the following figure:

dsc09476

It is a very small display, the screen has 25mm x 14mm (0.98in x 0.55in). It is made of 128 by 64 individual OLED pixels and no backlight is required. That OLED display is monochrome (white color), but there are other models with several colors.

This display uses I2C communication. This means that it communicates with the Arduino using just 2 pins.

Pin wiring

Wiring the OLED display to your Arduino is pretty straightforward:

Pin Wiring to Arduino Uno
Vin 5V
GND GND
SCL A5
SDA A4

If you’re using other Arduino board rather than the uno, chek out what are their SCL and SDA pins.

  • Nano: SDA (A4); SCL(A5);
  • MEGA: SDA (20); SCL(21);
  • Leonardo: SDA (20); SCL(21);

Libraries

To control the OLED display you’ll need the “adafruit_GFX.h” library and the “adafruit_SSD1306.h” library.

Installing the adafruit_GFX library

  1. Click here to download the adafruit GFX library. You should have a .zip folder in your Downloads folder
  2. Unzip the .zip folder and you should get Adafruit-GFX-Library-master folder
  3. Rename your folder from Adafruit-GFX-Library-master to Adafruit_GFX_Library (you really need ro replace those “-” by “_”)
  4. Move the Adafruit_GFX_Library folder to your Arduino IDE installation libraries folder
  5. Finally, re-open your Arduino IDE

Installing the adafruit_SSD1306 library

  1. Click here to download the adafruit_SSD1306 library. You should have a .zip folder in your Downloads folder
  2. Unzip the .zip folder and you should get Adafruit-GFX-Library-master folder
  3. Rename your folder from Adafruit_SSD1306-master to Adafruit_SSD1306
  4. Move the Adafruit_SSD1306 folder to your Arduino IDE installation libraries folder
  5. Finally, re-open your Arduino IDE

Tips about writing text using these libraries

Here’s some functions that will help you handle the OLED display library to write text or draw simple graphics.

  • display.clearDisplay() – all pixels are off
  • display.drawPixel(x,y, color) – plot a pixel in the x,y coordinates
  • display.setTextSize(n) – set the font size, supports sizes from 1 to 8
  • display.setCursor(x,y) – set the coordinates to start writing text
  • display.print(“message”) – print the characters at location x,y

Example: display the temperature and humidity in the OLED display

In this example you will display the temperature and humidity in the OLED display. The aim of this project is to get familiar with the OLED display.

The temperature and humidity will be measured using the DHT11 temperature and humidity sensor. If you’re not familiar with the DHT11 sensor I recommend that you check out the following post:

Parts required

For this example you’ll need the following components:

Schematics

Assemble all the parts as in the schematics below.

display-dht11-oled_bb

Code

Make sure you’ve installed the necessary libraries to control the OLED display. You also need to install the DHT library.

Installing the DHT sensor library

  1. Click here to download the DHT-sensor-library. You should have a .zip folder in your Downloads folder
  2. Unzip the .zip folder and you should get DHT-sensor-library-master folder
  3. Rename your folder from DHT-sensor-library-master toDHT_sensor_library (you really need ro replace those “-” by “_”)
  4. Move the DHT_sensor_library folder to your Arduino IDE installation libraries folder
  5. Finally, re-open your Arduino IDE

Then, you can upload the following code.

Demonstration

Here’s the OLED display in action after uploading the code.

demonstration

Wrapping up

I hope you’ve found this guide useful. If you like this post probably you might like my next ones, so make sure you subscribe the RNT blog.

Are you planning to use the OLED display in your next projects? Let me know in the comments section below.

Thanks for reading,

Rui and Sara

Recommended Resources

Home Automation using ESP8266 »
Build IoT projects and home automation gadgets with the ESP8266 Wi-Fi module.

Build a Home Automation System »
Learn how to build a automation system using open-source hardware and software from scratch.

Arduino Step-by-Step Projects »
Build 25 cool Arduino projects with our couse even with no prior experience!

Leave a Comment:

Add Your Reply

⏰ Early Black Friday 2017 Special ⏰
Download all our courses up to 35% off