Bird
0
0
Raspberry Piprogramming~10 mins

Baud rate and timeout configuration 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 set the baud rate to 9600 when opening the serial port.

Raspberry Pi
import serial
ser = serial.Serial('/dev/ttyUSB0', baudrate=[1])
Drag options to blanks, or click blank then click option'
A19200
B9600
C4800
D115200
Attempts:
3 left
💡 Hint
Common Mistakes
Using a baud rate that is too high or too low for the device.
2fill in blank
medium

Complete the code to set the timeout to 1 second for the serial connection.

Raspberry Pi
import serial
ser = serial.Serial('/dev/ttyUSB0', baudrate=9600, timeout=[1])
Drag options to blanks, or click blank then click option'
A1
B0
CNone
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Setting timeout to 0 disables waiting, which may cause immediate return.
3fill in blank
hard

Fix the error in the code to correctly set the baud rate and timeout.

Raspberry Pi
import serial
ser = serial.Serial('/dev/ttyUSB0', baudrate=9600, timeout=[1])
Drag options to blanks, or click blank then click option'
A1
BNone
CTrue
D'1'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around numbers, making them strings.
4fill in blank
hard

Fill both blanks to create a serial connection with baud rate 115200 and timeout 0.5 seconds.

Raspberry Pi
import serial
ser = serial.Serial('/dev/ttyUSB0', baudrate=[1], timeout=[2])
Drag options to blanks, or click blank then click option'
A115200
B9600
C0.5
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing baud rate and timeout values or using wrong types.
5fill in blank
hard

Fill all three blanks to open a serial port '/dev/ttyS1' with baud rate 19200, timeout 2 seconds, and write timeout 1 second.

Raspberry Pi
import serial
ser = serial.Serial(port=[1], baudrate=[2], timeout=[3], write_timeout=1)
Drag options to blanks, or click blank then click option'
A'/dev/ttyS1'
B19200
C2
D'/dev/ttyUSB0'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around port name or using wrong baud rate.