Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the spidev library.
Raspberry Pi
import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect module names like 'spi' or 'spilib'.
✗ Incorrect
The spidev library is imported using import spidev.
2fill in blank
mediumComplete the code to create an SPI object.
Raspberry Pi
spi = [1].SpiDev() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase 'SPI' or 'SpiDev' as the module name.
✗ Incorrect
You create an SPI object by calling SpiDev() from the spidev module.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping bus and device numbers or using invalid bus numbers.
✗ Incorrect
The SPI bus number is usually 0 or 1. To open bus 0, device 1, use spi.open(0, 1).
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong speed values or wrong mode numbers.
✗ Incorrect
Set max_speed_hz to 1,000,000 for 1 MHz speed and mode to 0 for SPI mode 0.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using decimal list instead of hex, printing wrong variable, or forgetting to close SPI.
✗ Incorrect
Use spi.xfer2([0x01, 0x02, 0x03]) to send bytes and get the response. Then print the response variable. Finally, close the SPI connection with spi.close().
