The I2C bus is not enabled in all Raspberry Pi images; therefore, we need to enable the module and install some supporting tools. Newer versions of Raspbian use device trees to handle hardware peripherals and drivers.
In order to make use of the I2C bus, we need to enable the ARM I2C in the bootconfig.txt file.
You can do this automatically using the following command:
sudo raspi-config
Select Advanced Options from the menu and then select I2C, as shown in the following screenshot. When asked, select Yes to enable the interface and then click Yes to load the module by default:
From the menu, select I2C