Bird
0
0

What will be the output of this Python code snippet using spidev to send data to an SPI display?

medium📝 Predict Output Q4 of 15
Raspberry Pi - SPI Communication
What will be the output of this Python code snippet using spidev to send data to an SPI display?
import spidev
spi = spidev.SpiDev()
spi.open(0, 0)
response = spi.xfer2([0xAA, 0xBB, 0xCC])
print(response)
A[0xAA, 0xBB, 0xCC]
B[170, 187, 204]
C[0, 0, 0]
D[255, 255, 255]
Step-by-Step Solution
Solution:
  1. Step 1: Understand spi.xfer2() behavior

    spi.xfer2() sends bytes and returns the bytes received from the SPI slave device.
  2. Step 2: Consider typical response from display

    Most SPI displays do not send meaningful data back, so response is usually zeros for each byte sent.
  3. Final Answer:

    [0, 0, 0] -> Option C
  4. Quick Check:

    spi.xfer2() returns received bytes, usually zeros from display [OK]
Quick Trick: SPI transfer returns received bytes, often zeros from displays [OK]
Common Mistakes:
MISTAKES
  • Assuming sent bytes are returned
  • Expecting hex strings instead of integers
  • Confusing xfer2 with write-only methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes