Bird
0
0
Raspberry Piprogramming~10 mins

Why serial communication connects to external devices 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 open a serial connection on Raspberry Pi.

Raspberry Pi
import serial
ser = serial.Serial([1], 9600)
Drag options to blanks, or click blank then click option'
A'/dev/ttyS0'
B'/dev/ttyUSB0'
C'COM1'
D'/dev/null'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Windows device names like 'COM1'.
Using non-existent device files.
2fill in blank
medium

Complete the code to send data over serial to an external device.

Raspberry Pi
ser.write([1])
Drag options to blanks, or click blank then click option'
Ab'Hello'
BHello
C'Hello'
Dbytearray('Hello')
Attempts:
3 left
💡 Hint
Common Mistakes
Sending a string without converting to bytes.
Using a plain string without prefix.
3fill in blank
hard

Fix the error in reading data from the serial port.

Raspberry Pi
data = ser.read([1])
Drag options to blanks, or click blank then click option'
Aser.in_waiting
BNone
C10
D'10'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string instead of an integer.
Passing None or invalid types.
4fill in blank
hard

Fill both blanks to create a dictionary of device names and their baud rates.

Raspberry Pi
devices = { [1]: 9600, [2]: 115200 }
Drag options to blanks, or click blank then click option'
A'sensor'
B'actuator'
C'controller'
D'display'
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers as keys.
Using the same device name twice.
5fill in blank
hard

Fill all three blanks to filter devices with baud rate above 9600.

Raspberry Pi
fast_devices = { [1]: [2] for [3], rate in devices.items() if rate > 9600 }
Drag options to blanks, or click blank then click option'
Adevice
Brate
Cdevices
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names.
Mixing up keys and values.