How to Detect I2C Devices on Raspberry Pi Quickly
To detect
I2C devices on a Raspberry Pi, first enable the I2C interface using raspi-config. Then run sudo i2cdetect -y 1 in the terminal to scan and list connected devices on the I2C bus.Syntax
The main command to detect I2C devices is i2cdetect. The syntax is:
sudo i2cdetect -y <bus_number>
Here:
sudoruns the command with administrator rights needed to access hardware.i2cdetectis the tool that scans the I2C bus.-ydisables interactive mode, so it runs without asking for confirmation.<bus_number>is the I2C bus number, usually1on Raspberry Pi models newer than revision 1.
bash
sudo i2cdetect -y 1Example
This example shows how to scan the I2C bus 1 on Raspberry Pi to find connected devices. It prints a grid with detected device addresses.
bash
sudo i2cdetect -y 1Output
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
Common Pitfalls
Common mistakes when detecting I2C devices include:
- Not enabling the I2C interface in Raspberry Pi settings before scanning.
- Using the wrong bus number; most Raspberry Pi models use bus 1, but older ones may use bus 0.
- Running
i2cdetectwithoutsudo, which causes permission errors. - Not connecting devices properly or using wrong pull-up resistors, so devices don't show up.
bash
Wrong (no sudo): i2cdetect -y 1 Right (with sudo): sudo i2cdetect -y 1
Quick Reference
- Enable I2C:
sudo raspi-config> Interface Options > I2C > Enable - Scan I2C bus 1:
sudo i2cdetect -y 1 - Check connected device addresses in the output grid
- Use bus 0 if your Pi is very old (before revision 2)
Key Takeaways
Always enable the I2C interface on Raspberry Pi before scanning devices.
Use
sudo i2cdetect -y 1 to scan the common I2C bus 1 safely and quickly.Check device addresses in the output grid to confirm connected I2C devices.
Use the correct bus number; most modern Raspberry Pis use bus 1.
Run commands with
sudo to avoid permission errors.