Template: Raspberry Pi

From Waveshare Wiki
Jump to: navigation, search

Provides C and Python demo

  • Open the Raspberry Pi terminal and enter the following command to enter the configuration interface

Open SPI Interface

sudo raspi-config
chooseInterfacing Options -> SPI -> Yes Open SPI Interface

R01.png

Then reboot Raspberry Pi:

sudo reboot

Please make sure the SPI is not occupied by other devices, you can check in the middle of /boot/config.txt

Open I2C Interface

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

R02.png

Then reboot Raspberry Pi:

sudo reboot

Install Function

BCM2835
#Open the Raspberry Pi terminal and run the following command
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.68.tar.gz
tar zxvf bcm2835-1.68.tar.gz 
cd bcm2835-1.68/
sudo ./configure && sudo make && sudo make check && sudo make install
# More can 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), 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 does not appear, the installation is wrong.
#Bullseye branch system uses 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, the installation is wrong.
python
#Open the Raspberry Pi terminal and run the following command
#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
sudo pip install Adafruit-PureIO
#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
sudo pip3 install Adafruit-PureIO

Download demo

Open the Raspberry Pi terminal and run the following command

sudo apt-get install p7zip-full
wget http://www.waveshare.net/w/upload/c/c5/2.23inch-OLED-HAT-Code.7z
7z x 2.23inch-OLED-HAT-Code.7z 
sudo chmod 777 -R  2.23inch-OLED-HAT-Code
cd 2.23inch-OLED-HAT-Code/
  • Raspberry Pi demo use (the following SPI routine is used as an example)
  • The scroll display is to enable all the pixels in the RAM of SSD1305 (132X64), and display it on the screen (128X32) by scrolling.
  • The scrolling routine provides two scrolling methods, you can only choose one or none of them, set it to '1'.
#define VERTICAL 1 
#define HORIZONTAL 0
Based on the use of BCM2835
#normal display
cd Without scrolling/Raspberry\ Pi/SPI/bcm2835
make clean
make
sudo ./oled
# scroll display
cd Scroll/Raspberry\ Pi/SPI/bcm2835
make clean
make
sudo ./oled
Based on the use of Wiring Pi
#normal display
cd Without scrolling/Raspberry\ Pi/SPI/wiringPi
make clean
make
sudo ./oled
#scroll display
cd Scroll/Raspberry\ Pi/SPI/wiringPi
make clean
make
sudo ./oled
Based on the use of Python
#normal display
cd Without scrolling/Raspberry\ Pi/SPI/python
sudo python3 stats.py
sudo ./oled
#scroll display
cd Scroll/Raspberry\ Pi/SPI/python
sudo python3 stats.py
Precautions for Routine Use

The WiringPi and Python demo operate by reading and writing the device files of the linux system, while the BCM2835 is a library function of the Raspberry Pi cpu chip, which operates on registers. Therefore, if the BCM2835 library is used first, the WiringPi and Python demo will fail to use, in this case, you need to restart the system and run it again.