0
0
Iot-protocolsHow-ToBeginner · 3 min read

How to Enable I2C on Raspberry Pi: Step-by-Step Guide

To enable I2C on Raspberry Pi, run sudo raspi-config, navigate to Interfacing Options, then select I2C and enable it. After rebooting, verify with ls /dev/i2c-* to confirm the interface is active.
📐

Syntax

The main command to enable I2C on Raspberry Pi is sudo raspi-config. This opens a configuration tool where you can enable interfaces.

  • sudo: runs the command as an administrator.
  • raspi-config: Raspberry Pi configuration tool.
  • Inside the tool, Interfacing Options is where hardware interfaces like I2C are managed.
  • Select I2C and choose Yes to enable it.

After enabling, reboot the Pi with sudo reboot to apply changes.

bash
sudo raspi-config
💻

Example

This example shows how to enable I2C, reboot, and check if the I2C device files exist.

bash
sudo raspi-config
# Navigate: Interfacing Options -> I2C -> Yes
sudo reboot

# After reboot, check I2C devices
ls /dev/i2c-*
Output
/dev/i2c-1
⚠️

Common Pitfalls

Common mistakes when enabling I2C on Raspberry Pi include:

  • Not rebooting after enabling I2C, so changes don't take effect.
  • Trying to use I2C without enabling it first in raspi-config.
  • Using wrong device file names; usually, the I2C bus is /dev/i2c-1 on modern Raspberry Pis.
  • Not installing necessary I2C tools like i2c-tools to test the bus.

To install tools, run sudo apt-get install -y i2c-tools.

bash
sudo apt-get install -y i2c-tools
sudo raspi-config
# Enable I2C
sudo reboot

# Check I2C devices
ls /dev/i2c-*
Output
/dev/i2c-1
📊

Quick Reference

StepCommand / ActionDescription
1sudo raspi-configOpen Raspberry Pi configuration tool
2Navigate to Interfacing Options > I2CSelect I2C interface to enable
3Enable I2CChoose Yes to enable the interface
4sudo rebootRestart Raspberry Pi to apply changes
5ls /dev/i2c-*Verify I2C device files exist
6sudo apt-get install -y i2c-toolsInstall tools to test I2C bus (optional)

Key Takeaways

Use sudo raspi-config to enable I2C under Interfacing Options.
Always reboot the Raspberry Pi after enabling I2C to apply changes.
Check for /dev/i2c-1 to confirm I2C is active.
Install i2c-tools to test and interact with I2C devices.
Avoid skipping the enable step or reboot, or I2C won't work.