กลับหน้าหลัก
views
Connecting OLED 128x64 Display to ESP8266 via SPI
Last updated on

Connecting OLED 128x64 Display to ESP8266 via SPI


Connecting OLED 128x64 Display to ESP8266 via SPI

This tutorial walks through wiring a 2.42-inch OLED display to a NodeMCU ESP8266 board using the SPI interface with the Adafruit_SSD1306 library. Useful for displaying data or simple graphics with ESP8266.

Wiring diagram showing ESP8266 NodeMCU connected to OLED 128x64 display via SPI with labeled pins

Required Components

  • NodeMCU ESP8266 V2 (CP2102)
  • OLED Display 128x64, 2.42 inch (blue/green/yellow)
  • MB-102 Breadboard (830 points)
  • Male-to-male and Male-to-female Jumper wires
  • Micro USB cable

Wiring Diagram

Connect the wires according to the table below. Pin assignments match the GPIO numbers used in the code.

ESP8266OLED SPI
3V3VCC
GNDGND
D2 (GPIO4)RST
D8 (GPIO15)CS
D1 (GPIO5)DC
D5 (GPIO14)SCK
D7 (GPIO13)SDA
Pin mapping table between ESP8266 and OLED display with recommended wire colors

Important: The 2.42-inch OLED uses 3.3V power supply only. Never connect it to 5V.

Installing the Library

  1. Download Adafruit_SSD1306 from MediaFire
  2. Extract the RAR file using WinRAR or WinZip
  3. Move the folder Adafruit_SSD1306_master to
    Documents/Arduino/libraries/

Example Code

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

// Define pins connected to OLED display
#define OLED_MOSI  13  // D7
#define OLED_CLK   14  // D5
#define OLED_DC    5   // D1
#define OLED_CS    15  // D8
#define OLED_RESET 4   // D2

Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

void setup() {
  Serial.begin(115200);
  
  // Initialize OLED display
  if(!display.begin(SSD1306_SWITCHCAPVCC)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Stop here if display fails
  }

  // Clear screen and display text
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(10, 20);
  display.println(F("ESP8266"));
  display.setCursor(10, 45);
  display.setTextSize(1);
  display.println(F("OLED 2.42 inch"));
  display.display();
}

void loop() {
  // Add code here to update display in loop
}

Upload Steps

  1. Open Arduino IDE
  2. Paste the code above into a new sketch
  3. Select Board: NodeMCU 1.0 (ESP-12E Module)
  4. Select the correct Port
  5. Click Upload button
  6. Wait for Done uploading message
Mockup of Arduino IDE showing successful upload and OLED displaying text

Reference Video

ESP8266 OLED 2.42 inch Tutorial

Summary

Wiring a 128x64 OLED to ESP8266 via SPI requires 7 connection wires. Pay attention to the 3.3V power requirement. After installing the library and uploading the code, the display will immediately show the programmed text.

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

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

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

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

Project estimate

Want something like this? Open the estimate page.

The long form is now on a separate estimate page, so this article stays clean.

ความคิดเห็น

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

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

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

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