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:

1951 questions
98
votes
4 answers

Full examples of using pySerial package

Can someone please show me a full python sample code that uses pyserial, i have the package and am wondering how to send the AT commands and read them back!
Gath
  • 1,257
  • 3
  • 15
  • 14
91
votes
12 answers

Listing available com ports with Python

I am searching for a simple method to list all available com port on a PC. I have found this method but it is Windows-specific: Listing serial (COM) ports on Windows? I am using Python 3 with pySerial on a Windows 7 PC. I have found in the pySerial…
doom
  • 2,302
  • 3
  • 18
  • 33
59
votes
4 answers

Is there a way to "compile" Python code onto an Arduino (Uno)?

I have a robotics type project with an Arduino Uno, and to make a long story short, I am experimenting with some AI algorithms. However, I need to implement some high level matrix algorithms that would be quite simple using NumPy/SciPy, but they are…
Alex Eftimiades
  • 2,329
  • 3
  • 22
  • 31
51
votes
6 answers

Virtual Serial Device in Python?

I know that I can use e.g. pySerial to talk to serial devices, but what if I don't have a device right now but still need to write a client for it? How can I write a "virtual serial device" in Python and have pySerial talk to it, like I would, say,…
tdavis
  • 1,352
  • 2
  • 12
  • 12
39
votes
4 answers

Reading serial data in realtime in Python

I am using a script in Python to collect data from a PIC microcontroller via serial port at 2Mbps. The PIC works with perfect timing at 2Mbps, also the FTDI usb-serial port works great at 2Mbps (both verified with oscilloscope) Im sending messages…
Vasco Baptista
  • 583
  • 2
  • 7
  • 14
34
votes
4 answers

PySerial non-blocking read loop

I am reading serial data like this: connected = False port = 'COM4' baud = 9600 ser = serial.Serial(port, baud, timeout=0) while not connected: #serin = ser.read() connected = True while True: print("test") reading =…
DominicM
  • 4,652
  • 13
  • 35
  • 57
33
votes
3 answers

python3 pySerial TypeError: unicode strings are not supported, please encode to bytes:

In Python 3 I imported the pySerial library so I could communicate with my Arduino Uno by serial commands. It worked very well in Python 2.7 but in Python 3 I keep running into a error it says this TypeError: unicode strings are not supported,…
Nik Hendricks
  • 363
  • 1
  • 3
  • 9
31
votes
4 answers

What is the cross-platform method of enumerating serial ports in Python (including virtual ports)?

Note: I'm using Python 2.7, and pySerial for serial communications. I found this article which lists two ways: http://www.zaber.com/wiki/Software/Python#Displaying_a_list_of_available_serial_ports This method works on Windows and Linux, but…
Chris Laplante
  • 28,157
  • 16
  • 93
  • 131
30
votes
11 answers

pyserial: No module named tools

I have installed the latest pySerial on my Ubuntu box with python 2.7.2, and it works fine for most things, but whenever I try to import the 'tools' package, it says that it can't find 'tools'. The documentation for pySerial explicitly references…
charmoniumQ
  • 4,270
  • 4
  • 24
  • 47
30
votes
3 answers

Efficient and fast Python While loop while using sleep()

I am attempting to communicate with a device over serial using Pyserial. As commands need to be continually sent, they have to be placed in a while loop in Python. I am currently using this code, and have taken a look at python process takes 100%…
jhtong
  • 1,349
  • 4
  • 18
  • 31
26
votes
4 answers

Python to automatically select serial ports (for Arduino)

Currently the python program must know which port a device (Arduino) is on before Python can communicate the device. Problem: Whenever the device is plugged out and back in, its COM port changes, so the correct serial port must be given to Python…
Nyxynyx
  • 52,075
  • 130
  • 401
  • 707
26
votes
4 answers

Python Serial: How to use the read or readline function to read more than 1 character at a time

I'm having trouble to read more than one character using my program, I can't seem to figure out what went wrong with my program. import serial ser = serial.Serial( port='COM5',\ baudrate=9600,\ parity=serial.PARITY_NONE,\ …
user2294001
  • 303
  • 1
  • 5
  • 6
25
votes
3 answers

pySerial write() won't take my string

Using Python 3.3 and pySerial for serial communications. I'm trying to write a command to my COM PORT but the write method won't take my string. (Most of the code is from here Full examples of using pySerial package What's going on? import…
Garvin
  • 815
  • 2
  • 10
  • 16
25
votes
4 answers

Convert an int value to unicode

I am using pyserial and need to send some values less than 255. If I send the int itself the the ascii value of the int gets sent. So now I am converting the int into a unicode value and sending it through the serial port.…
user2578666
  • 1,033
  • 3
  • 12
  • 18
23
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
  • 40,613
  • 26
  • 100
  • 171
1
2 3
99 100