ESP8266 - SSD1309 OLED Display
This tutorial instructs you how to use ESP8266 with a 2.42 inch (2.4") SSD1309 I2C OLED display (128×64 resolution). In detail, we will learn:
- How to connect a 2.42 inch SSD1309 OLED display to ESP8266.
- How to program ESP8266 to display text on the SSD1309 OLED.
- How to program ESP8266 to draw shapes on the SSD1309 OLED.
- How to enable hardware scrolling on the SSD1309 OLED with ESP8266.
- How to program ESP8266 to display bitmap images on the SSD1309 OLED.
- How to adjust brightness/contrast of the SSD1309 OLED.
- How to use external fonts with the SSD1309 OLED display.

Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (30 sensors/displays) | |
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of SSD1309 OLED Display
The SSD1309 is a monochrome OLED display driver chip. The 2.42 inch version provides a 128×64 pixel resolution. It communicates via I2C protocol, requiring only two pins (SDA and SCL) plus power connections. This makes it ideal for ESP8266 projects with limited pin availability.
Key features of the SSD1309 OLED:
- Display Size: 2.42 inches (diagonal)
- Resolution: 128×64 pixels
- Communication: I2C (2-wire interface)
- Default I2C Address: 0x3C
- Operating Voltage: 3.3V or 5V compatible (ESP8266 uses 3.3V)
- Built-in hardware scrolling support
- Adjustable contrast/brightness
- Low power consumption
SSD1309 OLED Display Pinout
The 2.42 inch SSD1309 I2C OLED module typically has 4 pins:
- GND: Ground pin - connect to ESP8266 GND
- VCC: Power supply pin - connect to ESP8266 3.3V
- SDA: I2C data line - connect to ESP8266 D2 (GPIO4)
- SCL: I2C clock line - connect to ESP8266 D1 (GPIO5)

※ NOTE THAT:
- The pins of an OLED module can differ across manufacturers and module types. It is essential to always refer to the labels printed on the OLED module. Pay attention!
- This tutorial uses the OLED display that has the SSD1309 I2C driver. We have tested it with the OLED display from DIYables and it works perfectly.
Wiring Diagram
Connect the 2.42 inch SSD1309 OLED display to ESP8266 following this wiring:

This image is created using Fritzing. Click to enlarge image
See more in ESP8266's pinout and how to supply power to the ESP8266 and other components.
| SSD1309 OLED | ESP8266 |
|---|---|
| VCC | 3.3V |
| GND | GND |
| SDA | D2 (GPIO4) |
| SCL | D1 (GPIO5) |
How To Use SSD1309 OLED with ESP8266
Install DIYables_OLED_SSD1309 Library
- Click on the Libraries icon on the left navigation bar of Arduino IDE.
- Type DIYables_OLED_SSD1309 in the search box and look for the library by DIYables.
- Click the Install button to add the library.

The DIYables_OLED_SSD1309 library depends on the Adafruit_GFX library. If Adafruit_GFX is not already installed, the Arduino IDE will automatically prompt you to install it when you install DIYables_OLED_SSD1309.
ESP8266 Code - Display "Hello World" on SSD1309 OLED
The below code shows how to display text on the 2.42 inch SSD1309 OLED display:
Explanation
- Include necessary libraries and define constants
- Create display object with I2C address 0x3C
- Initialize display in setup()
- Set text size, color, and cursor position
- Print text to display buffer using print() and println()
- Call display.display() to push buffer content to the screen
※ NOTE THAT:
The F() macro stores strings in flash memory instead of RAM. This saves valuable RAM on ESP8266.
ESP8266 Code - Display Text with Various Formats
This code demonstrates text display with different sizes and number formatting:
ESP8266 Code - Draw Shapes on SSD1309 OLED
The below code shows how to draw pixels, lines, rectangles, circles, and triangles:
Available drawing functions:
- drawPixel(x, y, color) - Draw a single pixel
- drawLine(x0, y0, x1, y1, color) - Draw a line
- drawRect(x, y, w, h, color) - Draw rectangle outline
- fillRect(x, y, w, h, color) - Draw filled rectangle
- drawRoundRect(x, y, w, h, radius, color) - Draw rounded rectangle
- drawCircle(x, y, radius, color) - Draw circle outline
- fillCircle(x, y, radius, color) - Draw filled circle
- drawTriangle(x0, y0, x1, y1, x2, y2, color) - Draw triangle outline
- fillTriangle(x0, y0, x1, y1, x2, y2, color) - Draw filled triangle
ESP8266 Code - Hardware Scrolling on SSD1309 OLED
The SSD1309 supports hardware-based scrolling. This code demonstrates all four scroll directions:
Scrolling functions:
- startscrollright(start, stop) - Scroll right
- startscrollleft(start, stop) - Scroll left
- startscrolldiagright(start, stop) - Diagonal scroll right
- startscrolldiagleft(start, stop) - Diagonal scroll left
- stopscroll() - Stop scrolling
The start and stop parameters define the page range (0x00 to 0x07 for full screen).
ESP8266 Code - Display Bitmap Image on SSD1309 OLED
This code shows how to display bitmap images stored in program memory:
To display images:
- Convert your image to a monochrome bitmap array (use online tools or image2cpp)
- Store the array in PROGMEM to save RAM
- Use drawBitmap(x, y, bitmap, width, height, color) to display
ESP8266 Code - Adjust Brightness/Contrast
Control the brightness and contrast of the SSD1309 OLED display:
Brightness control functions:
- setContrast(value) - Set contrast level (0-255, higher = brighter)
- dim(true/false) - Quick toggle between dim and normal brightness
- invertDisplay(true/false) - Invert all pixels (black↔white)
ESP8266 Code - Use External Fonts
The Adafruit_GFX library includes FreeFont typefaces. This code demonstrates three different fonts:
※ NOTE THAT:
FreeFont files are large. ESP8266 has limited flash memory (typically 4MB). Use only the fonts you need, or consider using smaller font sizes if memory is constrained.
Font usage:
- Include font header: #include <Fonts/FreeSans9pt7b.h>
- Set font: display.setFont(&FreeSans9pt7b)
- Reset to default: display.setFont(NULL)
- When using external fonts, Y coordinate represents the baseline, not the top
Troubleshooting
If the OLED display is not working, try these steps:
Check I2C Address
The default I2C address is 0x3C, but some modules use 0x3D. Run this I2C scanner to find the correct address:
If your display uses 0x3D, change SCREEN_ADDRESS to 0x3D in the code.
Check Wiring
Verify connections:
- VCC → 3.3V (not 5V for ESP8266)
- GND → GND
- SDA → D2 (GPIO4)
- SCL → D1 (GPIO5)
Check Power Supply
Make sure the ESP8266 is receiving adequate power through the USB cable or external power supply.