Template: 1.3inch OLED HAT rpi

From Waveshare Wiki
Jump to: navigation, search

Raspberry Pi

Enable SPI interface

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

RPI open spi.png
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.

Raspberry Pi Guides for 4.37 e-Paper.jpg
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.
Raspberry Pi Guides for 4.37 e-Paper02.jpg

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

1.3inch OLED HAT rpi.png
and the reboot RPi.

sudo reboot

Install Library

If you use the bookworm system, you can only use lgpio library, bcm2835 and wiringPi can't be installed and used.

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, you can refer to the official website at: http://www.airspayce.com/mikem/bcm2835/

WiringPi

#Open the Raspberry Pi terminal and run the following command
cd
sudo apt-get install wiringpi
#For Raspberry Pi systems after May 2019 (earlier than that can be executed without), an upgrade may be required:
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 doesn't it means there was an installation error

# Bullseye branch system using the following command:
git clone https://github.com/WiringPi/WiringPi
cd WiringPi
. /build
gpio -v
# Run gpio -v and version 2.70 will appear, if it doesn't it means there was an installation error

lgpio

#Open the Raspberry Pi terminal and run the following command
wget https://github.com/joan2937/lg/archive/master.zip
unzip master.zip
cd lg-master
sudo make install

# You can refer to the official website for more: https://github.com/gpiozero/lg

Python

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 spidev

Download Example

Run in the terminal of RPi:

sudo apt-get install p7zip-full
wget https://files.waveshare.com/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 is 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.