D
D
Dmitri2020-10-07 17:35:14
Python
Dmitri, 2020-10-07 17:35:14

Pyserial on ubuntu + arduino?

There is a python code that just reads data from the com port, the code works on windows but does not work on ubuntu
Error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/serial/serialposix.py", line 323, in _reconfigure_port
    orig_attr = termios.tcgetattr(self.fd)
termios.error: (5, 'Input/output error')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 5, in <module>
    ser = serial.Serial(port='/dev/ttyS5', baudrate=9600)
  File "/usr/local/lib/python3.8/dist-packages/serial/serialutil.py", line 240, in __init__
    self.open()
  File "/usr/local/lib/python3.8/dist-packages/serial/serialposix.py", line 272, in open
    self._reconfigure_port(force_update=True)
  File "/usr/local/lib/python3.8/dist-packages/serial/serialposix.py", line 326, in _reconfigure_port
    raise SerialException("Could not configure port: {}".format(msg))
serial.serialutil.SerialException: Could not configure port: (5, 'Input/output error')


The code:
import time
import serial
import datetime

ser = serial.Serial(port='/dev/ttyS5', baudrate=9600)
received = []

ser.write(b'begin\n')
time.sleep(5)

ser.write(b'hello')
line = ser.readline()
print(line.decode())

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kalapanga, 2020-10-08
@kalapanga

The instructions for installing the Arduino IDE on Linux say that you need to add your user to the dialout group so that you can interact with the port. Try it.

V
Vladimir Kuts, 2020-10-07
@fox_12

code works on windows but not on ubuntu

The port on windows and ubuntu is visible in different ways. Make sure you are accessing the correct port.
Besides there it is necessary to expose the rights to access.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question