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.
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.
| ESP8266 | OLED SPI |
|---|---|
| 3V3 | VCC |
| GND | GND |
| D2 (GPIO4) | RST |
| D8 (GPIO15) | CS |
| D1 (GPIO5) | DC |
| D5 (GPIO14) | SCK |
| D7 (GPIO13) | SDA |
Important: The 2.42-inch OLED uses 3.3V power supply only. Never connect it to 5V.
Installing the Library
- Download Adafruit_SSD1306 from MediaFire
- Extract the RAR file using WinRAR or WinZip
- 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
- Open Arduino IDE
- Paste the code above into a new sketch
- Select Board: NodeMCU 1.0 (ESP-12E Module)
- Select the correct Port
- Click Upload button
- Wait for Done uploading message
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
จ้างทำโปรเจคเลย