Interface SSD1306 OLED Display with STM32 Blue Pill Board

This tutorial shows how to interface STM32 Blue Pill board with SSD1306 monochrome OLED display module that has a size of 0.96-inch and resolution of 128×64 pixel.
The example shows how to print texts and draw shapes (circles, rectangular…) on the SSD1306 OLED display configured to work in I2C mode.

The STM32 Blue Pill development board is based on STMicroelectronics ARM Cortex-M3 microcontroller STM32F103C8T6 running at maximum clock frequency of 72MHz. This particular development board gained popularity due to its low cost and compact size, making it a popular choice for hobbyists, students, and developers.

To use the STM32 Blue Pill, a hardware programmer, such as ST-Link, is required to upload project code to the board. A USB-to-Serial converter module can also be used to upload the code to the board, an example of this converter is the popular one from FTDI which is FT232RL module.

Abbreviations:
OLED: Organic light Emitting Diode.
I2C: Inter-Integrated Circuit.
SPI: Serial Peripheral Interface.
IoT: Internet of things.

The SSD1306 OLED Display:
The SSD1306 is a driver chip used to control monochrome OLED displays with maximum resolution of 128×64 pixel.
These displays are available in different sizes like 0.96″, 1.3″, and 1.5″, with resolutions of, for example, 128×64 or 128×32 pixels.

Due to their low power consumption, the SSD1306 OLED displays are widely used in DIY & hobbyists electronics, embedded systems, IoT projects, and industrial products.

Technical Specification:
Here are some specifications of the the SSD1306 OLED display module.

Interface with master device:

  • I2C (2-wire): Easy to use and requires only 2 interface lines Clock (SCL) and Data (SDA).
  • SPI (3-wire or 4-wire): Faster then I2C interface but requires more interface lines.

Monochrome: It is a one color display and each pixel may be ON or OFF.
Resolution: The most common resolutions are 128×64 and 128×32 pixels.
Compatibility: Works with a variety of microcontrollers and development boards such as: PIC family MCUs, Arduino, Raspberry Pi, ESP8266/ESP32, etc.
Low power consumption: OLED technology lights up only the required pixels, making it more power-efficient than traditional graphics LCDs.
Viewing Angle: Excellent viewing angles compared to traditional LCDs.

The following image shows a SSD1306 OLED display module with resolution of 128x64pixel and can work in I2C mode only.
This type of display has 4 pins where:
GND: Ground pin (0V)
VCC: Power supply pin, may be 3.3V or 5V (refer to your display datasheet for power supply voltage range, some modules works with 3.3V only).
SCL: Serial clock pin for I2C interface.
SDA: Serial data pin for I2C interface.

I2C SSD1306 OLED display module 128x64 pixel

and the image below shows another version of the display that can be configured to work in I2C or SPI mode where the required mode is configured through resistors as indicated on the PCB.
This module has 7 pins, from left to right:
GND: Ground pin (0V).
VCC: Power supply pin, may be 3.3V or 5V (refer to your display datasheet for power supply voltage range, some modules works with 3.3V only).
SCK: Serial clock pin for SPI or I2C interface.
SDA: Serial data pin for SPI (MOSI) or I2C interface.
RES: Reset pin.
DC: Data/Command pin, used with SPI mode only.
CS: Chip Select pin, used with SPI mode only.

SPI SSD1306 OLED display module 128x64 pixel

 

Many SSD1306 OLED modules come with built-in voltage regulator that supplies the display driver with stable voltage of 3.3V. This type of modules can be supplied with 5V or 3.3V and can be interfaced with 5V microcontroller without any problem.

Interfacing STM32 Blue Pill Board with SSD1306 OLED Display – I2C Mode Example:
This post shows how to easily interface the STM32 Blue Pill development board with SSD1306 OLED display module. Circuit schematic diagram is the shown below.

The SSD1306 display module used in this project has 4 pins connected to the Blue Pill board as follows:
GND pin is connected to GND pin of the STM32 board.
VCC pin is connected to 3.3V pin of the STM32 board.
SCL (I2C Serial clock) pin is connected to pin B6 of the STM32 board.
SDA (I2C Serial data) pin is connected to pin B7 of the STM32 board.

Note that pins B6 and B7 of the STM32 Blue Pill board are hardware I2C pins of the microcontroller STM32F103C8T6, respectively for SCL and SDA lines.

Interfacing STM32F103C8T6 Blue Pill with SSD1306 OLED I2C mode fritzing circuit

Hardware Required:
This is a summary of the parts required to build this project.

Interfacing STM32 Blue Pill Board with SSD1306 OLED Display Code:
Arduino IDE (Integrated Development Environment) is used to write project code, the STM32 Blue Pill board has to be added to the IDE before compiling the code.
The STM32 Blue Pill board can be installed using Arduino IDE Boards Manager.

The FT232RL USB to serial UART converter is used to program the STM32F103C8T6 microcontroller, the ST-LINK V2 programmer also can be used and it is supported by Arduino IDE.

To be able to compile project Arduino code, two libraries are required from Adafruit Industries:
The first library is a driver for the SSD1306 OLED display and it can be installed from Arduino IDE library manager (Sketch —> Include Library —> Manage Libraries…, in the search box write “ssd1306” and install the one from Adafruit).
The second library is Adafruit graphics library which can be installed also from Arduino IDE library manager.
During installation of the Adafruit SSD1306 library, Arduino IDE may ask for installing some other libraries form Adafruit Industries (dependencies).

Project code was tested with the following library versions:
Adafruit GFX Library: Version 1.11.11.
Adafruit SSD1306 OLED display Library: Version 2.5.13.
Adafruit BusIO: Version 1.16.2.

Programming Hints:
The used libraries are included in the Arduino code as shown below:

The resolution of the display used in this project is 128×64 pixel and it is defined in Arduino code as:

The connection of the STM32 board with the SSD1306 display is initialized as shown below.
The display works in I2C mode with slave address 0x3C. If the display does not show any thing try with slave address of 0x3D.

Note that the Arduino code given below is originally comes as an example with the Adafruit SSD1306 OLED library. Minor modification are made to the original code.

Full Arduino code:

Interfacing STM32 Blue Pill Board with SSD1306 OLED Video:
The short video below shows a test circuit of the STM32 board with SSD1306 display.

STM32 Blue Pill Board with SSD1306 Display Proteus Simulation:
The following video shows the simulation of the STM32 Blue Pill board with SSD1306 OLED display.
Note that Proteus simulation circuit and behavior may not be the same as real hardware circuit.

Proteus simulation file download link is below, use version 8.15 or higher to open it:
STM32 Blue Pill with SSD1306 OLED – Proteus simulation


Discover more from Simple Circuit

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top