• sales

    +86-0755-88291180

1.3inch OLED HAT User Guide

Introduction

1.3inch LCD HAT, SPI/I2C interfaces

Specification

  • Driver: SH1106
  • Interface: 4-wire SPI, 3-wire SPI, I2C
  • Resolution: 128 x 64
  • Display Size: 1.3inch
  • Outline Dimension: 65mm x 30mm
  • Display color: blue
  • Visible Angle: >160°
  • Operating TEMP. (℃): -20~70
  • Storage TEMP. (℃): -30~80

Pin Function

PIN FunctionBCMDescription
KEY1P21Button 1/GPIO
KEY2P20Button 2/GPIO
KEY3P16Button 3/GPIO
Joystick UpP6Go Up
Joystick DownP19Go Down
Joystick LeftP5Go Left
Joystick RightP26Go Right
Joystick PressP13Press Down
SCLKP11/SCLKSPI Clock input
MOSIP10/MOSISPI Data input
SCLP3/SCL1I2C Clock Input
SDAP2/SDA1I2C Data Input
DCP24Data/Command
CSP8/CE0Chip Selection
RSTP25Reset

Hardware Configuration

The OLED module provides three drive interfaces: 3-wire SPI, 4-wire SPI and I2C interface. There are six resistors that can be soldered on the back of the module. The corresponding communication method is selected by the electronic selection, as shown in the figure:
The module uses a 4-wire SPI communication mode by default, that is, BS0, BS1, DC, CS, CLK, and DIN are connected to 0 by default (1 and 0 do not represent the level, but the welding method of connecting or connecting the resistance, the specific hardware link is as follows surface):
Note: The above picture is the welding on the hardware, the following table is the actual hardware connection

Communication MethodBS1/BS0CSDCDINCLK
3-wire SPI0/1CS1MOSISCLK
4-wire SPI0/0CSDCMOSISCLK
I2C1/001SDASCL

The specific hardware configuration is as follows:

  • Using 4-wire SPI:

That is, the factory program settings: BS0 and BS1 connect 0 to ground, CS connect 0 to CE0 (enable pin), D/C connect 0 to P24 (data/command pin) of Raspberry Pi, DIN to 0 is connected to Raspberry Pi MOSI, and CLK to 0 is connected to Raspberry Pi SCLK;

  • Using 3-wire SPI:

Connect BS0 to 1 to VCC, BS1 to 0 to connect to GND, CS to 0 to connect to Raspberry Pi CE0, D/C to 1 to connect to GND, DIN to 0 to connect to Raspberry Pi MOSI, CLK to 0 to connect to the tree Raspberry Pi SCLK;

  • Using I2C:

Connect BS0 to 0 to GND, BS1 to 1 to VCC (3.3V), CS to 1 to connect to GND, D/C to 1 to connect to GND, DIN to 1 to connect to Raspberry Pi SDA, CLK to 1 to connect to the tree Raspberry Pi SCL; when using I2C: the high and low states of DC can control the address of the slave device, here is connected to GND, then the 7-bit address of I2C is: 0x3C

Raspberry Pi

Enable SPI interface

  • Open terminal, use command to enter the configuration page
sudo raspi-config
Choose Interfacing Options -> SPI -> Yes  to enable SPI interface


Reboot Raspberry Pi:

sudo reboot

Please make sure that the SPI interface was not used by other devices, and you can check it in /boot/config.txt.

  • Check /boot/config.txt, and you can see 'dtparam=spi=on' was written in.

To make sure SPI is not occupied, it is recommended to close other drivers' coverage. You can use ls /dev/spi to check whether SPI is occupied. If the terminal outputs /dev/spidev0.1 and /dev/spidev0.1, SPI is not occupied.

Enable I2C Interface

  • Open the Raspberry Pi terminal and enter the following command to enter the configuration interface
sudo raspi-config
Select Interfacing Options -> I2C ->yes to start the i2C kernel driver

and the reboot RPi

sudo reboot


Install Libraries

BCM2835

#Open the Raspberry Pi terminal and run the following command
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.71.tar.gz
tar zxvf bcm2835-1.71.tar.gz
cd bcm2835-1.71/
sudo ./configure && sudo make && sudo make check && sudo make install
# For more information, please refer to the official website: http://www.airspayce.com/mikem/bcm2835/

WiringPi

#Open the Raspberry Pi terminal and run the following command
sudo apt-get install wiringpi
#For Raspberry Pi systems after May 2019 (earlier than before, you may not need to execute), you may need to upgrade:
wget https://project-downloads.drogon.net/wiringpi-latest.deb
sudo dpkg -i wiringpi-latest.deb
gpio -v
# Run gpio -v and version 2.52 will appear. If it does not appear, the installation is wrong

