1.3inch OLED Module (C)

From Waveshare Wiki
Revision as of 02:40, 10 June 2022 by Eng52 (talk | contribs) (→‎Python)
Jump to: navigation, search
1.3inch OLED Module (C)
1.3inch-OLED-Module (C)





1.3inch LCD HAT, SPI/I2C interfaces


  • Working Voltage:3.3V
  • Communication Interface:SPI/IIC
  • Controller:SH1107
  • Resolution:64 × 128
  • Display Area:14.7 × 29.42 (mm)
  • Pixel size:0.15 × 0.15 (mm)
  • Dimension: 30 × 39.5(mm)
  • Color: Black/White


PIN Description
VCC Power input(3.3V)
GND Ground
DIN MOSI pin of SPI (Data input)
CLK SCLK pin of SPI (Clock input)
CS Chip selection, low active
DC Data/Command, Low for command and High for data
RST Reset, Low active

Hardware Configuration

1.3inch OLED Module (C).png

The OLED module provides two drive interfaces: 4-wire SPI and I2C. There is a resistor that can be soldered on the back of the module, and the corresponding communication mode can be selected through the selection of the resistor, as shown in the figure:
The module uses 4-wire SPI communication mode by default, that is, IM is connected to 0 by default (1 and 0 do not represent the level, just the welding method of connecting or connecting the resistance, the specific hardware link is shown in the following table):
Note: The above picture is the welding on the hardware, the following table is the actual hardware connection

Communication Method IM
4-wire SPI 0
I2C 1

The specific hardware configuration is as follows:

  • Using 4-wire SPI:

That is, the factory program setting: IM is connected to 0 and connected to the ground;

  • Using I2C:

IM is connected to 1 to VCC (3.3V);
When using I2C: The high and low state of DC can control the address of the slave device. If it receives a low level, then the 7-bit address of I2C is: 0x3C;
PS: The program defaults to SPI mode. If you need to switch the mode, please modify DEV_Config.h. For details, please refer to the program description - bottom hardware interface - interface selection

OLED and its controller

This OLED integrates the SH1107 controller which has 128x128 bits SRAM, supports 128x128 resolution. The controller features SPI/IIC/ 6800/8080 interface and 256 brightness levels. The resolution of this 1.3inch OLED is only 64x128, only half of the SRAM is used.
This OLED use four-line SPI and I2C interface for communicating, which supports higher compatibility and speed.


Note: The MISO pin is hidden, for more details, you can refer to Datasheet Page11.
CS: Chip selection of the slaver, the chip is activated when CS is Low;
SI(D1): This is MOSI pin, the pin is used to transmit data from master to slaver;
SCL(D0)is the SPI clock
A0: This is the DC pin, it is used to determine the data input, DC=0: command is sent;

SPI communication has data transfer timing, which is combined by CPHA and CPOL.
CPOL determines the level of the serial synchronous clock at an idle state. When CPOL = 0, the level is Low. However, CPOL has little effect on the transmission.
CPHA determines whether data is collected at the first clock edge or at the second clock edge of the serial synchronous clock; when CPHL = 0, data is collected at the first clock edge.
According to the figure, SCL is high in idle and it starts to transmit data at the second edge. therefore the timing is Mode 3 (0x11). Data is transmitted in MSB format.


We provide examples that are based on BCM2835、WiringPi、File IO and RPI(Python)librraies.

Hardware connection

You should connect the OLED to your Raspberry Pi by the 7pin cable according to the table

Connect to Raspberry Pi
OLED Raspberry Pi
BCM2835 Board
VCC 3.3V 3.3V
CS 8 CE0
DC 25 GPIO.26
  • Four-wire SPI wiring diagram

1.3inch oled module c-spi.png

Enable SPI and IIC Interface

  • Open the Raspberry Pi terminal and run the following command
sudo raspi-config
Choose Interfacing Options -> SPI -> Yes 

Choose Interfacing Options -> I2C -> Yes RPI open spi.png
Reboot Raspberry Pi:

sudo reboot

Libraries Installation

  • Install BCM2835 libraries
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.60.tar.gz
tar zxvf bcm2835-1.60.tar.gz 
cd bcm2835-1.60/
sudo ./configure
sudo make
sudo make check
sudo make install
#For more details, please refer to http://www.airspayce.com/mikem/bcm2835/
  • Install wiringPi libraries
