ESP8266 NodeMCU interfacing with SSD1306 OLED

This topic shows how to interface the SSD1306 OLED display with ESP8266 NodeMCU development board (ESP-12E). The display used in this project has a resolution of 128×64 Pixel and works in I2C mode, that means the NodeMCU communicates with the display using I2C communication protocol. The I2C protocol uses two lines: SDA (serial data) and SCL (serial clock). the SSD1306 requires 2 pins for the I2C bus and an additional reset pin (if the SSD1306 OLED board has a reset pin).

SSD1306 OLED driver for Arduino IDE:
Adafruit Industries provides a very nice library for the SSD1306 OLED, it can be easily installed using Arduino library manager (Sketch —> Include Library —> Library Manager), or manually by downloading it from the link below and adding it to Arduino libraries folder (C:\Program Files\Arduino\libraries):
Adafruit SSD1306 OLED library

Note that the Adafruit SSD1306 OLED driver supports 3 types: 128×64, 128×32 and 96×16 pixel, we can select between them in the driver header file Adafruit_SSD1306.h. Opening the file with a text editor such as the Arduino IDE gives (scroll down as shown):

Adafruit SSD1306 OLED driver modifiy

I commented the default display type #define SSD1306_128_32 and uncommented #define SSD1306_128_64 because I’m using 128×64 pixel display (0.96″).

We need an other library named Adafruit GFX (graphics library) which can be installed through Arduino library manager or manually by downloading it from the link below:
Adafruit GFX library

ESP-12E NodeMCU SSD1306 OLED display hardware circuit

Hardware Required:
The components listed below are required for this project.

  • ESP8266 NodeMCU module (ESP-12E)
  • SSD1306 OLED display
  • Breadboard
  • Jumper wires

NodeMCU interfacing with SSD1306 OLED circuit:
The following image shows the circuit schematic diagram of the project.

ESP8266 ESP-12E nodeMCU SSD1306 OLED display circuit

and the second image shows fritzing breadboard circuit:

ESP8266 ESP-12E nodeMCU SSD1306 OLED display fritzing circuit

The SDA and SCL lines of the I2C bus come from GPIO4 (D2) and GPIO0 (D3) of the NodeMCU board (respectively), they are connected to SDA and SCL (SCK) pins of the SSD1306 display module.
Reset pin (RES) of the display module is connected to GPIO5 (D1) of the NodeMCU development board.

The SSD1306 display module is supplied with 3.3V which comes from the NodeMCU board.

NodeMCU interfacing with SSD1306 OLED code:
Project code is Adafruit library example code (ssd1306_128x64_i2c) with minor modifications. I added Wire.begin(4, 0); to configure the I2C bus pins. SDA is set to GPIO4 (D2) and SCL to GPIO0 (D3). The reset pin of the display module is connected to pin GPIO5 (D5):
#define OLED_RESET 5

The default clock frequency is 100kHz, for 400kHz clock uncomment line number 65 (L for long):
//Wire.setClock(400000L);

Full code is below:

After I build my protoboard circuit I got a result as shown in the following video where ESP8266 ESP-01 module is used:

ESP8266 Projects with SSD1306 OLED display:
ESP8266 NodeMCU interfacing with DHT11 sensor and SSD1306
Interfacing NodeMCU with DHT22 sensor and SSD1306 OLED
NodeMCU Interfacing with SSD1306 and DS18B20 temperature sensor
Real time clock using NodeMCU, DS3231 and SSD1306 OLED
NodeMCU Internet clock with SSD1306 display | IoT Projects
NodeMCU Internet weather station with SSD1306 OLED | IoT Projects
NodeMCU Internet clock and weather station | IoT Projects
ESP8266 NodeMCU Interface with SSD1306 OLED and BMP280 sensor
NodeMCU weather station with SSD1306 OLED and BME280 sensor
Interfacing NodeMCU with LM35 temperature sensor


Discover more from Simple Circuit

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top