Welcome to Muto RS Robot repository
9)I2C communication
I2C communication
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 updatesudo apt-get install -y i2c-tools
Check the installation status, terminal input:
xxxxxxxxxxapt-cache policy i2c-tools
The following output indicates successful installation:
xxxxxxxxxxi2c-tools:Installed: 4.0-2Candidate: 4.0-2Version List:*** 4.0-2 500500 http://ports.ubuntu.com/ubuntu-ports bionic/universe arm64 Packages100 /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
xxxxxxxxxxsudo i2cdetect -y -r -a 1

Smbus is a Python library. If smbus is not installed, the terminal input is:
xxxxxxxxxxsudo apt-get updatesudo 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
xxxxxxxxxxpip3 install Adafruit_SSD1306

Initialize OLED:

Input following command:
xxxxxxxxxxsudo python3 yahboom_oled.py
Experimental phenomenon:
