SSD1306 OLEDs with Arduino and Orange Pi

10/15/18

Last modified on 10/15/18

Categories: Microcontrollers Single Board Computers Tags: Modules Orange Pi Arduino

~/contents

Round 2 with a 0.96-inch I2C OLED. I fried the first one in the name of science and blamed the Orange Pi people though, in my defense, I’m not the only person confused by that module. This one was quite straightforward, so Yay!

This SSD1306 is a bicolor 128*64 LED display. In this case, bicolor means a 128x16 yellow OLED and a 128x48 blue OLED have been combined. You cannot swap those colors, unlike a bicolor LED matrix which allows you to choose one or the other. Power consumption for a fully-lit screen is 0.08W and it accepts voltage from 3V to 5V. It is compatible with a wide range of microcontrollers. It’s very tiny, but also quite cheap, and useful for basic information displays on sensors, though I have seen people display tiny games on them.

GND - GND
VIN - 5V
SCL - SCL / Nano A5 / OPi PA11|SCK
SDA - SDA / Nano A4 / OPi PA12|SDA

Arduino

Right out of the gate you’ll find several different Arduino libraries for this popular little display. In How to Drive the SSD1306 OLED LCD display Oliver compares the Adafruit and U8G2 driver libraries. The Adafruit library also requires the Adafruit GFX library. By default the library supports 128x32.

Working with the U8G2 examples, this board option works:
U8X8_SSD1306_128X32_UNIVISION_SW_I2C u8x8(/* clock=/ SCL, / data=/ SDA, / reset=*/ U8X8_PIN_NONE); // Adafruit Feather ESP8266/32u4 Boards + FeatherWing OLED

Orange Pi

See my notes for Enabling I2C if needed.

$ sudo i2cdetect -y 0

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

There are several libraries, including luma.oled and Adafruit’s Python version of their SSD1306 library. Since luma.oled works with multiple displays I chose that one. There’s also nopnop2002’s terminal library.

$ sudo apt-get install python-dev python-pip libfreetype6-dev libjpeg-dev build-essential
$ sudo -H pip install --upgrade luma.oled

I wanted to display sensor readings. The first issue is the text doesn’t remain on the screen. In SSD1306 with Python Mr. Scargill provides a simple solution for this.

def do_nothing(obj):
    pass

And once the device is instantiated:

device.cleanup = do_nothing

The second issue is the examples didn’t work out of the box. I think the problem is get_device doesn’t recognize the Orange Pi, so you will need to explicitly identify the device to get the examples running. I discovered terminal mode was what I wanted and it’s well documented in the terminal example.

The None font is super-tiny. I like ProggyTiny.ttf, but if you don’t want any of the packaged fonts you can check your SBC’s onboard fonts with

fc-list