Leon Anavi
IT Tips && Tricks

Mobile & Embedded

Created: 09.10.2025 06:30 Last Modified: 09.10.2025 06:33 Views: 7
Keywords: , I2C, OpenEmbedded, RaspberryPi, Yocto

The Yocto Project on Raspberry Pi 5 Episode 9: I2C and SSD1306 OLED Display

I2C (Inter-Integrated Circuit) is a simple yet powerful serial communication protocol developed by Philips Semiconductor (now NXP) in the early 1980s. It uses only two wires, SDA (data) and SCL (clock), to connect multiple master and slave devices on a single bus, each with its own address. This compact design makes I2C ideal for embedded systems where space and pins are limited. Today, it is one of the most widely used communication interfaces for connecting sensors, real-time clocks, EEPROMs, and display modules in Internet of Things (IoT) and embedded Linux devices.

In this video tutorial, we will go step-by-step through enabling I2C on a Raspberry Pi in your Yocto-built Linux image, autoloading the required kernel modules, and using an SSD1306 mini OLED display via I2C.

The Hardware: Raspberry Pi 5 and ANAVI Info uHAT

This demo is built around the Raspberry Pi 5, the latest and most powerful board in the Raspberry Pi lineup. It features a quad-core ARM CPU, PCIe expansion, dual 4K display outputs, and most importantly for this project, full support for hardware interfaces such as I2C, SPI, and UART through its GPIO header.

To demonstrate I2C communication, we are using ANAVI Info uHAT, a low-cost, open-source hardware Raspberry Pi add-on board designed for monitoring and displaying data. It includes:

  • A 0.96-inch yellow-blue I?C OLED display (based on the SSD1306 controller) with a resolution of 128x64 pixels
  • Three user buttons
  • Red and green indicator LEDs
  • Slots for connecting various sensors (temperature, light, humidity, and others)

Each ANAVI Info uHAT kit includes the mini OLED display, which connects via I2C and serves as an ideal example for displaying messages and sensor data on your Yocto-based Linux system.

Step 1: Enable I2C in Yocto

To enable the I2C interface and ensure that the related kernel modules load automatically, edit your build configuration file:

conf/local.conf

Then add the following lines:

ENABLE_I2C = "1"
KERNEL_MODULE_AUTOLOAD:rpi += "i2c-dev i2c-bcm2708"

This configuration does two things:

  • ENABLE_I2C = "1" activates I2C support in the image.
  • KERNEL_MODULE_AUTOLOAD:rpi ensures that the i2c-dev (I2C user-space interface) and i2c-bcm2708 (Raspberry Pi I2C bus driver) modules load automatically at boot.

Step 2: Add I2C Tools and SSD1306 Application

Next, include the necessary packages to scan for I2C devices and to control the SSD1306 OLED display. Add this line to your local.conf file:

IMAGE_INSTALL:append = " i2c-tools ssd1306"

Here is what these packages do:

  • i2c-tools provides utilities such as i2cdetect and i2cget to scan and debug I2C devices.
  • ssd1306 is an open-source command-line application that can display text and graphics on OLED screens based on the SSD1306 controller.

Step 3: Build Your Image

Now, rebuild your Yocto image using:

bitbake core-image-minimal

(or your custom image recipe, for example bitbake my-image)

Once the build is complete, flash the image to your Raspberry Pi SD card and boot it up.

Step 4: Verify I2C Devices

After booting, check whether your Raspberry Pi recognizes the I2C devices:

i2cdetect -y 1

You should see your SSD1306 display appear at its I2C address (commonly 0x3C or 0x3D).

Step 5: Test the SSD1306 Display

Now, use the ssd1306_bin tool to initialize and display text on your OLED display. Run the following commands:

ssd1306_bin -n 1 -I 128x64        # Initialize 128x64 display on I2C bus 1
ssd1306_bin -n 1 -c               # Clear the screen
ssd1306_bin -n 1 -r 0             # Reset display
ssd1306_bin -n 1 -x 1 -y 1
ssd1306_bin -n 1 -l "Hello World"
ssd1306_bin -n 1 -x 1 -y 2
ssd1306_bin -n 1 -l "The Yocto Project"
ssd1306_bin -n 1 -x 1 -y 3
ssd1306_bin -n 1 -l "on Raspberry Pi 5"

Your OLED display should now show the following text:

Hello World
The Yocto Project
on Raspberry Pi 5

Wrapping Up

You have successfully enabled I2C on a Yocto-built Raspberry Pi image and displayed text on an SSD1306 OLED display using the ANAVI Info uHAT.

This workflow demonstrates how straightforward it is to integrate hardware peripherals into a fully customized Linux distribution built with the Yocto Project. From here, you can expand the setup to include additional I2C-based sensors, displays, and IoT modules, unlocking the full potential of embedded Linux on the Raspberry Pi.

Related Videos

Useful Links



  Home | About | Contact | Disclaimer | Sitemap © 2009-2022 Leon Anavi. All rights reserved.