📖 Scenario: You have a Raspberry Pi connected to several I2C devices like sensors or displays. You want to find out which devices are connected and at what addresses.This is useful when setting up hardware projects to confirm your devices are detected correctly.
🎯 Goal: Learn how to use the i2cdetect command to scan the I2C bus on your Raspberry Pi and list all connected devices.
📋 What You'll Learn
A Raspberry Pi with I2C enabled
I2C devices optionally connected to the Pi
Basic terminal access to the Raspberry Pi
💡 Why This Matters
🌍 Real World
I2C device scanning helps verify hardware connections in projects like sensors, displays, and other peripherals connected to Raspberry Pi.
💼 Career
Understanding how to detect and troubleshoot I2C devices is useful for embedded systems engineers, hardware developers, and IoT professionals.
Progress0 / 4 steps
1
Enable I2C Interface
Run the command sudo raspi-config to open the Raspberry Pi configuration tool. Navigate to Interfacing Options and enable I2C. Then reboot your Raspberry Pi with sudo reboot.
Raspberry Pi
Hint
Use sudo raspi-config to enable I2C under Interfacing Options, then reboot.
2
Install i2c-tools Package
Install the i2c-tools package by running sudo apt-get install -y i2c-tools. This package contains the i2cdetect command.
Raspberry Pi
Hint
Use sudo apt-get install -y i2c-tools to install the tools.
3
Scan I2C Bus for Devices
Run the command sudo i2cdetect -y 1 to scan the I2C bus number 1 and list all connected devices with their addresses.
Raspberry Pi
Hint
Use sudo i2cdetect -y 1 to scan the I2C bus 1.
4
View and Interpret Scan Output
Look at the output of sudo i2cdetect -y 1. The grid shows addresses. Numbers indicate detected devices at those addresses. Print the command sudo i2cdetect -y 1 to display the scan result.
Raspberry Pi
Hint
Run sudo i2cdetect -y 1 again to see the detected device addresses.
Practice
(1/5)
1. What is the main purpose of the i2cdetect command on a Raspberry Pi?
easy
A. To update the Raspberry Pi operating system
B. To scan the I2C bus and list connected devices
C. To check the Wi-Fi signal strength
D. To format the SD card
Solution
Step 1: Understand the function of i2cdetect
The i2cdetect command scans the I2C bus to find devices connected to it.
Step 2: Compare with other options
Options A, C, and D relate to system update, Wi-Fi, and storage, which are unrelated to I2C scanning.
Final Answer:
To scan the I2C bus and list connected devices -> Option B
Quick Check:
i2cdetect scans I2C devices = B [OK]
Hint: Remember: i2cdetect scans I2C devices only [OK]
Common Mistakes:
Confusing i2cdetect with system update commands
Thinking it checks Wi-Fi or storage
Assuming it formats devices
2. Which of the following is the correct syntax to scan I2C devices on bus 1 using i2cdetect?
easy
A. i2cdetect --bus 1
B. i2cdetect -scan 1
C. sudo i2cdetect -y 1
D. sudo i2cdetect 1 -y
Solution
Step 1: Recall the correct command format
The correct syntax is sudo i2cdetect -y 1 where -y disables interactive confirmation and 1 is the bus number.
Step 2: Check other options for errors
Options A, B, and C use incorrect flags or order, making them invalid.
Final Answer:
sudo i2cdetect -y 1 -> Option C
Quick Check:
Correct syntax = sudo i2cdetect -y 1 [OK]
Hint: Use sudo i2cdetect -y followed by bus number [OK]
Common Mistakes:
Switching flag order or using wrong flags
Omitting sudo causing permission errors
Using non-existent flags like --bus
3. After running sudo i2cdetect -y 1, you see the following output snippet: