Python Library – OLED display (schrottratte)

library icon
Python OLED library (schrottratte)

Informatie (ENG):

SH1106 / SSD1306 OLED Driver (only tested with SH1106).

I forked the original and made some minor changes, to make it work with a BPi-M1 on Armbian Jessie Vanilla.

Interfacing OLED matrix displays with the SH1106 (or SSD1306) driver in Python using I2C on the Banana Pi. The particular kit I bought from Amazon: SainSmart 1.3″ I2C IIC Serial 128X64 OLED.

The SH1106 display is 128×64 pixels, and the board is tiny, and will fit neatly inside my BPi Case.

Pre-requisites

This was tested with Armbian-Jessie on a BP1-M1, with Mainline Kernel .

Install some packages(most should be already installed):

Next check that the device is communicating properly:

Installing the Python Package

From the bash prompt, enter:

This will install the python files in /usr/local/lib/python2.7 making them ready for use in other programs.

Software Display Driver

The screen can be driven with python using the oled/device.py script. There are two device classes and usage is very simple if you have ever used Pillow or PIL.

First, import and initialise the device:

The display device should now be configured for use. The specific ssd1306 or sh1106 classes both expose a display()method which takes a 1-bit depth image. However, for most cases, for drawing text and graphics primitives, the canvas class should be used as follows:

The canvas class automatically creates an ImageDraw object of the correct dimensions and bit depth suitable for the device, so you may then call the usual Pillow methods to draw onto the canvas.

As soon as the with scope is ended, the resultant image is automatically flushed to the device’s display memory and the ImageDraw object is garbage collected.

Run the demos in the example directory:

Note that python-dev (apt-get) and psutil (pip) are required to run the sys_info.py example. See install instructions for the exact commands to use.


Download @ Github.com

Top