Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Windows device names like 'COM1'.
Using non-existent device files.
✗ Incorrect
On Raspberry Pi, serial devices are usually accessed via /dev/ttyS0.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Sending a string without converting to bytes.
Using a plain string without prefix.
✗ Incorrect
Data sent over serial must be bytes, so prefix the string with b.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string instead of an integer.
Passing None or invalid types.
✗ Incorrect
The read() method expects an integer number of bytes to read.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers as keys.
Using the same device name twice.
✗ Incorrect
We use device names as keys and common baud rates as values.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names.
Mixing up keys and values.
✗ Incorrect
We iterate over devices.items() using name and rate, then filter by rate.
