Template: 1.3inch OLED HAT rpi

From Waveshare Wiki
Jump to: navigation, search

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

RPI open spi.png
Reboot Raspberry Pi:

sudo reboot

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

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 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
7z 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