Arduino Mega - SSD1309 OLED Display
This guide shows you how to use an Arduino Mega with a 2.42 inch (2.4") SSD1309 I2C OLED display (128×64 resolution). Here we will learn in detail:
- How to connect a 2.42 inch SSD1309 OLED display to Arduino Mega.
- How to program the Arduino Mega to show text on the SSD1309 OLED.
- How to draw shapes on the SSD1309 OLED with Arduino Mega.
- How to enable hardware scrolling on the SSD1309 OLED.
- How to display bitmap images on the SSD1309 OLED with Arduino Mega.
- How to adjust brightness/contrast of the SSD1309 OLED.
- How to use external fonts with the SSD1309 OLED display.

Hardware Preparation
| 1 | × | Arduino Mega | |
| 1 | × | USB 2.0 cable type A/B (for USB-A PC) | |
| 1 | × | USB 2.0 cable type C/B (for USB-C PC) | |
| 1 | × | SSD1309 I2C OLED Display 2.42 inch 128x64 | |
| 1 | × | Jumper Wires |
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 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
- 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 Arduino Mega GND
- VCC: Power supply pin - connect to Arduino Mega 5V
- SDA: I2C data line - connect to Arduino Mega pin 20 (SDA)
- SCL: I2C clock line - connect to Arduino Mega pin 21 (SCL)

※ NOTE THAT:
Pin layout on an OLED module can differ depending on the manufacturer and model. Always check and follow the labels printed on your specific OLED module. Pay attention!
This guide is for an OLED display that uses the SSD1309 I2C driver. We tested it with an SSD1309 OLED display from DIYables. It works well, with no problems.
Wiring Diagram
Connect the 2.42 inch SSD1309 OLED display to Arduino Mega following this wiring:

This image is created using Fritzing. Click to enlarge image
| SSD1309 OLED | Arduino Mega |
|---|---|
| VCC | 5V |
| GND | GND |
| SDA | 20 (SDA) |
| SCL | 21 (SCL) |
How To Use SSD1309 OLED with Arduino Mega
Install DIYables_OLED_SSD1309 Library
- Go to the Libraries icon on the left side of the 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.
Arduino Mega 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 Arduino Mega.
Arduino Mega Code - Display Text with Various Formats
This code demonstrates text display with different sizes and number formatting:
Arduino Mega 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
Arduino Mega 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).
Arduino Mega 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
Arduino Mega 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)
Arduino Mega Code - Use External Fonts
The Adafruit_GFX library includes FreeFont typefaces. This code demonstrates three different fonts:
※ NOTE THAT:
FreeFont files are large. Arduino Mega has 256KB flash memory, which is sufficient for multiple fonts. However, if you need to save space, use only the fonts you need.
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 → 5V
- GND → GND
- SDA → Pin 20 (SDA)
- SCL → Pin 21 (SCL)
Check Power Supply
Make sure the Arduino Mega is receiving adequate power through the USB cable or external power supply.
Video Tutorial
...VIDEO LINK_VIDEO_ARDUINO_MEGA_SSD1309_OLED_DISPLAY