Skip to content
systemcoding.dev
Embedded Linux

Enable I2C on Raspberry Pi in Yocto with ENABLE_I2C

Turn on the Raspberry Pi I2C bus in a Yocto Scarthgap image with ENABLE_I2C in local.conf, which writes the dtparam line for you.

1 min read
Summarize in AI

The Raspberry Pi firmware leaves I2C off until config.txt asks for it. With meta-raspberrypi you do not edit that file, you set a variable and the recipe writes the line.

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

Put both lines in conf/local.conf of a Yocto 5.0 (Scarthgap) build. ENABLE_I2C adds dtparam=i2c_arm=on to the generated config.txt, and the second line loads i2c-dev, which creates the /dev/i2c-* nodes that i2cdetect uses. Without it the bus exists but has no character device.

Shell
grep i2c /boot/config.txt
ls /dev/i2c-*
Text
dtparam=i2c_arm=on
/dev/i2c-1

The bus number is 1 on the 40-pin header of recent boards. The variable name is documented in the meta-raspberrypi layer docs. It only edits config.txt, so a change of kernel configuration or overlay is still separate. Also install i2c-tools to get i2cdetect, which is not in a minimal image.

Also inHardware
Share

More snippets

Kernels

Get a GPIO descriptor with devm_gpiod_get

devm_gpiod_get() looks up a named GPIO from the device tree, sets its direction and initial level, and releases it on unbind; use it instead of gpio numbers.

1 min read
Embedded Linux

Choose the hardware target with MIX_TARGET

Set MIX_TARGET to a Nerves target such as rpi4 before running mix commands, so dependencies and the firmware are built for the board and not the host.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.