กลับหน้าหลัก
views
Wiring and Using OLED 128x64 I2C Display with Arduino
Last updated on

Wiring and Using OLED 128x64 I2C Display with Arduino


Wiring and Using OLED 128x64 I2C Display with Arduino

This guide walks you through connecting a 1.3-inch OLED display with 128x64 resolution to an Arduino UNO over I2C. You’ll wire the circuit, install the required library, and upload code to display text.

What You Need

  • Arduino UNO R3
  • OLED 128x64 I2C display 1.3 inch
  • 4 jumper wires (male-to-female)
  • Breadboard (optional)

Wiring Diagram

Wiring diagram showing Arduino UNO connected to OLED 128x64 via 4 wires: 5V to VCC, GND to GND, A4 to SDA, A5 to SCL
Arduino UNOOLED Display
5VVCC
GNDGND
A4SDA
A5SCL

Install the Library

  1. Open Arduino IDE
  2. Go to Sketch > Include Library > Manage Libraries
  3. Search for Adafruit SSD1306
  4. Click Install

Adafruit GFX Library will install automatically as a required dependency.

Working Example Code

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

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

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

void setup() {
  Serial.begin(9600);

  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;);
  }

  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 20);
  display.println(F("Hello"));
  display.setCursor(0, 40);
  display.println(F("Arduino"));
  display.display();
}

void loop() {
  // nothing here
}
OLED screen displaying &quot;Hello&quot; on first line and &quot;Arduino&quot; on second line, white text on black background

Adjusting Text Size and Position

display.setTextSize(1);  // text size 1-4
display.setCursor(0, 10); // x, y position on screen
display.print(F("Your text"));

Text height by size level:

setTextSizeHeight (pixels)
18
216
324

Finding Your OLED I2C Address

If the display shows nothing, run the I2C Scanner sketch to find the correct address.

#include <Wire.h>

void setup() {
  Serial.begin(9600);
  Wire.begin();
}

void loop() {
  byte error, address;
  int devices = 0;

  Serial.println("Scanning I2C...");
  for (address = 1; address < 127; address++) {
    Wire.beginTransmission(address);
    error = Wire.endTransmission();
    if (error == 0) {
      Serial.print("I2C device found at 0x");
      if (address < 16) Serial.print("0");
      Serial.println(address, HEX);
      devices++;
    }
  }
  if (devices == 0) Serial.println("No I2C devices found");
  delay(5000);
}

Open Serial Monitor at 9600 baud. If you see 0x3C or 0x3D, update the address in your main code at display.begin(SSD1306_SWITCHCAPVCC, 0x3C).

Serial Monitor showing I2C address scan results, displaying found device at 0x3C

If OLED V2.0 Does Not Work

Some OLED V2.0 modules use SH1106 driver instead of SSD1306. Switch to U8g8lib instead.

#include <U8g2lib.h>

U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

void setup() {
  u8g2.begin();
  u8g2.clear();
  u8g2.setFont(u8g2_font_ncenB14_tr);
  u8g2.drawStr(0, 20, "Hello");
  u8g2.drawStr(0, 40, "Arduino");
  u8g2.sendBuffer();
}

Quick Checklist

  1. Wire 4 connections: 5V, GND, A4 (SDA), A5 (SCL)
  2. Install Adafruit SSD1306 and Adafruit GFX Library
  3. Upload the working example code
  4. If the screen stays blank, run I2C Scanner to find the address
  5. If using SH1106 driver, switch library to U8g8lib

อยากทำโปรเจคแบบนี้?

รับทำโปรเจค Arduino / IoT จบงานไว ส่งงานครบ พร้อมสอน

If you need Arduino project service or urgent IoT development, see full service details on the home page

จ้างทำโปรเจคเลย

ประเมินราคาอัตโนมัติ + Reference Code

ขอให้ AI ประเมินราคาโปรเจคนี้

กรอกข้อมูลให้ครบ ระบบจะสร้างรหัสอ้างอิงและประเมินราคา/ระยะเวลาคร่าว ๆ จากรายละเอียดงาน แล้วให้กด Add LINE พร้อมพิมพ์รหัสนี้เพื่อคุยต่อ

คำถามให้ AI ประเมินแม่นขึ้น

หลังส่งฟอร์ม ระบบจะโชว์ Reference Code ให้ copy แล้วกด Add LINE เพื่อคุยต่อ ข้อมูลส่วนตัวจะไม่ถูกส่งเข้า GA4

ความคิดเห็น

รีวิวจากคนใช้งานจริง

รีวิวจากลูกค้าและคนที่เคยใช้งาน

ถ้าเคยสั่งงาน เคยอ่านหน้านี้แล้วได้ประโยชน์ หรือมีข้อเสนอแนะ ฝากรีวิวไว้ได้เลย

กำลังโหลดรีวิว...