Sunday 29 March 2020

Pimoroni 1.12" OLED breakout

A long time ago I bought a Pimoroni Breakout Garden and a selection of breakouts.

I had intended to write some very simple test code  and put it on the blog, unfortunately I then managed to break the SD card with the code on. Must remember to back up regularly...

The Breakout Garden equipped Pi Zero then languished at the back of the cupboard while other, shinier things caught my attention.

And then I wanted to know what the temperature was. I do have a number of pieces of technology that would do that (Arduino, Micro:Bit, Raspberry Pi), but decided that the Breakout Garden would be a good starting point.

But first I wanted to check out the operation of the OLED display.

1.12" OLED breakout

Pimoroni provide a good set of example code, including a complete weather station, but I wanted to build my own using the supplied modules.

First off a simple piece of Python to display a message on the screen.

# Simple test of a Pimoroni SH1106 Breakout board attached to a Breakout Garden HAT

# Required modules
from luma.core.interface.serial import i2c, spi
from luma.core.render import canvas
from luma.oled.device import ssd1306, ssd1309, ssd1325, ssd1331, sh1106

# Instantiate a luma SH1106 object
oled = sh1106(i2c(port=1, address=0x3C), rotate=2, height=128, width=128)

# Create a suitable canvas to draw on
with canvas(oled) as draw:
    draw.rectangle(oled.bounding_box, outline="white", fill="black")
    draw.text((30, 40), "Hello SH1106!", fill="white")

print("There should be something on the display now")

References