Raspberry Pi I2c Interfacing and Programming

I2C is a multi-device bus used to connect low-speed peripherals to computers and embedded systems. The Raspberry Pi supports this interface on its GPIO header and it is a great way to connect sensors and devices. Once configured you can connect more than one device without using up additional pins on the header.

Before using I2C it needs to be configured. This technique has changed slightly with the latest version of Raspbian so I’ve updated this article.Enabling The I2C Interface On The Raspberry Pi.jpg

Step 1 – Enable i2c using raspi-config utility

From the command line type :

sudo raspi-config

This will launch the raspi-config utility.

Now complete the following steps :

  • Select “8 Advanced Options”
  • Select “A7 I2C”
  • Select “Yes”

The screen will ask if you want the interface to be enabled :

  • Select “Yes”
  • Select “Ok”

The screen will ask if you want the module to be loaded by default :

  • Select “Yes”

The screen will state the module will be loaded by default :

  • Select “Ok”
  • Select “Finish” to return to the command line

When you next reboot the I2C module will be loaded.

Step 2 – Manually Edit Module File

Next we need to edit the modules file using :

sudo nano /etc/modules

and add the following two lines :


Use CTRL-X, then Y, then RETURN to save the file and exit.

Step 3 – Install Utilities

To help debugging and allow the i2c interface to be used within Python we can install “python-smbus” and “i2c-tools” :

sudo apt-get update
sudo apt-get install -y python-smbus i2c-tools

Enabling The I2C Interface On The Raspberry Pi schematic.jpg

Step 4 – Shutdown

Shutdown your Pi using :

sudo halt

Wait ten seconds, disconnect the power to your Pi and you are now ready to connect your I2C hardware.

Checking If I2C Is Enabled (Optional)

When you power up or reboot your Pi you can check the i2c module is running by using the following command:


For more detail: Raspberry Pi I2c Interfacing and Programming

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top