Bird
0
0
Raspberry Piprogramming~10 mins

spidev library usage in Raspberry Pi - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the spidev library.

Raspberry Pi
import [1]
Drag options to blanks, or click blank then click option'
Aspidev
Bspi
Cspidev_lib
Dspilib
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect module names like 'spi' or 'spilib'.
2fill in blank
medium

Complete the code to create an SPI object.

Raspberry Pi
spi = [1].SpiDev()
Drag options to blanks, or click blank then click option'
ASPI
Bspidev
Cspi
DSpiDev
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase 'SPI' or 'SpiDev' as the module name.
3fill in blank
hard

Fix the error in opening SPI bus 0, device 1.

Raspberry Pi
spi.open([1], 1)
Drag options to blanks, or click blank then click option'
A0
B1
C2
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping bus and device numbers or using invalid bus numbers.
4fill in blank
hard

Fill both blanks to set SPI max speed to 1 MHz and mode to 0.

Raspberry Pi
spi.max_speed_hz = [1]
spi.mode = [2]
Drag options to blanks, or click blank then click option'
A1000000
B500000
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong speed values or wrong mode numbers.
5fill in blank
hard

Fill all three blanks to write bytes [0x01, 0x02, 0x03] and read response.

Raspberry Pi
response = spi.xfer2([1])
print([2])
[3].close()
Drag options to blanks, or click blank then click option'
A[0x01, 0x02, 0x03]
Bresponse
Cspi
D[1, 2, 3]
Attempts:
3 left
💡 Hint
Common Mistakes
Using decimal list instead of hex, printing wrong variable, or forgetting to close SPI.