Bird
0
0

Find the mistake in this Raspberry Pi I2C setup code:

medium📝 Debug Q7 of 15
Raspberry Pi - I2C Communication
Find the mistake in this Raspberry Pi I2C setup code:
import smbus
bus = smbus.SMBus(0)
address = 0x40
bus.write_byte(address, 100)
Awrite_byte() requires two addresses
BSMBus(0) should be SMBus(1) on newer Raspberry Pi models
CAddress 0x40 is invalid for I2C devices
DMissing import for GPIO
Step-by-Step Solution
Solution:
  1. Step 1: Check bus number for Raspberry Pi

    Newer Raspberry Pi models use bus 1, not 0.
  2. Step 2: Confirm correct bus usage

    Using SMBus(0) may cause communication failure.
  3. Final Answer:

    SMBus(0) should be SMBus(1) on newer Raspberry Pi models -> Option B
  4. Quick Check:

    Use SMBus(1) on modern Pi [OK]
Quick Trick: Use SMBus(1) for I2C on Raspberry Pi 3 and later [OK]
Common Mistakes:
MISTAKES
  • Using SMBus(0) on new Pi
  • Wrong device address
  • Confusing GPIO with I2C imports

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes