OLED Display with I2C

OLED Display with I2C

Introduction

This experiment demonstrates how to use an OLED display with the I2C protocol to display text or graphics on the screen. I2C simplifies wiring by using just two data lines for communication.

OLED Display with I2C

Components Needed

Circuit Setup

  1. Connect the VCC pin of the OLED to the 5V pin on the Arduino.
  2. Connect the GND pin of the OLED to the GND pin on the Arduino.
  3. Connect the SDA and SCL pins of the OLED to the SDA and SCL pins on the Arduino (A4 and A5 for Arduino Uno).

Ensure the connections are secure and the display is connected properly.

OLED Display Circuit Setup

Code for OLED Display

Upload the following code to your Arduino to display text on the OLED screen:


#include 
#include 
#include 

Adafruit_SSD1306 display(128, 64, &Wire, -1);

void setup() {
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0,0);
  display.print("Hello, OLED!");
  display.display();
}

void loop() {
  // No need for continuous code, text is static
}
            

Explanation

The code initializes the OLED display and writes the text "Hello, OLED!" to the screen. The I2C protocol allows the display to communicate with the Arduino using only two data lines, making it easier to wire compared to parallel communication.

Troubleshooting