Home » News » How To Use OLED Sh1106 Screen?

How To Use OLED Sh1106 Screen?

Views: 222     Author: Tina     Publish Time: 2025-06-19      Origin: Site

Inquire

facebook sharing button
twitter sharing button
line sharing button
wechat sharing button
linkedin sharing button
pinterest sharing button
whatsapp sharing button
sharethis sharing button
How To Use OLED Sh1106 Screen?

Content Menu

Introduction

Understanding the SH1106 OLED Screen

Hardware Specifications and Pinout

Wiring the SH1106 OLED to Microcontrollers

>> Connecting to Arduino (I2C)

>> Connecting to Raspberry Pi (I2C)

>> SPI Wiring Example

Setting Up the Software Environment

>> Arduino

Initializing and Testing the Display

>> Arduino

>> Raspberry Pi

Displaying Text, Numbers, and Graphics

>> Text Display

>> Displaying Numbers

>> Drawing Lines, Rectangles, and Circles

Drawing Images and Animations

>> Displaying Bitmaps

>> Animations

Advanced Features: Scrolling, Contrast, and Power Modes

>> Scrolling

>> Adjusting Contrast

>> Power Modes

Troubleshooting Common Issues

Conclusion

Frequently Asked Questions

>> 1. What is the default I2C address for SH1106 OLED screens?

>> 2. Can I use the SH1106 OLED with both Arduino and Raspberry Pi?

>> 3. How do I display custom images on the SH1106 OLED?

>> 4. Why is my SH1106 OLED screen blank or flickering?

>> 5. How can I improve the display contrast or reduce power consumption?

Introduction

OLED displays have become a staple in modern electronics projects due to their crisp visuals, low power consumption, and versatility. Among the various OLED controllers, the SH1106 stands out for its widespread use in 1.3-inch 128x64 pixel screens. Whether you are building a DIY gadget, upgrading a Raspberry Pi project, or adding a display to your Arduino, mastering the SH1106 OLED screen opens up a world of creative possibilities.

This in-depth guide will walk you through everything you need to know about using the SH1106 OLED screen. From understanding its hardware features to wiring, coding, displaying text, graphics, and troubleshooting, this article aims to be your definitive resource. Throughout the article, you will find illustrative diagrams, code snippets, and detailed explanations to enhance your learning experience.

how to use OLED sh1106 screen

Understanding the SH1106 OLED Screen

The SH1106 is a single-chip CMOS OLED/PLED driver with a controller, designed for monochrome dot-matrix graphic displays. It supports resolutions up to 132x64 pixels and is commonly found in 1.3-inch displays with a 128x64 pixel active area. The SH1106 offers multiple interface options, including I2C, 3-wire SPI, and 4-wire SPI, making it compatible with a wide range of microcontrollers and single-board computers.

One key distinction between the SH1106 and similar controllers like the SSD1306 is the slightly larger internal memory addressing of the SH1106, which accounts for 132 columns even though only 128 are visible on the screen. This difference means that some libraries designed for SSD1306 may not work perfectly with SH1106 without modification.

The SH1106's internal architecture allows for efficient control of the OLED pixels, enabling high contrast and fast refresh rates. Its monochrome nature means it displays pixels as either on or off, which simplifies rendering but also requires creative use of dithering or animation for more complex visuals.

Hardware Specifications and Pinout

Key Features:

- Display Size: 1.3 inches

- Resolution: 128x64 pixels (active area)

- Controller: SH1106

- Interface: I2C (default), 3-wire SPI, 4-wire SPI

- Operating Voltage: 3.3V to 5V (check your module)

- Viewing Angle: >160°

- Colors: Monochrome (typically blue, white, or yellow)

- Operating Temperature: -20°C to 70°C

Pinout Diagram:

Below is a typical pinout for an SH1106 OLED module using I2C:

