Python Forum
Unable to read from serial port
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to read from serial port
#1
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.
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  MCU reboots after opening Serial port when ran from Raspberry PI zazas321 3 328 Mar-19-2024, 09:02 AM
Last Post: zazas321
  Waiting for input from serial port, then move on KenHorse 2 832 Oct-17-2023, 01:14 AM
Last Post: KenHorse
  pyserial/serial "has no attribute 'Serial' " gowb0w 9 3,312 Aug-24-2023, 07:56 AM
Last Post: gowb0w
  Serial Port As Global Prasanjith 2 1,420 Mar-23-2023, 08:54 PM
Last Post: deanhystad
  Python Serial: How to read the complete line to insert to MySQL? sylar 1 781 Mar-21-2023, 10:06 PM
Last Post: deanhystad
  python serial port barryjo 2 1,601 Dec-27-2021, 11:09 PM
Last Post: barryjo
  is there a way to mention port range or search for port dynamically with qConnection Creepy 0 1,449 Sep-09-2021, 03:15 PM
Last Post: Creepy
  How to Properly Open a Serial Port in a Function bill_z 2 4,350 Jul-22-2021, 12:54 PM
Last Post: bill_z
  UART Serial Read & Write to MP3 Player Doesn't Work bill_z 15 5,644 Jul-17-2021, 04:19 PM
Last Post: bill_z
  Stop the serial read until video is recorded vj01 1 1,713 Jun-10-2021, 09:56 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020