Bird
0
0

What will be the output of this code snippet?

medium📝 Predict Output Q5 of 15
Raspberry Pi - I2C Communication
What will be the output of this code snippet?
from smbus2 import SMBus
with SMBus(1) as bus:
    bus.write_byte_data(0x30, 0x05, 0xFF)
    result = bus.read_byte_data(0x30, 0x05)
    print(result)

Assuming the device echoes back the written byte.
A5
B0xFF
C255
DError: Write failed
Step-by-Step Solution
Solution:
  1. Step 1: Write byte 0xFF to register 0x05

    The code writes the byte 0xFF (decimal 255) to the device register.
  2. Step 2: Read back the byte from the same register

    The device echoes back 0xFF, which is 255 in decimal, printed as integer.
  3. Final Answer:

    255 -> Option C
  4. Quick Check:

    Write then read byte returns decimal 255 [OK]
Quick Trick: Hex 0xFF equals decimal 255 when printed as int [OK]
Common Mistakes:
MISTAKES
  • Expecting hex string output instead of int
  • Confusing register address with data
  • Assuming write_byte_data returns a value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes