ESP-12 ESP8266 with SSD1306 OLED Display
Arduino sketch for the ESP-12 (ESP8266) with an OLED display using the Adafruit_SSD1306 library.
ESP-12 (ESP8266) with OLED Display (SSD1306) - Arduino Code
This guide provides an Arduino sketch to interface an ESP-12 (ESP8266) with a 0.96" SSD1306 OLED display using the Adafruit SSD1306 library. The code initializes the OLED screen, displays text, and draws simple graphics.
** Hardware Requirements **
- ESP-12 (ESP8266) Module
- 0.96" OLED Display (SSD1306, I2C)
- Jumper Wires
- 3.3V Power Source (ESP-12 operates at 3.3V)
** Wiring Diagram (ESP-12 to OLED - I2C Mode)**
| OLED Pin | ESP-12 Pin |
|---|---|
| VCC | 3.3V |
| GND | GND |
| SDA | GPIO4 (D2) |
| SCL | GPIO5 (D1) |
** Install Required Libraries **
Before uploading the code, install the following libraries in the Arduino IDE:
- Adafruit GFX
- Adafruit SSD1306
- Wire (Pre-installed in Arduino IDE) To install:
- Go to Sketch → Include Library → Manage Libraries
- Search and install Adafruit GFX & Adafruit SSD1306
c
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
Serial.begin(115200);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C, false, false)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
delay(2000); // Pause for 2 seconds
// Clear the buffer.
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0);
display.println("ESP12 SSD1306 OLED");
display.setTextSize(2);
display.setCursor(0,24);
display.println("EltroNerd");
display.setTextSize(1);
display.setCursor(0,44);
display.println("[email protected]");
display.display();
}
void loop() {
display.clearDisplay();
// Display Title
display.setCursor(10, 10);
display.setTextSize(2);
display.print("ESP-12 OLED");
// Draw a Rectangle
display.drawRect(20, 30, 80, 20, WHITE);
// Draw a Circle
display.fillCircle(64, 50, 5, WHITE);
display.display();
delay(1000);
}