Complete the code to open the UART serial port on Raspberry Pi.
import serial ser = serial.Serial('/dev/ttyS0', [1]) print("Serial port opened")
The baud rate 9600 is the standard speed for UART communication with Arduino.
Complete the code to send the string 'Hello Arduino' over UART.
message = 'Hello Arduino' ser.write([1]) print("Message sent")
We must encode the string to bytes before sending over UART.
Fix the error in reading a line from UART and decoding it.
line = ser.readline() text = line.[1]('utf-8').strip() print(text)
We use decode('utf-8') to convert bytes to string.
Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.
words = ['arduino', 'pi', 'uart', 'code'] lengths = {word: [1] for word in words if len(word) [2] 3} print(lengths)
We use len(word) to get length and filter words with length greater than 3.
Fill all three blanks to create a dictionary with uppercase keys and values greater than 2.
data = {'temp': 1, 'humidity': 3, 'pressure': 5}
filtered = [1]: [2] for k, v in data.items() if v [3] 2}
print(filtered)Keys are converted to uppercase with k.upper(), values are v, and filter uses '>' to select values greater than 2.