Pin Function Description
GND Ground Connect to microcontroller GND
VCC Power Supply 3.3V or 5V depending on module
SCL I2C Clock Serial clock line
SDA I2C Data Serial data line

For SPI mode, additional pins like CS (Chip Select), DC (Data/Command), and RES (Reset) are used. Always refer to your specific module's datasheet for exact pin labeling.

The physical layout of the pins may vary between manufacturers, so it is crucial to verify the pin functions before wiring. Some modules also include a reset pin or allow switching between I2C and SPI via solder jumpers or pins.

Wiring the SH1106 OLED to Microcontrollers

Connecting to Arduino (I2C)

The most common and straightforward way to connect the SH1106 OLED to an Arduino is via the I2C interface. This method uses only four wires, simplifying connections and reducing pin usage.

1. Connect GND on the OLED module to the Arduino GND pin.

2. Connect VCC on the OLED to the Arduino 3.3V or 5V pin, depending on your module's voltage requirements.

3. Connect SCL on the OLED to the Arduino's SCL pin (A5 on Uno/Nano).

4. Connect SDA on the OLED to the Arduino's SDA pin (A4 on Uno/Nano).

Ensure that your Arduino board supports I2C on these pins or use the dedicated I2C pins on boards like the Arduino Mega or Leonardo.

Connecting to Raspberry Pi (I2C)

For Raspberry Pi, the SH1106 OLED can be connected via the Pi's I2C interface:

1. Connect GND on the OLED to any GND pin on the Pi.

2. Connect VCC to the Pi's 3.3V pin (do not use 5V unless the OLED module supports it).

3. Connect SCL to the Pi's SCL pin (GPIO 3).

4. Connect SDA to the Pi's SDA pin (GPIO 2).

Before running your code, enable I2C on the Raspberry Pi via `raspi-config` and install necessary libraries.

SPI Wiring Example

If your SH1106 module supports SPI, wiring will involve additional pins:

- CS (Chip Select): Selects the device for SPI communication.

- DC (Data/Command): Switches between sending data or commands.

- RES (Reset): Resets the display.

Connect these pins to available GPIOs on your microcontroller and configure your software accordingly.

SH1106 OLED Display Example Code

Setting Up the Software Environment

Arduino

To work with the SH1106 OLED on Arduino, you need to install a compatible library. The U8g2 library is highly recommended because it supports SH1106 displays and offers a wide range of fonts and graphics functions.

- Open the Arduino IDE.

- Go to Sketch > Include Library > Manage Libraries.

- Search for U8g2 and install it.

Once installed, include the library in your sketch and initialize the display with the correct constructor for SH1106.

Initializing and Testing the Display

After wiring and setting up the software, the next step is to initialize the display and perform a simple test to confirm everything works.

Arduino

Begin by initializing the display in your `setup()` function. Then, clear the display buffer, set a font, and write a simple message to the screen. Finally, send the buffer to the display to render the content.

Raspberry Pi

Using Python, initialize the device object and create a drawing canvas. Write text or draw shapes on the canvas, which will be rendered on the OLED screen.

This initial test confirms that your wiring is correct, the display is functional, and your software environment is properly configured.

Displaying Text, Numbers, and Graphics

Text Display

Displaying text on the SH1106 involves selecting a font, positioning the cursor, and writing the string. The U8g2 library for Arduino and the luma.oled library for Python both support multiple fonts, including scalable and fixed-width fonts.

You can display static messages or dynamically update text, such as sensor readings or status updates. Positioning is controlled by pixel coordinates, allowing precise placement anywhere on the screen.

Displaying Numbers

Numbers are typically converted to strings before display. This allows you to format decimal places, add units, or concatenate with other text. For example, displaying temperature readings or time values is straightforward.

Drawing Lines, Rectangles, and Circles

The SH1106 supports basic graphic primitives. You can draw lines, rectangles (filled or outlined), circles, and other shapes. These are useful for creating custom UI elements like progress bars, frames, or icons.

Using these primitives combined with text allows you to build rich interfaces despite the monochrome display.

Drawing Images and Animations

Displaying Bitmaps

To display images, convert your graphics to monochrome bitmaps. This can be done using image editing software or online converters that output arrays of bytes representing pixel data.

Once converted, include the bitmap array in your code and use the display library's bitmap drawing functions to render the image.

Animations

Animating on the SH1106 involves updating the display buffer repeatedly with new frames. Since the display is monochrome and has limited resolution, animations are typically simple, such as blinking icons, moving bars, or frame-by-frame sprite animations.

Keep animations smooth by controlling the update rate and minimizing the amount of data sent per frame.

Advanced Features: Scrolling, Contrast, and Power Modes

Scrolling

The SH1106 controller supports hardware scrolling in horizontal and vertical directions. This can be used to create marquee text effects or to scroll through menus.

Scrolling commands are available in the controller's instruction set and can be accessed via libraries or direct command sending.

Adjusting Contrast

Adjusting the contrast helps optimize visibility under different lighting conditions. Higher contrast improves readability but may increase power consumption.

Use library functions to set contrast levels dynamically based on ambient light or user preference.

Power Modes

The SH1106 supports sleep and wake modes to conserve power. When the display is not needed, putting it to sleep reduces current draw significantly.

Implementing power management is essential for battery-powered projects to extend operating time.

Troubleshooting Common Issues

- Blank Screen: Double-check wiring, ensure the power supply is adequate, and verify the I2C address.

- Garbled or Partial Display: Confirm that you are using the correct library for SH1106 and not SSD1306. Also, check for loose connections.

- No Response: Make sure the display is not in sleep mode and that your microcontroller pins match your code configuration.

- Flickering: This can be caused by unstable power or incorrect initialization sequences. Use capacitors on power lines if necessary.

Thoroughly testing each step from wiring to code helps isolate issues quickly.

Conclusion

The SH1106 OLED screen is a versatile and powerful display solution for hobbyists and professionals alike. With its flexible interface options, crisp visuals, and robust library support, integrating it into your projects is straightforward. By following the steps outlined in this guide—covering hardware setup, software configuration, and advanced features—you can unlock the full potential of your SH1106 OLED display.

Whether you aim to display sensor data, graphics, or animations, the SH1106 offers reliable performance and creative flexibility. Experiment with different fonts, images, and effects to create engaging user interfaces for your electronics projects.

SH1106 OLED Screen Arduino Wiring

Frequently Asked Questions

1. What is the default I2C address for SH1106 OLED screens?

The default I2C address for most SH1106 OLED modules is 0x3C. Some modules may use 0x3D; always check your module's datasheet or test both addresses if you encounter issues.

2. Can I use the SH1106 OLED with both Arduino and Raspberry Pi?

Yes, the SH1106 OLED is compatible with both Arduino and Raspberry Pi platforms. You need to use the appropriate libraries for each platform and ensure correct wiring for I2C or SPI communication.

3. How do I display custom images on the SH1106 OLED?

Convert your image to a monochrome bitmap (1-bit per pixel) using an image editor or online tool. Save the bitmap as a byte array in your code and use the display library's bitmap function to render it.

4. Why is my SH1106 OLED screen blank or flickering?

Common causes include incorrect wiring, insufficient power, wrong I2C address, or using a library designed for a different controller (such as SSD1306). Double-check your connections and library selection.

5. How can I improve the display contrast or reduce power consumption?

Use the display library's contrast adjustment function to set optimal contrast. To save power, enable sleep mode when the display is not in use, and reduce screen updates to the minimum necessary.

News

PRODUCTS

QUICK LINKS

CONTACT

Building 1, Taihong Industrial Park, West Daya Bay, Huizhou, Guangdong, China
  +86 0752 5556588
Copyrights 2025 Huizhou Kelai Electronics Co., Ltd.