Drive a SSD1306 display with STM32F4 Discovery board and Micropython via SPI

It wasn't trivial to set it up (at least for me), probably it worth to document it, so here is how you can connect and drive an SSD1306 display from Micropython running on an STM32F4 Discovery board:


The labeling of the display pins is a bit ambigous,  so here is the pinout i've used:

Pin label  Function Discovery Pin
VCC   3V3 or 5V 5V
RES   Reset PA3
DC   Data/Command PB1
CS   SPI Chip Select PC5

And this how it looks like when hooked up:



There is already a driver for SSD1306 in the main Micropython source tree which implements both I2C and SPI, but for me the SPI version didn't work, the SPI.init() call missed a parameter:

>>> d = SSD1306_SPI(width, height, spibus, dc, res, cs)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "", line 144, in __init__
  File "", line 49, in __init__
  File "", line 74, in init_display
  File "", line 147, in write_cmd
TypeError: 'mode' argument required

After adding the missing parameter and some sanitizing (Pull request sent to upstream a simple test script works well:

from ssd1306 import SSD1306_SPI
from pyb import SPI
width = 128
height = 64
spibus = SPI(1, SPI.MASTER, baudrate=600000, polarity=1, phase=0,crc=0x7)
dc = pyb.Pin.board.PB1
res = pyb.Pin.board.PA3
cs =  pyb.Pin.board.PC5

d = SSD1306_SPI(width, height, spibus, dc, res, cs)
d.text('Hello There!',0,0)

The whole source code (with the patched driver) available here: You just need upload the content of the ssd1306 directory  onto your (Micropython flashed) STM32F4 Discovery board to get it running.

Update 2017-11-05: turned out that the driver supposed to be used with the 'new' machine.SPI Micropython API, so my fix in the driver isn't needed. During testing this i found some room for improvements in the I2C variant of the driver, and also added a test script, se a new PR was sent  as Also updated the  corresponding files at

Currently unrated