Arduino - SSD1309 OLED Display
An OLED (Organic Light-Emitting Diode) display offers self-emitting pixels that deliver deep blacks, high contrast, and wide viewing angles — making it a great upgrade over traditional LCDs. The SSD1309 is the driver IC commonly found on 2.42-inch (sometimes labeled 2.4-inch) 128×64 I2C OLED modules.

In this step-by-step guide you will learn how to connect and program the SSD1309 OLED 128×64 with an Arduino board using the DIYables_OLED_SSD1309 library. Specifically, we will cover:
- Wiring the 2.42-inch SSD1309 OLED to Arduino via I2C
- Printing text and numbers on the screen
- Centering text both vertically and horizontally
- Drawing geometric shapes (lines, rectangles, circles, triangles, rounded rectangles)
- Rendering monochrome bitmap images
- Hardware scrolling in four directions
- Adjusting contrast and dimming the display
- Using custom external fonts from the Adafruit GFX font collection
Hardware Required
Or you can buy the following kits:
| 1 | × | DIYables STEM V3 Starter Kit (Arduino included) | |
| 1 | × | DIYables Sensor Kit (30 sensors/displays) | |
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some links direct to products from our own brand, DIYables .
About the SSD1309 2.42-Inch OLED Display
The SSD1309 is a single-chip CMOS OLED driver IC designed for 128×64 dot-matrix panels. It is register-compatible with the widely-used SSD1306, so many existing code examples carry over with minimal changes. The key hardware differences are:
- No built-in charge pump — the SSD1309 requires an external VCC rail, though virtually all breakout boards (including 2.42-inch and 2.4-inch modules) ship with an onboard boost converter, so this is transparent to you.
- Higher voltage tolerance — the SSD1309 accepts up to 16 V VCC, whereas the SSD1306 is limited to roughly 4.2 V.
The 2.42 inch (2.4 inch) OLED module commonly uses the SSD1309 driver and features a 128×64 pixel resolution with I2C interface. Panel color (white, blue, yellow, green, or dual-zone) is determined by the physical OLED material and is not software-controllable.
This tutorial communicates with the display over the I2C bus, which only requires two signal wires (SDA and SCL) and can share the bus with other I2C peripherals.
SSD1309 OLED Pinout (I2C Module)
The typical 2.42-inch SSD1309 I2C OLED module exposes four pins:
- GND — Connect to the Arduino ground rail.
- VCC — Power input. Wire to the Arduino 5 V (or 3.3 V, depending on the module's onboard regulator).
- SCL — I2C clock line.
- SDA — I2C data line.

※ NOTE THAT:
- Pin ordering varies between manufacturers. Always verify the labels silk-screened on your module before wiring.
- This tutorial has been verified with the 2.42 inch SSD1309 OLED display from DIYables. Other SSD1309-based 2.4/2.42-inch modules should work identically.
Wiring Diagram — Arduino & SSD1309 OLED 128×64
- Schematic wiring between Arduino and the 2.42 inch SSD1309 OLED 128×64

This image is created using Fritzing. Click to enlarge image
- Photograph of the actual wiring between Arduino and SSD1309 OLED 128×64

This image is created using Fritzing. Click to enlarge image
When using a different Arduino variant, the I2C pins change. The table below lists the correct connections:
| OLED Module | Arduino Uno, Nano | Arduino Mega |
|---|---|---|
| Vin | 5V | 5V |
| GND | GND | GND |
| SDA | A4 | 20 |
| SCL | A5 | 21 |
Getting Started — SSD1309 OLED with Arduino
Step 1: Install the DIYables_OLED_SSD1309 Library
- Open the Arduino IDE and click the Libraries icon in the left sidebar.
- Type "DIYables_OLED_SSD1309" in the search box and locate the library published by DIYables.
- Click the Install button.

- The IDE will prompt you to install the required dependency (Adafruit GFX Library). Click Install All to proceed.

Step 2: Basic Programming Pattern
Every sketch that drives the SSD1309 follows the same pattern: include headers, create a display object, initialise it in setup(), draw into the off-screen buffer, then push the buffer to the screen with display().
- Include the required headers:
- Set the screen dimensions (128×64 for the 2.42-inch module):
- Create the display object (pass -1 when no reset pin is connected):
- Initialise the display inside setup():
- After this, you are free to call any drawing function (clearDisplay(), drawPixel(), print(), etc.) followed by oled.display() to update the screen.
※ NOTE THAT:
All example code in this tutorial targets the SSD1309 OLED 128×64 (2.42 inch) and uses the DIYables_OLED_SSD1309 library.
Arduino Code — Hello World on SSD1309 OLED
The simplest starting point: print a few lines of text at different sizes.
Arduino Code — Display Text on SSD1309 OLED
The following example demonstrates more text features — multiple sizes, number formatting, and the F() macro for saving RAM.
Useful Display Functions Reference
Below is a quick-reference list of the most frequently used functions when working with the SSD1309 OLED through the DIYables library:
- oled.clearDisplay() — wipe the frame buffer (all pixels off).
- oled.display() — transfer the buffer to the OLED so changes become visible.
- oled.drawPixel(x, y, color) — set or clear an individual pixel.
- oled.setTextSize(n) — scale the font by factor *n* (1 = 6×8, 2 = 12×16, …, up to 8).
- oled.setCursor(x, y) — move the text cursor to pixel coordinates *(x, y)*.
- oled.setTextColor(SSD1309_PIXEL_ON) — text foreground only (background is transparent).
- oled.setTextColor(SSD1309_PIXEL_OFF, SSD1309_PIXEL_ON) — text with an explicit background colour.
- oled.println("message") — print a string and advance to the next line.
- oled.println(number) — print an integer in decimal.
- oled.println(number, HEX) — print an integer in hexadecimal.
- oled.startscrollright(start, stop) — hardware-scroll right between page *start* and page *stop*.
- oled.startscrollleft(start, stop) — hardware-scroll left.
- oled.startscrolldiagright(start, stop) — hardware-scroll diagonally right.
- oled.startscrolldiagleft(start, stop) — hardware-scroll diagonally left.
- oled.stopscroll() — halt any active hardware scroll.
- oled.setContrast(value) — adjust display brightness (0–255).
- oled.dim(true/false) — quickly dim the display to minimum or restore the previous contrast.
- oled.invertDisplay(true/false) — hardware-level colour inversion (on pixels ↔ off pixels).
How to Vertically and Horizontally Center Text on the SSD1309 OLED
Arduino Code — Draw Shapes on SSD1309 OLED
Because the DIYables_OLED_SSD1309 library extends Adafruit_GFX, you get a complete set of shape-drawing primitives: pixels, lines, rectangles, filled rectangles, circles, filled circles, triangles, filled triangles, and rounded rectangles. The sketch below cycles through all of them with animated demos.
Arduino Code — Hardware Scrolling on SSD1309 OLED
The SSD1309 has a built-in scrolling engine that shifts the display contents without any CPU load. The DIYables library exposes four scroll directions: right, left, diagonal-right, and diagonal-left. Each takes a start page and stop page parameter (pages are 8-pixel-high horizontal strips numbered 0–7 on a 64-pixel-tall display).
※ NOTE THAT:
Always call display() to push your content to the OLED before starting a scroll. Avoid drawing new content while scrolling is active — call stopscroll() first.
Arduino Code — Display Bitmap Image on SSD1309 OLED
To render a bitmap on the SSD1309 OLED you first need to convert your image into a C byte array. Use the free image2cpp online tool to do this:
- Upload your image (PNG, JPG, BMP, etc.).
- Set the canvas size to 128×64 (or smaller).
- Choose Arduino code as the output format.
- Copy the generated array into your sketch.

The example below alternates between a 16×16 heart icon and a full-width DIYables logo:
※ NOTE THAT:
- The bitmap dimensions must not exceed the screen resolution (128×64 for the 2.42 inch module).
Arduino Code — Contrast and Dim on SSD1309 OLED
The SSD1309 supports 256 levels of contrast (0–255). The DIYables library provides setContrast() for fine-grained control and dim() for a quick toggle between minimum brightness and the previously-configured level.
Arduino Code — Custom External Fonts on SSD1309 OLED
The Adafruit GFX library ships with dozens of scalable FreeFont typefaces (Serif, Sans, Mono — each in Regular, Bold, Italic, and four sizes). You can activate any of them on the SSD1309 display by including the corresponding header and calling setFont().
※ NOTE THAT:
- When an external font is active, the cursor Y coordinate refers to the text baseline, not the top-left corner. This is different from the built-in 5×7 font.
- External fonts are stored in flash (PROGMEM). On memory-limited AVR boards (Arduino Uno = 32 KB flash), use them sparingly.
SSD1309 OLED Troubleshooting
If nothing appears on the 2.42 inch SSD1309 OLED after uploading your sketch, work through these checks:
- Verify wiring — confirm SDA, SCL, VCC and GND are connected to the correct Arduino pins.
- Confirm the driver chip — this library is designed for the SSD1309. If your module uses a different controller (e.g. SH1106), it will not respond correctly.
- Check the I2C address — most SSD1309 modules default to 0x3C, but some use 0x3D. Run the I2C scanner sketch below to detect the actual address:
Expected Serial Monitor output when the SSD1309 is detected:
- Make sure display() is called — the SSD1309 uses a frame buffer. Drawing functions only modify the buffer in RAM; nothing appears on screen until you call oled.display().
- Check power supply — the 2.42 inch module draws more current than smaller OLEDs. Ensure your power source can provide sufficient current (typically 20–40 mA at full brightness).