Bird
0
0
Raspberry Piprogramming~10 mins

Why SPI is used for fast peripherals in Raspberry Pi - Test Your Understanding

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

Complete the code to initialize SPI communication on Raspberry Pi.

Raspberry Pi
import spidev
spi = spidev.SpiDev()
spi.open(0, [1])
Drag options to blanks, or click blank then click option'
A3
B1
C2
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using device number instead of bus number
Confusing bus and device numbers
2fill in blank
medium

Complete the code to set SPI speed to 1 MHz.

Raspberry Pi
spi.max_speed_hz = [1]
Drag options to blanks, or click blank then click option'
A100000
B5000000
C1000000
D10000
Attempts:
3 left
💡 Hint
Common Mistakes
Using 100000 instead of 1000000
Confusing kHz and MHz
3fill in blank
hard

Fix the error in the code to send data over SPI.

Raspberry Pi
data = [0x01, 0x02, 0x03]
response = spi.[1](data)
Drag options to blanks, or click blank then click option'
Axfer
Bread
Cwrite
Dsend
Attempts:
3 left
💡 Hint
Common Mistakes
Using write which only sends data
Using read which only reads data
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps pin numbers to their SPI modes.

Raspberry Pi
spi_modes = {pin: [1] for pin in range(1, 5) if pin [2] 3}
Drag options to blanks, or click blank then click option'
A0
B>
C<
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operator
Assigning wrong SPI mode
5fill in blank
hard

Fill all three blanks to filter and map SPI devices with speed over 500 kHz.

Raspberry Pi
fast_devices = [1]: [2] for [3] in devices if devices[[3]] > 500000}
Drag options to blanks, or click blank then click option'
Adevice
Bspeed
Cdev
Ddevices
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names
Incorrect dictionary comprehension syntax