Questions tagged [pyserial]

pySerial is a Python module that encapsulates the access for the serial port. It provides backends for different platforms and Python implementations.

pySerial encapsulates the access for the serial port. It provides backends for Python running on Windows, Linux, BSD (possibly any POSIX compliant system), Jython and IronPython (.NET and Mono). The module named serial automatically selects the appropriate backend.

This is an example extracted from the introduction of the documentation:

>>> import serial
>>> ser = serial.Serial(0)  # open first serial port
>>> print(ser.portstr)      # check which port was really used
>>> ser.write("hello")      # write a string
>>> ser.close()             # close port

References:

2268 questions
27
votes
3 answers

Using PySerial is it possible to wait for data?

I've got a Python program which is reading data from a serial port via the PySerial module. The two conditions I need to keep in mind are: I don't know how much data will arrive, and I don't know when to expect data. Based on this I have came up…
Mike
  • 47,263
  • 29
  • 113
  • 177
23
votes
3 answers

Kill process that raises Device or resource busy: '/dev/ttyUSB0'?

I connect to my Arduino board with the following Python code. device=glob.glob("/dev/ttyUSB*")[0] time.sleep(1) arduino = serial.Serial(device, 115200, timeout=5) It generally works, but somehow some other process must be accessing the board after…
birgit
  • 1,121
  • 2
  • 21
  • 39
23
votes
10 answers

pyserial - How to read the last line sent from a serial device

I have an Arduino connected to my computer running a loop, sending a value over the serial port back to the computer every 100 ms. I want to make a Python script that will read from the serial port only every few seconds, so I want it to just see…
Greg
  • 45,306
  • 89
  • 231
  • 297
21
votes
2 answers

How to send and receive some data via a GSM modem during an active call (Python and AT Command)

I wrote the below Python program to communicate with my D-Link DWM-156 GSM modem. This program wait for incoming calls and as it receive a RING alert, it accepts that call. Fortunately it works fine ;) The Program: import time import serial phone =…
Ebrahim Ghasemi
  • 5,850
  • 10
  • 52
  • 113
21
votes
3 answers

OSError: [Errno 13] Permission denied: '/dev/ttyACM0' - using pyserial from Python to Arduino

Environment Linux Mint 17.1 Python 2.7 pyserial 2.7 Arduino UNO rv3 Desired Behaviour I'm trying to send three values from a Python application to Arduino. It works when doing the following from terminal: $ python $ import serial $ import…
user1063287
  • 10,265
  • 25
  • 122
  • 218
19
votes
4 answers

PySerial: How to send Ctrl-C command on the serial line

I'm automating a configuration process for an embedded board. To enter the setup screen I need to send "Ctrl-C" command. This is NOT to interrupt a process I'm running locally, KeyboardInterrupt will not work. I need to send a value that will be…
Misha M
  • 10,979
  • 17
  • 53
  • 65
17
votes
3 answers

Binary data with pyserial(python serial port)

serial.write() method in pyserial seems to only send string data. I have arrays like [0xc0,0x04,0x00] and want to be able to send/receive them via the serial port? Are there any separate methods for raw I/O? I think I might need to change the arrays…
Atilla Filiz
  • 2,383
  • 8
  • 29
  • 47
17
votes
2 answers

How to read and write from a COM port using PySerial?

I have Python 3.6.1 and PySerial installed. I am able to get a list of COM ports connected. I want to send data to the COM port and receive responses: import serial.tools.list_ports as port_list ports = list(port_list.comports()) for p in ports: …
Neil Dey
  • 449
  • 2
  • 7
  • 18
17
votes
1 answer

how to make python awaitable object

In python 3.5.1 one can make use of await/async, however, to use it (as I undestand), you need to have awaitable object. An awaitable object is an object that defines __await__() method returning an iterator. More info here. But I can not google out…
nekitip
  • 357
  • 1
  • 2
  • 10
17
votes
3 answers

ImportError: No module named serial

I have a script written in Python 3 with 3.3.5 installed, and I am getting this error from the terminal whenever I try to run it. I am using a Mac, OSX 10.7.5 I have already installed pyserial (using pip) for python 3. In order to do this, I first…
user3587244
  • 173
  • 1
  • 1
  • 7
16
votes
4 answers

pySerial buffer won't flush

I'm having a problem with serial IO under both Windows and Linux using pySerial. With this code the device never receives the command and the read times out: import serial ser =…
Robert Jordan
  • 1,053
  • 1
  • 10
  • 17
15
votes
6 answers

Using pyserial to send binary data

I know there has been a lot of discussion on this but I still have a question. I am trying to send hex values through pyserial to my device using pyserial command="\x89\x45\x56" ser.write(command) However I keep getting an error saying string…
BladeRunner
  • 151
  • 1
  • 1
  • 4
15
votes
5 answers

Disable DTR in pyserial from code

I'm trying to use pyserial to send data to an arduino. But when I open the COM port it sets DTR low and resets the board. However, I have my arduino code setup such that I have to put it into serial receive mode by holding two buttons for 1 second.…
Adam Haile
  • 30,705
  • 58
  • 191
  • 286
15
votes
2 answers

Python/PySerial and CPU usage

I've created a script to monitor the output of a serial port that receives 3-4 lines of data every half hour - the script runs fine and grabs everything that comes off the port which at the end of the day is what matters... What bugs me, however, is…
Crazy Joe Malloy
  • 834
  • 6
  • 14
14
votes
2 answers

Access USB serial ports using Python and pyserial

How do I access the USB port using pyserial? I have seen an example with: import serial ser = serial.Serial('/dev/ttyUSB0') I used to access the serial port from MATLAB on Windows and using the appropriate syntax, /dev/ttyUSB0 would be replaced by…
Kit
  • 30,365
  • 39
  • 105
  • 149