Lloyd Rochester's Geek Blog

I recently bought a DIY Display Module using the SSD1306 Driver from Alibaba AliExpress. In this post we discuss the physical wiring from the display module to the Raspberry Pi and the SPI Mode to interface with it. The goal is to control it in a C program.

Hardware Required

The module I got was a GME12864-83 1.3" SPI OLED SH1106 for $3.52 USD from the S+S+S+.

Display Module Pinout

What’s confusing is the silkscreen on the circuit board for the display module has SCK and SDA which are I2C Pins and not the SCLK and MOSI per the SPI spec. If the pin ends with a # that means it’s active low.

Module PinNameDescriptionType
1GNDGround PinPower
2VDDCMOS Vdd 1.35V to 3.3V for IC LogicPower
3SCLKSPI Serial ClockInput
4MOSISPI Master Out, Slave InInput
5RES#Reset Pin. When LOW, chip will initialize. Keep HIGH for normal operationInput
6D/C#Data/Command. High is to write data (pixels), Low is commands.Input
7CS#Chip Select. Active Low.Input

This pinout is for the 4-wire SPI Interface. This interface has the benefit of being able to send either data or control using the D/C# pin and we can also support multiple display interfaces by using the CS# lines. I think it’s the best fit since it minimizes the amount of software by using more pins - which there are plenty - on the RPI.

Wiring Display Module to Raspberry Pi

Display Module PinDisplay Module Pin NameRPI Pin DescRPI Header PinRPI BCM Pin
1GNDGND9
2VDD3.3V17
3SCKSPIO SCLK2311
4MOSISPI0 MOSI1910
5RES#GPIO5295
6D/C#SPI0 CE0248
7CS#GND246

Having the RES# wired to a GPIO line is helpful since we can reset the display. It does, however, add some more code since we not only have to use SPI in the Raspberry Pi, but also use GPIO.

See Pinout for the Raspberry Pi. Note, the BCM is the actual pin on the Broadcom chip, and not the pin on the header.

SPI Modes

Here is the SPI timing for the SSD1306.

SPI Timing for SSD1306

We have the following SPI Modes. We will need to know which Mode the SSD1306 uses.

ModeCPOLCPHAOutput EdgeInput Edge
000FallingRising
101RisingFalling
210RisingFalling
311FallingRising

From the timing diagram in the Datasheet we can see that data is captured on the rising edge of the Clock so we know CPOL=0. For the input we can see that CPHA=0 since the data changes on the falling edge of the clock and it is valid on the rising edge of the clock.

Thus, the SSD1306 is in SPI Mode 0.

Added

raspi-config # enable spi

Was set to: pi@raspberrypi:~/rpi_ssd1306/src $ ls -l /dev/spidev0.0 crw——- 1 root root 153, 0 Mar 20 20:34 /dev/spidev0.0

Changed to pi@raspberrypi:/rpi_ssd1306/src $ sudo chgrp spi /dev/spidev0* pi@raspberrypi:/rpi_ssd1306/src $ sudo chmod g+rw /dev/spidev0* pi@raspberrypi:/rpi_ssd1306/src $ ls -l /dev/spidev0.0 crw-rw—- 1 root spi 153, 0 Mar 20 20:34 /dev/spidev0.0 pi@raspberrypi:/rpi_ssd1306/src $

What’s Next?

I hope to soon post some C-code to control the SSD1306.