Bird
0
0

You wrote this code to read from a serial device but get no output:

medium📝 Debug Q14 of 15
Raspberry Pi - Serial UART Communication
You wrote this code to read from a serial device but get no output:
import serial
ser = serial.Serial('/dev/ttyS0', 115200)
data = ser.read(5)
print(data)
What is the likely problem?
AThe serial port '/dev/ttyS0' is not valid on Raspberry Pi
BThe read() function requires a string argument, not an integer
Cprint() cannot display bytes
DThe baud rate 115200 does not match the device speed
Step-by-Step Solution
Solution:
  1. Step 1: Check baud rate importance

    Serial communication requires matching baud rates on both ends; mismatch causes no data or garbage.
  2. Step 2: Validate other code parts

    read() accepts integer bytes count, '/dev/ttyS0' is valid, and print() can display bytes, so these are not issues.
  3. Final Answer:

    The baud rate 115200 does not match the device speed -> Option D
  4. Quick Check:

    Baud rate mismatch = no data received [OK]
Quick Trick: Match baud rates exactly to get data [OK]
Common Mistakes:
MISTAKES
  • Thinking read() needs string argument
  • Assuming port name is always wrong
  • Believing print() can't show bytes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes