Arduino SH1106 OLED Tutorial: Connect Over I2C and Show Text, Bitmaps and Animations
The SH1106 is a 128 x 64 monochrome OLED controller that is common on 1.3 inch I2C display modules. These modules look almost the same as the 0.96 inch SSD1306 displays, but the two controllers handle display memory differently, so a sketch written for one does not always work on the other. This tutorial shows how to wire an SH1106 module to an Arduino Uno, find its I2C address, install the Adafruit SH110X library and draw text, numbers, shapes, bitmaps and animations.
Each example is a complete sketch. The text and shape examples come first, the bitmap and animation examples follow, and a short section on memory and update speed explains what limits the frame rate on an Uno. A troubleshooting table at the end covers the problems that readers most often meet.
This guide belongs to the Arduino Display Interfacing Tutorials series. Readers who use the 0.96 inch controller can follow the SSD1306 Arduino OLED tutorial, and the Arduino I2C tutorial explains the bus in more detail. Other displays in the series include the ST7735 SPI TFT, the ILI9341 touchscreen and the ST7920 graphic LCD.
Table of contents
- Arduino SH1106 OLED Tutorial: Connect Over I2C and Show Text, Bitmaps and Animations
- SH1106 vs SSD1306 Differences
- Arduino SH1106 Pinout and I2C Address
- Arduino SH1106 Wiring
- Arduino SH1106 I2C Pins by Board
- Adafruit SH110X Library Setup
- Arduino SH1106 Text and Numbers
- Arduino SH1106 Shapes
- Arduino SH1106 Bitmap Images
- Arduino SH1106 Animations
- Arduino SH1106 Memory and Update Speed
- Arduino SH1106 Troubleshooting
- Conclusion
SH1106 vs SSD1306 Differences
The SH1106 and the SSD1306 both drive a 128 x 64 monochrome OLED over I2C or SPI, but the SH1106 has a different memory layout. The SH1106 has 132 columns of display RAM while the panel shows only 128 of them, and most 1.3 inch modules are wired so that the visible area starts at column 2. The SSD1306 has 128 columns of RAM that match the panel exactly.
| Feature | SH1106 module | SSD1306 module |
|---|---|---|
| Typical screen size | 1.3 inch | 0.96 inch |
| Visible resolution | 128 x 64 pixels | 128 x 64 pixels |
| Display RAM width | 132 columns | 128 columns |
| Column offset | Usually 2 columns | None |
| Library class in Adafruit libraries | Adafruit_SH1106G | Adafruit_SSD1306 |
When an SSD1306 library drives an SH1106 module, the image usually appears shifted by two pixels with noise on one edge, and a dedicated library avoids this by applying the offset itself. The 1.3 inch size is the main reason to choose the SH1106, because the larger panel is easier to read at a distance. The SSD1306 Arduino OLED tutorial covers the smaller module.
Arduino SH1106 Pinout and I2C Address
A typical I2C module has four pins, and the table lists them with their connection to an Arduino Uno or Nano.
| Pin | Function | Connection on Uno or Nano |
|---|---|---|
| GND | Ground | GND |
| VCC | Power supply | 3.3V or 5V, see the note below |
| SCL | I2C clock | A5 |
| SDA | I2C data | A4 |
SH1106 Supply Voltage
The original post lists 5V in the pin table and 3.3V in the wiring table. The SH1106 controller itself runs from a low supply of roughly 1.65 V to 3.5 V, and modules that carry an onboard regulator accept 3.3 V or 5 V on the VCC pin. A module without a regulator accepts only 3.3 V. Powering the module from 3.3 V is safe for both kinds, so the wiring in this guide uses the 3.3V pin, but the seller’s description of the particular module should be checked first.
SH1106 I2C Address
Most SH1106 modules answer at the I2C address 0x3C. A few modules use 0x3D, and some have a solder jumper or a resistor position that changes the address. A scanner sketch finds the address of the connected module without guessing.
#include <Wire.h>
void setup() {
Serial.begin(9600);
Wire.begin();
Serial.println("Scanning I2C bus...");
uint8_t found = 0;
for (uint8_t address = 1; address < 127; address++) {
Wire.beginTransmission(address);
if (Wire.endTransmission() == 0) { // 0 means a device acknowledged
Serial.print("Device found at 0x");
Serial.println(address, HEX);
found++;
}
}
if (found == 0) {
Serial.println("No I2C device found. Check the wiring.");
}
}
void loop() {
}The address printed in the Serial Monitor is the value for display.begin() in the sketches below.
Arduino SH1106 Wiring
The module connects to the Arduino with four wires. Connect VCC to the 3.3V pin and GND to GND. Connect SDA to A4 and SCL to A5 on the Uno or Nano, because those two analog pins carry the hardware I2C bus. Reversing SDA and SCL is the most common wiring error and leaves the screen blank.
| OLED pin | Arduino Uno or Nano pin | Description |
|---|---|---|
| VCC | 3.3V | Power for the display |
| GND | GND | Common ground |
| SDA | A4 | I2C data line |
| SCL | A5 | I2C clock line |
The module normally has pull-up resistors on SDA and SCL, so no external resistors are needed. The 1.3 inch module itself is shown in the photo below.
Arduino SH1106 I2C Pins by Board
The I2C pins depend on the board, and the table lists the default pins of the common ones.
| Board | SDA pin | SCL pin |
|---|---|---|
| Arduino Uno and Nano | A4 | A5 |
| Arduino Mega | 20 | 21 |
| Arduino Leonardo | 2 | 3 |
| Arduino Due | 20 | 21 |
| ESP32 | GPIO 21 | GPIO 22 |
The pin layout of each board is shown in the Arduino UNO pinout guide and the Arduino Nano pinout guide. The Due and the ESP32 are 3.3 V boards, so the module must be powered from 3.3 V there.
Adafruit SH110X Library Setup
The Adafruit SH110X library drives the SH1106 and applies its column offset, and it depends on the Adafruit GFX library for text and graphics. Both libraries install through the Arduino IDE.
Install the Libraries
Open the Library Manager from Sketch, Include Library, Manage Libraries. Search for Adafruit SH110X and install it, and accept the installation of Adafruit GFX Library when the IDE offers it as a dependency. If a library is installed from a ZIP file instead, the source is the Adafruit SH110X repository.
Initialize the Display
The first sketch creates the display object, starts it at the I2C address found by the scanner and sends the buffer to the screen. It also stops with a message when the display does not respond, which saves time when the wiring is wrong.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_ADDRESS 0x3C // use the address found by the I2C scanner
// The last argument is the reset pin, and -1 means the module has no reset wire.
Adafruit_SH1106G display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
Serial.begin(9600);
if (!display.begin(OLED_ADDRESS, true)) { // true resets the controller on start
Serial.println("SH1106 not found. Check the wiring and the address.");
for (;;) {} // stop here
}
display.display(); // show the buffer, which holds the library splash screen
}
void loop() {
}A working setup shows the Adafruit splash logo, or a blank screen if the library buffer starts empty. Either result means that the display and the library work. The sketches in the next sections replace display.display() with their own drawing code.
Arduino SH1106 Text and Numbers
Text is drawn into a memory buffer with the Adafruit GFX functions, and display.display() sends the buffer to the screen. Nothing appears until display() runs, and the text colour must be set with setTextColor() in every sketch.
Display Text on the SH1106
The default font is 6 x 8 pixels at text size 1, so a line holds 21 characters and the screen holds 8 lines. Text size 2 doubles both dimensions to 12 x 16 pixels, which fits 10 characters in a line.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
Adafruit_SH1106G display(128, 64, &Wire, -1);
void setup() {
if (!display.begin(0x3C, true)) {
for (;;) {}
}
display.clearDisplay(); // clear the buffer
display.setTextSize(2); // 12 x 16 pixel characters
display.setTextColor(SH110X_WHITE); // required, otherwise nothing is drawn
display.setCursor(0, 10); // x, y of the top-left corner of the text
display.println("Hello OLED"); // 10 characters fit in one line at size 2
display.display(); // send the buffer to the screen
}
void loop() {
}The setCursor() function sets the position of the next character in pixels, and println() moves the cursor to the next line. Text that is longer than the screen wraps to the next line.
Display a Counter Value
A value that changes is shown by clearing the buffer, printing the new value and calling display() again. The sketch below uses millis() for the one-second interval, so the loop stays free for other work.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
Adafruit_SH1106G display(128, 64, &Wire, -1);
unsigned long lastUpdate = 0;
int counter = 0;
void setup() {
if (!display.begin(0x3C, true)) {
for (;;) {}
}
display.setTextColor(SH110X_WHITE);
}
void loop() {
if (millis() - lastUpdate >= 1000) { // update once per second
lastUpdate = millis();
display.clearDisplay();
display.setTextSize(2);
display.setCursor(0, 0);
display.print("Count:");
display.setTextSize(3);
display.setCursor(0, 28);
display.print(counter++); // print, then increase
display.display();
}
}Display Decimal Numbers
The print() function accepts a second argument that sets the number of decimal places for a float. A value such as 23.2678 prints as 23.27 with two places, which is enough for most readings on a screen this small.
float temperature = 23.2678;
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SH110X_WHITE);
display.setCursor(0, 20);
display.print("Temp: ");
display.print(temperature, 2); // two decimal places
display.display();The fragment goes inside setup() or loop() of the sketch above. The DS18B20 Arduino tutorial uses an OLED to show real temperature readings.
Arduino SH1106 Shapes
Adafruit GFX draws lines, rectangles and circles directly into the buffer, and the functions use pixel coordinates with the origin at the top-left corner. The x range is 0 to 127 and the y range is 0 to 63.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
Adafruit_SH1106G display(128, 64, &Wire, -1);
void setup() {
if (!display.begin(0x3C, true)) {
for (;;) {}
}
display.clearDisplay();
display.drawLine(0, 0, 127, 63, SH110X_WHITE); // x0, y0, x1, y1, colour
display.drawRect(5, 5, 40, 25, SH110X_WHITE); // x, y, width, height, colour
display.fillRect(55, 5, 40, 25, SH110X_WHITE); // filled rectangle
display.drawCircle(25, 48, 12, SH110X_WHITE); // centre x, centre y, radius, colour
display.fillCircle(75, 48, 12, SH110X_WHITE); // filled circle
display.display();
}
void loop() {
}The rectangle and circle functions each have a filled version, and the calls above use both. The same colour argument accepts SH110X_BLACK to erase part of a drawing and SH110X_INVERSE to flip the pixels.
Arduino SH1106 Bitmap Images
A bitmap on this display is a monochrome image that is stored as an array of bytes, with one bit for each pixel. A set bit lights the pixel, and a cleared bit leaves it dark. The array is stored in flash memory with the PROGMEM keyword, so it does not use the limited SRAM of the Uno.
Convert an Image with Image2CPP
The online tool Image2CPP converts a picture into the array. Upload the image, set the canvas size to the size at which the image will appear, and choose Arduino code as the output format. Set the draw mode to Horizontal, 1 bit per pixel, because this is the byte order that drawBitmap() expects. If the picture appears with inverted colours on the screen, the Invert image colors option in the tool corrects it.
Create a new tab in the Arduino IDE, name it logo.h, and paste the generated array into it. Give the array a short name such as logo, because the tool’s default name is long. The header file must sit in the same folder as the sketch.
Array Size and drawBitmap()
The number of bytes in the array depends on the image size. Each row uses one byte for every 8 pixels, rounded up, so the size is ((width + 7) / 8) * height bytes.
| Image size | Bytes in the array |
|---|---|
| 16 x 16 | 32 |
| 64 x 64 | 512 |
| 128 x 64 | 1024 |
The drawBitmap() function takes the position, the array, the width, the height and the colour. The width and the height must match the size used in Image2CPP, because a smaller array than the size passed to the function makes the display read bytes beyond the array and show random pixels. The original post showed a 7-byte array drawn with 64 x 64 dimensions, which is such a mismatch.
Display a Full-Screen Bitmap
The sketch below draws a 128 x 64 logo from logo.h on the whole screen.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#include "logo.h" // defines: const unsigned char logo[] PROGMEM = { ... };
Adafruit_SH1106G display(128, 64, &Wire, -1);
void setup() {
if (!display.begin(0x3C, true)) {
for (;;) {}
}
display.clearDisplay();
display.drawBitmap(0, 0, logo, 128, 64, SH110X_WHITE); // x, y, array, width, height, colour
display.display();
}
void loop() {
}Combine Text and a Small Icon
A small icon and a line of text work well together for status screens. The sketch uses a 16 x 16 icon, which needs a 32-byte array from Image2CPP, and it prints the text next to the icon.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
Adafruit_SH1106G display(128, 64, &Wire, -1);
// 16 x 16 icon, 32 bytes. Paste the array generated by Image2CPP here.
const unsigned char wifiIcon[] PROGMEM = {
/* 32 bytes from Image2CPP */
};
void setup() {
if (!display.begin(0x3C, true)) {
for (;;) {}
}
display.clearDisplay();
display.drawBitmap(10, 20, wifiIcon, 16, 16, SH110X_WHITE); // icon at x = 10, y = 20
display.setTextSize(1);
display.setTextColor(SH110X_WHITE);
display.setCursor(32, 24); // text starts to the right of the icon
display.print("Connected");
display.display();
}
void loop() {
}Arduino SH1106 Animations
An animation is a series of frames. Each pass of the loop clears the buffer, draws the next frame, sends it with display() and waits briefly, and the eye reads the result as motion. Every frame needs a full redraw, so the update speed described in the next section sets the upper limit on the frame rate.
Moving Box Animation
The first animation moves a 20 x 20 pixel box from the left edge to the right edge. The position grows by 2 pixels in every frame, and the box starts again from the left when it has left the screen.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
Adafruit_SH1106G display(128, 64, &Wire, -1);
const int16_t BOX_SIZE = 20;
int16_t boxX = -BOX_SIZE; // start just outside the left edge
void setup() {
if (!display.begin(0x3C, true)) {
for (;;) {}
}
}
void loop() {
display.clearDisplay();
display.fillRect(boxX, 22, BOX_SIZE, BOX_SIZE, SH110X_WHITE); // box in the middle of the screen
display.display();
boxX += 2; // move 2 pixels per frame
if (boxX > 128) {
boxX = -BOX_SIZE; // wrap around
}
delay(20);
}Pac-Man Chomping Animation
This animation moves a Pac-Man shape across the screen, opens and closes its mouth and removes each dot as Pac-Man reaches it. The mouth and the movement use millis() timers, so each of them runs at its own rate without blocking the loop. A black triangle drawn over a white circle forms the mouth.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
Adafruit_SH1106G display(128, 64, &Wire, -1);
const int16_t RADIUS = 10; // Pac-Man radius
const int16_t CENTRE_Y = 32; // vertical centre of the screen
const uint8_t DOT_COUNT = 8;
const int16_t DOT_START = 16; // x of the first dot
const int16_t DOT_SPACING = 14; // distance between dots
int16_t pacX = -RADIUS; // start just outside the left edge
bool mouthOpen = true;
unsigned long lastMove = 0;
unsigned long lastMouth = 0;
void drawPacman(int16_t x, bool open) {
display.fillCircle(x, CENTRE_Y, RADIUS, SH110X_WHITE);
if (open) {
// black wedge that points to the right forms the open mouth
display.fillTriangle(x, CENTRE_Y,
x + RADIUS + 1, CENTRE_Y - RADIUS + 2,
x + RADIUS + 1, CENTRE_Y + RADIUS - 2,
SH110X_BLACK);
}
}
void setup() {
if (!display.begin(0x3C, true)) {
for (;;) {}
}
}
void loop() {
unsigned long now = millis();
if (now - lastMouth >= 120) { // toggle the mouth every 120 ms
lastMouth = now;
mouthOpen = !mouthOpen;
}
if (now - lastMove >= 40) { // move and redraw every 40 ms
lastMove = now;
pacX += 2;
display.clearDisplay();
for (uint8_t i = 0; i < DOT_COUNT; i++) {
int16_t dotX = DOT_START + i * DOT_SPACING;
if (dotX > pacX + RADIUS) { // draw only the dots that Pac-Man has not reached
display.fillCircle(dotX, CENTRE_Y, 2, SH110X_WHITE);
}
}
drawPacman(pacX, mouthOpen);
display.display();
if (pacX > 128 + RADIUS) {
pacX = -RADIUS; // start again, which also restores the dots
}
}
}Multi-Frame Custom Animation
A custom animation uses one full-screen bitmap for every frame. Split the source animation into frames, convert each frame with Image2CPP at 128 x 64 pixels and save each array in its own header file, for example frame1.h, frame2.h and frame3.h. Each array needs a different name, such as frame1, frame2 and frame3. The sketch then draws the frames in order.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#include "frame1.h" // const unsigned char frame1[] PROGMEM = { ... };
#include "frame2.h"
#include "frame3.h"
Adafruit_SH1106G display(128, 64, &Wire, -1);
// The list of pointers uses only a few bytes of RAM, and the bitmaps stay in flash.
const unsigned char* const frames[] = { frame1, frame2, frame3 };
const uint8_t FRAME_COUNT = sizeof(frames) / sizeof(frames[0]);
const unsigned long FRAME_DELAY_MS = 100;
uint8_t currentFrame = 0;
unsigned long lastFrame = 0;
void setup() {
if (!display.begin(0x3C, true)) {
for (;;) {}
}
}
void loop() {
if (millis() - lastFrame >= FRAME_DELAY_MS) {
lastFrame = millis();
display.clearDisplay();
display.drawBitmap(0, 0, frames[currentFrame], 128, 64, SH110X_WHITE);
display.display();
currentFrame = (currentFrame + 1) % FRAME_COUNT; // go to the next frame and wrap around
}
}The original post builds a blinking cat eye from three frames of a free GIF and plays them with an 80 ms delay. The same sketch plays that animation when the frame list holds the three cat frames and FRAME_DELAY_MS is set to 80. Any source animation should come from a licence that allows reuse.
Arduino SH1106 Memory and Update Speed
The Adafruit library keeps a copy of the whole screen in RAM, and the Uno has little RAM to spare. A 128 x 64 monochrome display needs 128 x 64 / 8 = 1024 bytes, which is half of the 2048 bytes of SRAM on the ATmega328P. The remaining 1 KB must hold the variables, the stack and any other library, so large arrays belong in flash with PROGMEM.
Every display() call sends that 1024-byte buffer over I2C. At the standard 100 kHz clock the transfer of the data alone takes about 92 ms, because each byte needs nine clock cycles including the acknowledge bit. At 400 kHz the same transfer takes about 23 ms, and the commands for each page add some time on top. The Adafruit library raises the clock for the transfer by default, which keeps full-screen animations near 30 frames per second at best. The delay() values in the examples therefore add to the transfer time, and the real frame rate is lower than the delay alone suggests.
Two habits keep an animation smooth. Call display() once per frame and not after every drawing call, and use millis() timers as in the Pac-Man sketch so that nothing else in the loop is delayed. The Arduino I2C tutorial describes the bus in more detail.
Arduino SH1106 Troubleshooting
Most SH1106 problems come from the I2C wiring, the address or the library choice, and the table lists the common symptoms with their causes and fixes.
| Symptom | Likely cause | Fix |
|---|---|---|
| The screen stays blank. | The address is wrong, SDA and SCL are swapped, or the module has no power. | Run the I2C scanner, check the wiring and use the address it prints in display.begin(). |
| The sketch stops at the message “SH1106 not found”. | The module does not answer at the address in the sketch. | Check the four connections and try 0x3D if the scanner reports that address. |
| The scanner finds no device. | A wire is loose or the module needs 5 V and does not run from 3.3 V. | Reseat the wires, test another module wire and check the seller’s voltage rating. |
| The image is shifted by two pixels or has noise on one edge. | An SSD1306 library is driving the SH1106 module. | Use Adafruit_SH1106G from the Adafruit SH110X library. |
| The text or graphics do not appear. | setTextColor() was not called, or display() was not called after drawing. | Set the colour to SH110X_WHITE and call display() after the drawing code. |
| The bitmap shows random pixels or looks sheared. | The width and height passed to drawBitmap() do not match the array. | Use the size from Image2CPP, and check the array size with the table in the bitmap section. |
| The bitmap has inverted colours. | The tool output is inverted compared with the display. | Switch on Invert image colors in Image2CPP or draw with the other colour. |
| The sketch crashes or behaves strangely after more code is added. | The 1024-byte display buffer leaves too little RAM on an Uno. | Keep bitmaps in PROGMEM, reduce other arrays and avoid large String objects. |
| The animation is slower than the delay suggests. | A full-screen update takes about 23 ms at 400 kHz. | Reduce the delay, draw less per frame and update the display once per frame. |
Conclusion
The SH1106 module works well with an Arduino when it is driven by a library that knows its 132-column memory and the two-column offset. The Adafruit SH110X library handles that offset, and a short I2C scan confirms the address before any drawing code runs. Text, shapes, bitmaps and animations all follow the same pattern of clearing the buffer, drawing and calling display().
The 1024-byte buffer and the I2C transfer time set the practical limits on an Uno. Bitmaps belong in flash memory, each frame should call display() once, and millis() timers keep the rest of the sketch responsive.
The next displays in the series are the ST7735 SPI TFT tutorial for colour graphics and the ILI9341 touchscreen tutorial for touch input. A screen like this one also suits the readings from the Arduino sensor interfacing tutorials.
Download Project Here
Download the Arduino source code — all tested on real hardware.
If you find this useful, you can support us with a Donation as well.
Browse More Arduino Display Tutorials

Arun is an embedded systems engineer with 10+ years of experience in STM32, ESP32, and AVR microcontrollers. He created ControllersTech to share practical tutorials on embedded software, HAL drivers, RTOS, and hardware design — grounded in real industrial automation experience.
Recommended Tools
Essential dev tools
Categories
Browse by platform

















