Bird
0
0

You wrote this code to read from an I2C sensor on Raspberry Pi:

medium📝 Debug Q14 of 15
Raspberry Pi - I2C Communication
You wrote this code to read from an I2C sensor on Raspberry Pi:
import smbus
bus = smbus.SMBus(1)
address = 0x40
value = bus.read_byte(0x40)
print(value)
But it raises an IOError. What is the likely problem?
AThe code should use <code>write_byte</code> instead of <code>read_byte</code>.
BThe sensor is not connected or powered properly at address 0x40.
CSMBus(1) is incorrect; it should be SMBus(0).
DThe address 0x40 is invalid for I2C devices.
Step-by-Step Solution
Solution:
  1. Step 1: Understand IOError cause

    IOError usually means no device responds at the given address.
  2. Step 2: Check device connection

    If sensor is not connected or powered, Raspberry Pi can't read data, causing error.
  3. Final Answer:

    The sensor is not connected or powered properly at address 0x40. -> Option B
  4. Quick Check:

    IOError = device missing or unpowered [OK]
Quick Trick: IOError means device not found or powered [OK]
Common Mistakes:
MISTAKES
  • Changing SMBus number unnecessarily
  • Confusing read_byte with write_byte
  • Assuming address 0x40 is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes