Note: This course requires the use of a 0.91-inch OLED display screen and DuPont cable as materials. Please provide them in advance
The I2C pin of Raspberry Pi is shown in the figure, and the I2C service needs to be enabled before use.
Install I2C tool, and input the terminal as follows:
sudo apt-get update
sudo apt-get install -y i2c-tools
Check the installation status, terminal input:
xxxxxxxxxx
apt-cache policy i2c-tools
The following output indicates successful installation:
xi2c-tools:
Installed: 4.0-2
Candidate: 4.0-2
Version List:
*** 4.0-2 500
500 http://ports.ubuntu.com/ubuntu-ports bionic/universe arm64 Packages
100 /var/lib/dpkg/status
Scan all i2c devices on a certain bus and print out the device i2c bus address.
For example, if a device with address 0x0f is mounted on the I2C pin here, the corresponding device I2C address will be displayed
xxxxxxxxxx
sudo i2cdetect -y -r -a 1
Smbus is a Python library. If smbus is not installed, the terminal input is:
xxxxxxxxxx
sudo apt-get update
sudo apt-get install -y python3-smbus
The Smbus protocol has many related library functions that can be used for I2C communication.
Wiring: Raspberry Pi Pin 3 (SDA) → OLED Module SDA Raspberry Pi Pin 5 (SCL) → OLED Module SCL Raspberry Pi Pin 4 (5V) → OLED Module VCC Raspberry Pi Pin 6 (GND) → OLED Module GND
Import Adafruit_ SSD1306 library This is the OLED library, and you need to download this library when using your own image
xxxxxxxxxx
pip3 install Adafruit_SSD1306
Initialize OLED:
Input following command:
xxxxxxxxxx
sudo python3 yahboom_oled.py
Experimental phenomenon: