Bird
0
0

Given this Python code on Raspberry Pi: import serial ser = serial.Serial('/dev/serial0', 115200) ser.write(b'Ping') response = ser.readline() print(response.decode().strip()) If Arduino replies with 'Pong\n', what is printed?

medium📝 Predict Output Q5 of 15
Raspberry Pi - Serial UART Communication
Given this Python code on Raspberry Pi: import serial ser = serial.Serial('/dev/serial0', 115200) ser.write(b'Ping') response = ser.readline() print(response.decode().strip()) If Arduino replies with 'Pong\n', what is printed?
APong
BPong\n
CPing
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand readline and decode

    readline reads until newline, decode converts bytes to string.
  2. Step 2: strip removes trailing newline

    strip() removes '\n', so printed string is 'Pong'.
  3. Final Answer:

    Pong -> Option A
  4. Quick Check:

    readline + decode + strip = Pong [OK]
Quick Trick: Use strip() to remove newline from serial readline output [OK]
Common Mistakes:
MISTAKES
  • Printing raw bytes
  • Not stripping newline
  • Confusing sent and received data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes