Introduction
OLED (Organic Light Emitting Diode) displays are popular in the world of electronics due to their bright and clear display, low power consumption, and wide viewing angles. The SSD1306 is a popular OLED display driver that is often used in small OLED screens. In this article, we will cover how to interface a 0.96-inch SSD1306 OLED display with an Arduino using the I2C communication protocol. We will walk through the necessary components, features of the SSD1306, the required libraries, and provide example code to get you started.
Working Principle
Organic Light Emitting Diodes (OLEDs) are currently under intensive investigation for use in the next generation of display technologies. The benefits of this technology include wide viewing angle, high emission efficiencies that result in high brightness with low power consumption and low operating voltage. As OLED devices are very lightweight they are used in cellular phones, notebooks, digital video cameras, digital versatile disc (DVD) players, car stereos, televisions and many other consumer tools that require colour displays.
The OLED is a display technology based on the use of organic polymers as the semiconductor material in Light-Emitting Diodes (LEDs). The organic materials used in OLED devices may include “small” molecules or “macro” polymers. For OLED displays constructed of “small” molecules vapour sublimation in a vacuum chamber is the most convenient deposition technique. In the case of macro polymers solvent coating techniques are often used.
Features of the OLED SSD1306
- Resolution: 128×64 pixels
- Color: Monochrome (usually white, blue, or yellow)
- Communication Interface: I2C
- Operating Voltage: 3.3V – 5V
- Viewing Angle: >160 degrees
- Low Power Consumption: Ideal for battery-powered devices
- Compact Size: 0.96 inches, suitable for small projects
Things we need
- Arduino Board (e.g., Arduino Uno, Nano, Mega)
- 0.96 inch SSD1306 I2C OLED Display
- Jumper Wires
- Breadboard (optional)
Circuit Diagram
Connect the circuit as shown below.
To interface the SSD1306 OLED display with Arduino, we need to install the following libraries:
- Adafruit SSD1306
- Adafruit GFX
Steps to Add Libraries:
- Open Arduino IDE.
- Go to Sketch > Include Library > Manage Libraries.
- In the Library Manager, search for “Adafruit SSD1306”.
- Click on the library and then click Install.
- Repeat the process for “Adafruit GFX”.
Code
- Adafruit GFX Library: This library provides a common set of graphics functions for various displays.
- Adafruit SSD1306 Library: Specifically for controlling SSD1306-based OLED displays.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
// Declaration for SSD1306 display connected using I2C
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
// Initialize the display
if(!display.begin(SSD1306_I2C_ADDRESS, OLED_RESET)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
// Clear the buffer
display.clearDisplay();
// Display a message
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0);
display.println(F("Hello, World!"));
// Display a graphic
display.drawLine(0, 10, 127, 10, SSD1306_WHITE);
// Display the buffer content on the screen
display.display();
}
void loop() {
// Put your main code here, to run repeatedly
}
Instructions on Editing the Code:
- Adjust pin definitions (‘OLED’,) if using different pins.
- Modify the display rotation using
display.setRotation()
if your display orientation differs. - Customize the text, shapes, and colors to suit your project requirements.
Applications
OLED displays like the SSD1306 can be used in a variety of applications, including:
- Wearable devices
- Smart home gadgets
- Portable electronics
- Health monitoring devices
- DIY projects and prototypes
- IoT devices
Conclusion
Interfacing an SSD1306 0.96-inch OLED display with an Arduino is a straightforward process thanks to the available libraries. This display is a great choice for projects that require a small, energy-efficient display with high contrast and wide viewing angles. By following the steps and using the provided code, you can quickly integrate this display into your projects.
Suggested Readable Topics
- Interfacing Different Types of Displays with Arduino
- Introduction to I2C and SPI Communication Protocols
- Creating Graphics and Animations on OLED Displays
- Low-Power Display Options for Battery-Powered Projects
- Using Sensors with Arduino and Displaying Data on OLEDs
- Building an Arduino-Based Weather Station with OLED Display