• sales

    +86-0755-88291180

Raspberry Pi 2.23inch OLED HAT User Guide

Instruction

This is a 2.23inch OLED display within controller.You can directly add it on Raspberry Pi by the 40 PIN pinheader, or connect it to other hardware platform via the IIC and SPI interfaces.The interface of 2.23inch OLED HAT is default SPI, you can also switch to I2C by soldering the resitors on the back of OLED.

Specification

ControllerSSD1305
InterfaceSPI/I2C (default SPI)
Display size2.23inch
Pixel size0.41mm x 0.39mm
Display colorWhite
Working voltage3.3V

Usage Guide

PINS

PINDescription
VCC3.3V/5V
GNDGND
DINMOSI of SPI interface / SDA of I2C interface
CLKSCLK of SPI interface / SCL of I2C interface
CSChip select of SPI interface (Low active) / GND when set to I2C itnerface
DCCommand / Data selection (SPI) / GND (I2C)


The interface of 2.23inch OLED HAT is default SPI interface, that is 0R resistors are soldered to SPI sides. If you want to use I2C interface, you need to solder the 0R resistors to I2C side,

Working principle

SSD1305 is a controller for 132*64 resolution OLED, however, this 2.23inch OLED HAT has only 128*32 resolution, therefore only part of SSD1305's buffer are used.

I2C

At the begging, the Master device sends a byte (7 bits address and 1 bit R/W)to slaver device and wait for a response.

After getting response, the Master device sends a control byte, this byte tells slave device the data followed later is command or data.

Then Master device will send data or command to slaver device.

For more details please refer to Page22 Figure 8-6 of Datasheet

SPI

For details of the SPI communicating, you can refer to Datasheet Page21 Figure8-5.

Exampels

We provide examples for this module based on three popular hardware platform (STM32, Arduino and RaspberryPi). The libraries include supports Drawing points, lines, figures and displaying strings.

You can download the codes from [[#Demo codes] and unzip it to get examples.

STM32 examples

STM32 example is based on Waveshare (XNULCEO-F103RB)

I2C Interface
2.23inch OLED HATSTM32 Board
VCC3.3V
GNDGND
DINPB15
CLKPB13
SPI interface
2.23inch OLED HATSTM32 Board
VCC3.3V
GNDGND
DINPB15
CLKPB13
CSPB12
DCPC6
RSTPC2
  • Open project, compile and download to XNUCLEO-F103RB board
Raspberry Pi example

Hardware connection

I2C interface
2.23inch OLED HATRaspberry Pi (BCM)
VCC3.3V
GNDGND
DINSDA
CLKSCL
SPI interface
2.23inch OLED HATRaspberry Pi(BCM)
VCC3.3V
GNDGND
DINMOSI
CLKSCLK
CSCE0
DC24
RST25

Software setting

Open terminal of Raspbain and enable I2C/SPI interface

sudo raspi-config

Choose Interfacing Options -> I2C -> Yes;

or

Choose Interfacing Options -> SPI ->Yes;

Libraries Installation

Open terminal of Raspbain and install libraries (BCM2835, wiringPi, Python) as below

#Installing BCM2835 library, for more details of the libraries, you can refer ti its website: http://www.airspayce.com/mikem/bcm2835/
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
make
sudo make check
sudo make install

#Installing 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

#Installing python libraries
#python2
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
#python3
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

Runing example (Take SPI codes as example)

Copy Raspberry Pi codes which is downloaded before to Raspberry Pi, put it to /home/pi of Raspbian

Enter the corresponding directory of codes and execute commands to run:

#bcm2835:

cd ~/Raspberry Pi/SPI/bcm2835
make
sudo ./oled

#wiringPi
cd ~/Raspberry Pi/SPI/wiringPI
make
sudo ./oled

#python

cd ~/Raspberry Pi/SPI/python
sudo python stats.py

Note: If wiringPi and Python example work abnormally after bcm2835 example, please reboot and test again.

Arduino example

This examples are based on Waveshare UNO PLUS which is compatible with official Arduino UNO R3

  • Connect OLED to UNO Plus according to figure below:
I2C interface
PINUNO PLUS
VCC3.3V
GNDGND
DINSDA/D14
CLKSCL/D15
SPI interface
PINUNO PLUS
VCC3.3V
GNDGND
DIND11(MOSI)
CLKD13(SCK)
CSD10
DCD8
RSTD9

How to create image data

  • Open Image2Lcd software
  • Open an BMP file
  • Set Data type: *c
Scanning type: Horizontal
Grey Scale: Monochrome
Max height and width: 128 32

The expected result: