Python Forum

Full Version: Unable to read from serial port
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm working on a project where I control a LED matrix connected to an Arduino.
Using pyserial I open the Arduino's serial port and send a "?" to it.
The Arduino should reply with an "!", however I'm unable to read this.

import serial

port = "/dev/tty.usbserial-A106TL49"
port = serial.Serial(port, 115200, timeout=5)
port.write("?\n".encode())
port.flush()
resp = port.readline().decode()
port.close()
print(resp)
If I copy and paste each line into the Python Shell (or just type it in manually), it works.
İmage

I tried adding a time.sleep() before writing and reading to/from the serial port but it did not work either.
only the receiver will see the time delay, not the sender so whatever was sent may be gone by the time you try to read it.