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

image-20231031163337469

Install I2C tool, and input the terminal as follows:

Check the installation status, terminal input:

The following output indicates successful installation:

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

img

Smbus is a Python library. If smbus is not installed, the terminal input is:

The Smbus protocol has many related library functions that can be used for I2C communication.

img

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

image-20231031163440104

Import Adafruit_ SSD1306 library This is the OLED library, and you need to download this library when using your own image

img

Initialize OLED:

img

Input following command:

Experimental phenomenon:

image-20231031163817000