26
- December
2020
Posted By : Dave Hartburn
Micro:bit OLED (SSD1306) Screen

Small OLED screens for microcontrollers are a cheap and easy way to display more detailed output for your Micro:bit than the scrolling LED matrix allows. Often sold as 0.96″ screens, these are just under 25mm wide and come in two formats. The larger square screen is 128×64 pixels or the slimmer model (pictured above) is half the height at 128×32 pixels. Some SPI connection versions are available, this post covers connections for I2C connections or the 4-pin version.

Connect up the screen as shown below. The two power pins, Vcc and GND connect to 3v and GND on the Micro:bit. On the Micro:bit, pins 19 and 20 are the I2C pins, connect SCL on the screen to pin 19 and SDA to pin 20. It is possible to connect multiple devices to I2C, while leaving the other IO pins free.

To use the OLED screen, we need to add additional libraries to MU editor. Libraries are additional software packages that add functions and hardware support, so you do not have to write everything yourself. Helpfully, ‘fizban99’ has produced a Micro:bit python library for OLED screens. Go to their Github page and using the green ‘Code’ button, select ‘Download ZIP’.

Open the ZIP file and copy all the python (.py) files into your mu_code folder (not a subdirectory). Use the following code to display some sample text:

from microbit import *
from ssd1306 import initialize, clear_oled
from ssd1306_text import add_text

initialize()
clear_oled()
add_text(0, 0, "Hello")
add_text(0, 2, "World")
add_text(2, 3, "Micro:bit")
display.show(Image.HAPPY)

This will still fail. Any libraries you need must also be copied to your Micro:bit. Hit the files button in MU and drag to your Micro:bit ‘ssd1306.py’ and ‘ssd1306_text.py’. Now you should have three lines of text displayed.

The libraries are a little limited in that you can’t control the font or font size, however there are a number of graphical functions in the library available. See the Github page for examples. If you are using a 128×32 screen, the same code will work, however you have to be careful not to use additional lines.

Where these screens are useful, is for displaying debugging information or detailed sensor output while developing.

Leave a Reply