Bird
0
0

Which Python code snippet correctly initializes the I2C bus to read sensor data on Raspberry Pi?

easy📝 Syntax Q3 of 15
Raspberry Pi - I2C Communication
Which Python code snippet correctly initializes the I2C bus to read sensor data on Raspberry Pi?
Aimport i2c bus = i2c.Bus(0)
Bimport smbus bus = smbus.SMBus(1)
Cimport gpio bus = gpio.I2C(1)
Dimport smbus bus = smbus.SMBus(0)
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct Python library and bus number

    Python uses smbus library and bus 1 for Raspberry Pi's I2C.
  2. Step 2: Check code syntax and initialization

    import smbus and bus = smbus.SMBus(1) is correct syntax.
  3. Final Answer:

    import smbus\nbus = smbus.SMBus(1) -> Option B
  4. Quick Check:

    Correct library and bus number = import smbus bus = smbus.SMBus(1) [OK]
Quick Trick: Use smbus.SMBus(1) to access I2C bus on Raspberry Pi [OK]
Common Mistakes:
MISTAKES
  • Using wrong bus number 0
  • Importing non-existent i2c module
  • Wrong class or method names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes