Title

Autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et dolore feugait

How to activate Raspberry-pi’s i2c bus

I recently completed the Proof of Concept for a client project using embedded Linux. In this context, I used the I2C bus of my new Raspberry-Pi 4. Unfortunately the i2c bus was not functional by default. Here is how to activate it and use it with Buildroot, the procedure is very similar under Raspbian :

Raspberry Pi i2c
A Raspberry-Pi 4 with a device connected on the i2c-1 bus

Configuring the firmware of the Raspberry-Pi 4 to enable the i2c bus

By default all non-essential buses (i2c, SPI, etc) are disabled on the Raspberry-Pi. You must first configure your firmware to enable the i2c-1 bus via the config.txt file.

This file is present on the boot partition of the SD card, but the most efficient way is to activate it directly in the rpi-firmware package in buildroot. To do this, edit the file package/rpi-firmware/config.txt from the buildroot source folder and add this line to it.

dtparam=i2c1=on

On Raspbian, you will find this file directly in /boot/config.txt. You can simply make the change, reboot and go to the next step.

The config.txt file is the equivalent of the BIOS on a PC. It allows you to configure the system.

Now you need to recompile the rpi-firmware package:

make rpi-firmware-rebuild

Then, you need to regenerate your Raspberry-pi’s micro-sd card image:

make

Now you can (re)flash the firmware on the map and start the Raspberry-pi 4

Manually add missing modules for the i2c bus

The Processor of the Raspberry-Pi 4 is a Broadcom 2711, it reuses a number of modules that were already present in older versions of the SoC (System on Chip, multifunction processor), including the bcm2835. For this reason you can load the following modules. By default the necessary modules are present on the system, so you just have to start them manually:

modprobe i2c-bcm2835
modprobe i2c-dev
[   37.740438] i2c /dev entries driver

Now you should find the i2c-1 bus in /dev:

 ls -la /dev/i2c-1 
crw-------    1 root     root       89,   1 Jan 18 15:19 /dev/i2c-1

The i2c-1 bus is now usable, it has the necessary functions to use your I2C peripherals, but also for SMBus (the ancestor of i2C):

# i2cdetect -F 1
Functionalities implemented by bus #1
I2C                              yes
SMBus quick command              yes
SMBus send byte                  yes
SMBus receive byte               yes
SMBus write byte                 yes
SMBus read byte                  yes
SMBus write word                 yes
SMBus read word                  yes
SMBus process call               yes
SMBus block write                yes
SMBus block read                 no
SMBus block process call         no
SMBus PEC                        yes
I2C block write                  yes
I2C block read                   yes
Julien Grossholtz

As an expert in embedded software, I assist companies in the creation of their smart devices and IoTs.

3 comments so far

Use the MPU6050 accelerometer on Raspberry-Pi – OpenestPosted on 3:43 pm - Jan 21, 2020

[…] Make sure that /dev/i2c-1 exists on your Raspberrry-Pi. If not, check our article on the i2c bus of the Raspberry-Pi. […]

JohanPosted on 11:43 am - Apr 17, 2020

Thank you for this article. I was using dtparam=i2c_arm=on in the config file, which prevented the bus from showing up. It works now!

Leave a Reply