#Bullseye branch system use the following command:
git clone https://github.com/WiringPi/WiringPi
cd WiringPi
./build
gpio -v
# Run gpio -v and version 2.60 will appear. If it does not appear, it means that there is an installation error
  • python
#python2
sudo apt-get update
sudo apt-get install python-pip 
sudo pip install RPi.GPIO
sudo apt-get install python-smbus
sudo pip install spidev

#python3
sudo apt-get update
sudo apt-get install python3-pip 
sudo pip3 install RPi.GPIO
sudo apt-get install python3-smbus
sudo pip3 install spidev

Download Example

Run in the terminal of RPi:

sudo apt-get install p7zip-full
wget https://www.waveshare.com/w/upload/5/53/1.3inch-OLED-HAT-Code.7z
7zr x 1.3inch-OLED-HAT-Code.7z -r -o.
sudo chmod 777 -R  1.3inch-OLED-HAT-Code
cd 1.3inch-OLED-HAT-Code/RaspberryPi/

Test Program

  • C
cd C
make clean
make
sudo ./main
  • python
#python2
cd python2
sudo python main.py
sudo python key_demo.py
#python3
cd python3
sudo python3 main.py
sudo python3 key_demo.py
  • For Raspberry Pi 4B and the system after raspbian_lite-2019-06-20, you need to set as follows, and the key can be input normally
sudo nano /boot/config.txt
#add:
gpio=6,19,5,26,13,21,20,16=pu

I2C Control

  • The 4-wire SPI used by default, if the hardware is modified to I2C, the program needs to be modified

C

Open C\obj\DEV_Config.h,change

#define USE_SPI 1
#define USE_IIC 0

To

#define USE_SPI 0
#define USE_IIC 1

and then execute again:

make clean
make
sudo ./main

python

Open python2/config.py, change:

Device_SPI = 1
Device_I2C = 0

To

Device_SPI = 0
Device_I2C = 1

and then execute again:

sudo python main.py

The same is true for python3

Jetson Nano

Install Libraries

  • Open the trminal and enter the following commands
sudo apt-get update
sudo apt-get install python3-pip
sudo pip3 install Jetson.GPIO
sudo groupadd -f -r gpio
sudo usermod -a -G gpio your_user_name
sudo cp /opt/nvidia/jetson-gpio/etc/99-gpio.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules && sudo udevadm trigger

【Note】your_user_name is the username you use, such as waveshare

  • Install I2C
sudo apt-get install python-smbus
  • Install the image processing library:
sudo apt-get install python3-pil
sudo apt-get install python3-numpy

Download Program

sudo apt-get install p7zip
wget https://www.waveshare.com/w/upload/5/53/1.3inch-OLED-HAT-Code.7z
7z x 1.3inch-OLED-HAT-Code.7z
sudo chmod 777 -R  1.3inch-OLED-HAT-Code
cd 1.3inch-OLED-HAT-Code/JetsonNano/

Program Test

Due to the weak GPIO drive capability of Jetson Nano, it can only be controlled using SPI.

  • C
cd C
make clean
make
sudo ./main
  • python
#python2
cd python2
sudo python main.py
sudo python key_demo.py
#python3
cd python3
sudo python3 main.py
sudo python3 key_demo.py

Document

Datasheet

Relate Resources

Software

FAQ

Question:How many volts can an OLED module be used in a system?

 Answer:
The OLED module is used in a 3.3V system by default, but after more than 24 hours of burn-in test, it is found that it can also work normally in a 5V system.


Question:How many hours is the service life of an OLED module?

 Answer:
Under normal working conditions, generally 50,000 hours.


Question:What is the working current of the OLED module?

 Answer:
At the operating voltage of 3.3V:

Working current of 0.95inch RGB OLED: about 38mA for full white display, about 4mA for full black display.
The working current of 0.96inch OLED is about 25mA when fully on, and 1.5mA when fully off.

Working current of 1.3inch OLED: about 29mA when fully on, 1.0mA when fully off.


Question:Why does the OLED module not turn on when it is connected to the power supply?

 Answer:
OLED has no backlight, and the display is self-illuminating. Only connect VCC and GND, the OLED will not light up.
Program control is required to brighten the OLED.


Question:What should I pay attention to when using this OLED module?

 Answer:
1. Be careful not to connect the power supply in reverse.
2. The same picture cannot be displayed for a long time, otherwise it will produce afterimages and cause damage to the OLED.