Bird
Raised Fist0
Raspberry Piprogramming~10 mins

i2cdetect for device scanning in Raspberry Pi - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - i2cdetect for device scanning
Start i2cdetect command
↓
Scan I2C bus addresses 0x03 to 0x77
↓
Send probe to each address
↓
Check for device response
↓
Mark address
↓
Display full address map
↓
End
The i2cdetect command scans all possible I2C addresses on the bus, probing each one to see if a device responds, then shows a map of detected devices.
Execution Sample
Raspberry Pi
sudo i2cdetect -y 1
This command scans the I2C bus number 1 and shows which addresses have devices connected.
Execution Table
StepAddress ProbedDevice ResponseMark on Map
10x03No--
20x04No--
30x05No--
40x20Yes20
50x21No--
60x3CYes3c
70x40No--
80x77No--
9All addresses scannedScan completeMap displayed
💡 All addresses from 0x03 to 0x77 scanned; devices found at 0x20 and 0x3C; scan ends.
Variable Tracker
VariableStartAfter Step 4After Step 6Final
Detected Devices[][0x20][0x20, 0x3C][0x20, 0x3C]
Key Moments - 3 Insights
Why do some addresses show '--' instead of a number?
Addresses marked '--' mean no device responded at that address during the scan, as shown in execution_table rows 1-3 and 5,7,8.
Why does the scan start at address 0x03 and not 0x00?
Addresses below 0x03 are reserved or not valid for devices, so i2cdetect skips them, as seen in the concept_flow scanning range.
What does the 'Yes' response mean during probing?
'Yes' means a device acknowledged the probe at that address, so it is marked on the map, like at 0x20 and 0x3C in execution_table steps 4 and 6.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the device response at address 0x21?
AYes
BError
CNo
DNot scanned
💡 Hint
Check execution_table row 5 for address 0x21 response.
At which step does the first device get detected?
AStep 2
BStep 4
CStep 6
DStep 8
💡 Hint
Look at execution_table rows 1-6 and find the first 'Yes' response.
If a device was connected at address 0x40, how would the map mark it?
AIt would show '40'
BIt would show '--'
CIt would show 'xx'
DIt would be skipped
💡 Hint
Devices that respond are marked by their hex address, as in execution_table step 4 and 6.
Concept Snapshot
i2cdetect scans I2C bus addresses from 0x03 to 0x77.
It sends a probe to each address.
If a device responds, the address is shown.
Addresses with no response show '--'.
Use 'sudo i2cdetect -y <bus>' to scan.
Detected devices help confirm hardware connections.
Full Transcript
The i2cdetect command is used on Raspberry Pi to scan the I2C bus for connected devices. It checks addresses from 0x03 to 0x77 by sending a probe to each. If a device responds, its address is shown in the output map; otherwise, '--' is shown. This helps users find which devices are connected and at what addresses. The scan ends after all addresses are checked. For example, running 'sudo i2cdetect -y 1' scans bus 1 and lists detected devices. Addresses below 0x03 are skipped because they are reserved. The output map is a grid showing addresses with devices or empty spots. This tool is essential for troubleshooting I2C connections on Raspberry Pi.

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

  1. Step 1: Understand the function of i2cdetect

    The i2cdetect command scans the I2C bus to find devices connected to it.
  2. 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.
  3. Final Answer:

    To scan the I2C bus and list connected devices -> Option B
  4. 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

  1. 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.
  2. Step 2: Check other options for errors

    Options A, B, and C use incorrect flags or order, making them invalid.
  3. Final Answer:

    sudo i2cdetect -y 1 -> Option C
  4. 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:
     00: -- -- -- -- -- -- -- -- 
     10: -- -- -- -- -- -- -- -- 
     20: -- -- -- -- -- -- -- -- 
     30: -- -- -- -- -- -- -- -- 
     40: -- -- -- -- -- -- -- -- 
     50: -- -- -- -- -- -- -- -- 
     60: -- -- -- -- -- -- -- -- 
     70: 70 -- -- -- -- -- -- -- 

What does the address 0x70 in the output indicate?
medium
A. The command failed to run
B. No device is connected at address 0x70
C. The I2C bus is disabled
D. An I2C device is detected at address 0x70

Solution

  1. Step 1: Interpret i2cdetect output

    Addresses with numbers (like 70) show detected devices; dashes mean no device.
  2. Step 2: Analyze the given output

    Only address 0x70 shows a number, so a device is present there.
  3. Final Answer:

    An I2C device is detected at address 0x70 -> Option D
  4. Quick Check:

    Number in table = device present [OK]
Hint: Numbers show devices; dashes mean no device [OK]
Common Mistakes:
  • Thinking dashes mean devices
  • Assuming output means error
  • Confusing address with bus number
4. You run i2cdetect -y 1 without sudo and get a permission error. How do you fix this?
medium
A. Run the command with sudo as sudo i2cdetect -y 1
B. Add --force flag to bypass permissions
C. Change the bus number to 0
D. Restart the Raspberry Pi

Solution

  1. Step 1: Understand permission requirements

    Accessing I2C bus requires root privileges, so sudo is needed.
  2. Step 2: Apply correct fix

    Running sudo i2cdetect -y 1 grants permission and avoids error.
  3. Final Answer:

    Run the command with sudo as sudo i2cdetect -y 1 -> Option A
  4. Quick Check:

    Use sudo for I2C commands = C [OK]
Hint: Always use sudo with i2cdetect to avoid permission errors [OK]
Common Mistakes:
  • Trying to bypass permissions with wrong flags
  • Changing bus number unnecessarily
  • Restarting without fixing permissions
5. You want to scan I2C devices on bus 0 and bus 1, but sudo i2cdetect -y 0 shows no devices, while bus 1 shows several. What is the best explanation?
hard
A. Bus 0 is usually reserved or unused on most Raspberry Pi models
B. Bus 0 devices are hidden and require a special flag
C. Bus 1 is disabled by default and must be enabled manually
D. The i2cdetect command only works on bus 1

Solution

  1. Step 1: Know Raspberry Pi I2C bus defaults

    Most Raspberry Pi models use bus 1 for I2C; bus 0 is often reserved or inactive.
  2. Step 2: Analyze scan results

    Devices appear on bus 1 but not on bus 0, confirming bus 0 is unused.
  3. Final Answer:

    Bus 0 is usually reserved or unused on most Raspberry Pi models -> Option A
  4. Quick Check:

    Bus 0 unused, bus 1 active = A [OK]
Hint: Bus 1 is main I2C bus; bus 0 often unused [OK]
Common Mistakes:
  • Thinking bus 0 devices are hidden
  • Assuming i2cdetect only works on bus 1
  • Believing bus 1 is disabled by default
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard