Bird
0
0

Given this Python code snippet using spidev on Raspberry Pi:

medium📝 Predict Output Q4 of 15
Raspberry Pi - SPI Communication
Given this Python code snippet using spidev on Raspberry Pi:
import spidev
spi = spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz = 1000000
response = spi.xfer2([0xAA, 0xBB])
print(response)

What will be the output format of the print statement?
AAn error because xfer2 returns None
BA string showing hexadecimal values
CA single integer representing combined bytes
DA list of integers representing received bytes
Step-by-Step Solution
Solution:
  1. Step 1: Understand spidev xfer2 method

    xfer2 sends a list of bytes and returns a list of bytes received from the SPI device.
  2. Step 2: Analyze the print output

    Printing the response will show a list of integers representing each received byte.
  3. Final Answer:

    A list of integers representing received bytes -> Option D
  4. Quick Check:

    spidev.xfer2 output = C [OK]
Quick Trick: xfer2 returns list of received bytes [OK]
Common Mistakes:
MISTAKES
  • Expecting a string output
  • Assuming xfer2 returns None
  • Thinking output is a single integer

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes