Bird
0
0
Raspberry Piprogramming~10 mins

SPI with display modules 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 SPI library for Raspberry Pi.

Raspberry Pi
import [1]
Drag options to blanks, or click blank then click option'
Agpiozero
Bspidev
CRPi.GPIO
Dtime
Attempts:
3 left
💡 Hint
Common Mistakes
Importing gpiozero instead of spidev
Using RPi.GPIO which is for general GPIO, not SPI
2fill in blank
medium

Complete the code to open SPI bus 0, device 0.

Raspberry Pi
spi = spidev.SpiDev()
spi.[1](0, 0)
Drag options to blanks, or click blank then click option'
Aconnect
Binit
Cstart
Dopen
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'connect' which is not a spidev method
Using 'init' which does not exist in spidev
3fill in blank
hard

Fix the error in the code to send data [0xAA, 0xBB] over SPI.

Raspberry Pi
data = [0xAA, 0xBB]
spi.[1](data)
Drag options to blanks, or click blank then click option'
Awritebytes
Bwrite
Csend
Dtransfer
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'send' which is not a spidev method
Using 'transfer' which sends and receives data
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
B0
C1
D500000
Attempts:
3 left
💡 Hint
Common Mistakes
Setting mode to 1 instead of 0
Using 500000 for max speed instead of 1000000
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each byte in data to its hex string if byte is greater than 0x80.

Raspberry Pi
result = [1]: hex([2]) for [3] in data if [2] > 0x80
Drag options to blanks, or click blank then click option'
Abyte
Bb
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names for key and iteration variable
Not converting byte to hex string