Arduino Mega - OLED 128x32 Display
This guide shows you how to use an Arduino Mega with a 128x32 OLED display using I2C. You'll learn:
- How to connect a 128x32 OLED screen to the Arduino Mega.
- How to make the Arduino Mega show text and numbers on the 128x32 OLED screen.
- How to draw pictures on the 128x32 OLED screen with the Arduino Mega.
- How to show pictures on the 128x32 OLED screen with the Arduino Mega.
- How to center text and numbers on the 128x32 OLED screen, vertically and horizontally.

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 | × | SSD1306 I2C OLED Display 128x32 | |
| 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 OLED Display
I2C OLED Display Pinout
- GND pin: connect to the Arduino Mega ground.
- VCC pin: power for the display; connect to the Arduino Mega 5V pin.
- SCL pin: I2C clock line.
- SDA pin: I2C data line.

※ NOTE THAT:
The pin layout on an OLED module can be different depending on who makes it and the model. Always check the labels on the OLED module and follow them. Pay attention!
This guide is for an OLED display that uses the SSD1306 I2C driver. We tested it with an OLED display from DIYables. It works perfectly, with no problems.
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
If you use a different Arduino Mega, the pin layout will be different from the Uno. See the table below for information about other Arduino Mega models.
| 128x32 OLED Module | Arduino Mega |
|---|---|
| Vin | 5V |
| GND | GND |
| SDA | A4 |
| SCL | A5 |
How To Use OLED with Arduino Mega
Install SSD1306 OLED library
- Find the Libraries icon on the left side of the Arduino IDE.
- Type "SSD1306" into the search box and find the SSD1306 library by Adafruit.
- Click Install to add the library.

- You need to install some extra libraries.
- Click the Install All button to install all the needed libraries.

How to program for OLED
- Add a library.
- Set the screen size to OLED 123 by 32.
- Make an SSD1306 OLED display.
- In the setup() function, get the OLED screen ready.
- Then you can show text, pictures and draw lines.
Arduino Mega Code - Display Text on OLED
These are a few functions you can use to display text on the OLED screen:
- Oled.clearDisplay(): turns off all pixels.
- Oled.drawPixel(x, y, color): draws a dot at position x, y.
- Oled.setTextSize(n): changes text size; choose from 1 to 8.
- Oled.setCursor(x, y): sets where text starts.
- Oled.setTextColor(WHITE): makes the text color white.
- Oled.setTextColor(BLACK, WHITE): makes the text black and the background white.
- Oled.println("message"): shows text.
- Oled.println(number): shows a number.
- Oled.println(number, HEX): shows a number in hex (base-16).
- Oled.display(): refreshes the screen to show changes.
- Oled.startscrollright(start, stop): moves text from left to right.
- Oled.startscrollleft(start, stop): moves text from right to left.
- Oled.startscrolldiagright(start, stop): moves text diagonally from bottom left to top right.
- Oled.startscrolldiagleft(start, stop): moves text diagonally from bottom right to top left.
- Oled.stopscroll(): stops any scrolling text.
Arduino Mega Code - Drawing on OLED
Arduino Mega Code – Display Image
To show a picture on an OLED screen, first turn the picture (any format) into a bitmap array. You can use this online tool https://javl.github.io/image2cpp/ to convert it. Look at the image below to see how to change a picture into a bitmap array. I turned the Arduino icon into a bitmap array.

Copy the new array code and paste it into the Arduino icon array in the code below.
The video below shows how to do it with an OLED 128x64 display, an Arduino Uno, and the Arduino logo.
We can do it the same way to make it work with Arduino Mega and the 128x32 OLED. The code below displays the DIYables icon on the 128x32 OLED.
※ NOTE THAT:
- The image should fit the screen or be smaller.
- If you want to use the code with an OLED 128x32, you need to resize the image and change the width and height in the oled.drawBitmap() function.
How to vertical and horizontal center align text/number on OLED
OLED Troubleshooting
If the OLED screen is blank, please follow these steps:
- Make sure the wiring is correct.
- Check that your I2C OLED uses an SSD1306 driver.
- Check the I2C address of your OLED using the I2C Address Scanner code on the Arduino Mega board.
What you see on the Serial Monitor: