It's easy to use the Monochrome 1.12" 128x128 OLED with Python or CircuitPython, and the Adafruit CircuitPython DisplayIO SH1107 module. This module allows you to easily write Python code that controls the Monochrome 1.12" 128x128 OLED graphic display.

CircuitPython Microcontroller Wiring

First wire up your OLED to your board exactly as shown below. Here's an example of wiring a Feather M4 to the display with I2C using one of the handy STEMMA QT connectors:

  • Board 3V to display VIN (red wire)
  • Board GND to display GND (black wire)
  • Board SCL to display Clk (yellow wire)
  • Board SDA to display Data (blue wire)

You can also use the standard 0.100" pitch headers to wire it up via I2C on a breadboard:

  • Board 3V to display VIN (red wire)
  • Board GND to display GND (black wire)
  • Board SCL to display Clk (yellow wire)
  • Board SDA to display Data (blue wire)

You can also use the standard 0.100" pitch headers to wire it up via SPI on a breadboard:

To use the board in SPI mode, you must close the J1 jumper on the back.
  • Board 3V to display VIN (red wire)
  • Board GND to display GND (black wire)
  • Board SCK to display Clk (yellow wire)
  • Board MOSI to display Data (blue wire)
  • Board D5 to display CS (orange wire)
  • Board D6 to display DC (green wire)
  • Board D9 to display Rst (purple wire)

CircuitPython Usage

To use with CircuitPython, you need to first install the DisplayIO SH1107 library into the lib folder on your CIRCUITPY drive. This example also requires the Display Text library. Then you need to update code.py with the example script.

Thankfully, we can do this in one go. In the example below, click the Download Project Bundle button below to download the necessary libraries and the code.py file in a zip file. Extract the contents of the zip file, and copy the entire lib folder and the code.py file to your CIRCUITPY drive.

Your CIRCUITPY/lib folder should contain the following folder and file:

  • adafruit_displayio_sh1107.mpy
  • adafruit_display_text/

Example Code

This example defaults to using I2C. To use with SPI, comment out the I2C setup, and uncomment the SPI setup.

Remember, to use the board in SPI mode, you must close the J1 jumper on the back.
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense
"""
Based on example by Mark Roberts (mdroberts1243).

This example writes text to the display, and draws a series of squares and a rectangle.
"""

import board
import displayio
import terminalio
from adafruit_display_text import bitmap_label as label
from adafruit_displayio_sh1107 import SH1107, DISPLAY_OFFSET_ADAFRUIT_128x128_OLED_5297

displayio.release_displays()

# For I2C
i2c = board.I2C()  # uses board.SCL and board.SDA
# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
display_bus = displayio.I2CDisplay(i2c, device_address=0x3D)

# For SPI:
# import busio
# spi_bus = busio.SPI(board.SCK, board.MOSI)
# display_bus = displayio.FourWire(spi_bus, command=board.D6, chip_select=board.D5, reset=board.D9)

# Width, height and rotation for Monochrome 1.12" 128x128 OLED
WIDTH = 128
HEIGHT = 128
ROTATION = 90

# Border width
BORDER = 2

display = SH1107(
    display_bus,
    width=WIDTH,
    height=HEIGHT,
    display_offset=DISPLAY_OFFSET_ADAFRUIT_128x128_OLED_5297,
    rotation=ROTATION,
)

# Make the display context
splash = displayio.Group()
display.root_group = splash

color_bitmap = displayio.Bitmap(WIDTH, HEIGHT, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0xFFFFFF  # White

bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
splash.append(bg_sprite)

# Draw a smaller inner rectangle in black
inner_bitmap = displayio.Bitmap(WIDTH - BORDER * 2, HEIGHT - BORDER * 2, 1)
inner_palette = displayio.Palette(1)
inner_palette[0] = 0x000000  # Black
inner_sprite = displayio.TileGrid(
    inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER
)
splash.append(inner_sprite)

# Draw some white squares
small_bitmap = displayio.Bitmap(8, 8, 1)
small_square = displayio.TileGrid(small_bitmap, pixel_shader=color_palette, x=58, y=17)
splash.append(small_square)

medium_bitmap = displayio.Bitmap(16, 16, 1)
medium_square = displayio.TileGrid(
    medium_bitmap, pixel_shader=color_palette, x=71, y=15
)
splash.append(medium_square)

large_bitmap = displayio.Bitmap(32, 32, 1)
large_square = displayio.TileGrid(large_bitmap, pixel_shader=color_palette, x=91, y=28)
splash.append(large_square)

bottom_bitmap = displayio.Bitmap(110, 50, 1)
bottom_rectangle = displayio.TileGrid(
    bottom_bitmap, pixel_shader=color_palette, x=10, y=69
)
splash.append(bottom_rectangle)

# Draw some label text
name_text = "Monochrome 1.12in"
name_text_area = label.Label(terminalio.FONT, text=name_text, color=0xFFFFFF, x=8, y=8)
splash.append(name_text_area)
size_text = "128x128"
size_text_area = label.Label(terminalio.FONT, text=size_text, color=0xFFFFFF, x=8, y=25)
splash.append(size_text_area)
oled_text = "OLED"
oled_text_area = label.Label(
    terminalio.FONT, text=oled_text, scale=2, color=0xFFFFFF, x=9, y=44
)
splash.append(oled_text_area)

while True:
    pass

Once everything is saved to the CIRCUITPY drive, you should see the display change!

That's all there is to using the Monochrome 1.12" 128x128 OLED Graphic Display with CircuitPython!

This guide was first published on Nov 19, 2021. It was last updated on Mar 28, 2024.

This page (CircuitPython) was last updated on Mar 28, 2024.

Text editor powered by tinymce.