sudo apt-get install wiringpi

#For Pi 4, you need to update it:
cd /tmp
wget https://project-downloads.drogon.net/wiringpi-latest.deb
sudo dpkg -i wiringpi-latest.deb
gpio -v
#You will get 2.52 information if you install it correctly
  • Install Python libraries
sudo apt-get update
sudo apt-get install python-pip
sudo apt-get install python-pil
sudo apt-get install python-numpy
sudo pip install RPi.GPIO
sudo pip install spidev
sudo apt-get update
sudo apt-get install python3-pip
sudo apt-get install python3-pil
sudo apt-get install python3-numpy
sudo pip3 install RPi.GPIO
sudo pip3 install spidev

Downlaod example

Open the terminal and run the following commands:

sudo apt-get install p7zip-full
sudo wget https://www.waveshare.com/w/upload/3/37/1.3inch_OLED_Module_C_code.7z
7z x 1.3inch_OLED_Module_C_code.7z -O./1.3inch_OLED_Module_C_code
cd 1.3inch_OLED_Module_C_code/raspberry/

Run the test codes

Please first go into the raspberry directory of examples and then run the following command:

C Code

  • Recompile may take a few seconds
cd c
sudo make clean
sudo make -j 8
  • The test program of all screens can be called directly by entering the corresponding size:
sudo ./main screen size
  • Depending on the LCD, you can enter one of the following commands:
#0.91inch OLED Module
sudo ./main 0.91
#0.95inch RGB OLED (A)/(B)
sudo ./main 0.95rgb
#0.96inch OLED (A)/(B)
sudo ./main 0.96
#1.3inch OLED (A)/(B)
sudo ./main 1.3
#1.3inch OLED Module (C)
sudo ./main 1.3c
#1.5inch OLED Module
sudo ./main 1.5
#1.5inch RGB OLED Module
sudo ./main 1.5rgb


  • Enter the python program directory
cd python/example
  • Run the corresponding OLED demo, the program supports python2/3

If you purchased a 1.3inch OLED Module (C), please enter:

# python2
sudo python OLED_1in3_c_test.py
# python3
sudo python3 OLED_1in3_c_test.py

If you purchased a 1.5inch RGB OLED Module, please enter:

# python2
sudo python OLED_1in5_rgb_test.py
# python3
sudo python3 OLED_1in5_rgb_test.py
  • Model Command Correspondence Table
#0.91inch OLED Module
sudo python OLED_0in91_test.py
#0.95inch RGB OLED (A)/(B)
sudo python OLED_0in95_rgb_test.py
#0.96inch OLED (A)/(B)
sudo python OLED_0in96_test.py
#1.3inch OLED (A)/(B)
sudo python OLED_1in3_c_test.py
#1.3inch OLED Module (C)
sudo python OLED_1in3_test.py
#1.5inch OLED Module
sudo python OLED_1in5_test.py
#1.5inch RGB OLED Module
sudo python OLED_1in5_rgb_test.py
  • Please make sure the SPI is not occupied by other devices, you can check in the middle of /boot/config.txt

STM32 guides

The examples is based on STM32F103RBT6

Harware connection

The examples is based on STM32F103RBT6, if you want to use the OLED with other STM32 board, you should porting the codes to your project.

Connect to STM32F103RBT6
VCC 3.3V

Run demo codes

The examples provided are based on HAL libraries. Download the demo codes and go into STM32 directory
STM32 1 1in3OLED module c.png
Open the oled_demo.uvprojx project by Keil5, which is located in 1.3inch_OLED_Module(C)_code\STM32\MDK-ARM, compile and download it to your STM32 board

Arduino guides

Hardware connection

The examples and connections are based on Arduino UNO, if you want to use the OLED with other type of Arduino, you need to correct the connection and codes according to the Arduino board.

Connect to Arduino UNO
VCC 3.3V
CS D10

Run the example

Download the demo codes and go into Arduino directory.
Open the OLED_Show.ino file by Arduino IDE, which is located in 1.3inch_OLED_Module(C)_code\Arduino\OLED_Show, compile and upload the codes to your Arduino board



Demo codes


If you require technical support, please go to the Support page and open a ticket.