Enable I2C interface

Using "Raspberry Pi Configuration" on Raspberry Pi OS (Raspbian)

Click on the main menu, select “Preferences” and then “Raspberry Pi Configuration”.

Now select the tab “Interface” and then and set I2C to “Enabled”.

Finally restart the Raspberry Pi.

Raspberry Pi configuration
Raspberry Pi - Enable 12C

Enable I2C interface

Using "raspi-config" on Raspberry Pi OS (Raspbian)

Type from Terminal the command to launch the raspi-config utility:
sudo raspi-config

Select “Interfacing Options”, now select “I2C”.

To the question “Would you like the ARM I2C interface to be enabled?” answer with “Yes”.

Finally reboot your Raspberry Pi.

Enable I2C interface

Manually

Install the i2c-tools package:
sudo apt-get update
sudo apt-get install i2c-tools

I2c tools

Remove the driver from the blacklist:
sudo nano /etc/modprobe.d/raspi-blacklist.conf

If the file contains blacklist i2c-bcm2708 comment the line with a # :
#blacklist i2c-bcm2708

If the above file is blank or doesn’t exist, then skip the above step

Edit the modules file:
sudo nano /etc/modules

and add these 2 lines:
i2c-dev
i2c-bcm2708

Edit the /boot/config.txt file:
sudo nano /boot/config.txt
(Some distributions may use the /boot/firmware/config.txt)

and add these 2 lines:
dtparam=i2c_arm=on
dtparam=i2c1=on

 

Finally reboot the Raspberry Pi

See all the connected devices

You can type the following command to see all the connected devices:
sudo i2cdetect -y 1

 

If you are using an older Raspberry Pi you will need to use the command:
sudo i2cdetect -y 0

Raspberry Pi - I2C detect