Connect to serial from a PyQt GUI

Instead of using pySerial + thread it is better to use QSerialPort that is made to live with the Qt event-loop: from PyQt5 import QtCore, QtWidgets, QtSerialPort class Widget(QtWidgets.QWidget): def __init__(self, parent=None): super(Widget, self).__init__(parent) self.message_le = QtWidgets.QLineEdit() self.send_btn = QtWidgets.QPushButton( text=”Send”, clicked=self.send ) self.output_te = QtWidgets.QTextEdit(readOnly=True) self.button = QtWidgets.QPushButton( text=”Connect”, checkable=True, toggled=self.on_toggled ) lay = … Read more

Python to automatically select serial ports (for Arduino)

Use the following code to see all the available serial ports: import serial.tools.list_ports ports = list(serial.tools.list_ports.comports()) for p in ports: print p This gives me the following: (‘COM4’, ‘Arduino Due Programming Port (COM4)’, ‘USB VID:PID=2341:003D SNR=75330303035351300230’) (‘COM11’, ‘RS-232 Port (COM11)’, ‘FTDIBUS\\VID_0856+PID_AC27+BBOPYNPPA\\0000′) To work out if it’s an Arduino you could do something like: if “Arduino” … Read more

PySerial non-blocking read loop

Using a separate thread is totally unnecessary. Just do this for your infinite while loop instead (Tested in Python 3.2.3). I use this technique in my eRCaGuy_PyTerm serial terminal program here (search the code for inWaiting() or in_waiting). import serial import time # Optional (required if using time.sleep() below) ser = serial.Serial(port=”COM4″, baudrate=9600) while (True): … Read more

Listing available com ports with Python

This is the code I use. Successfully tested on Windows 8.1 x64, Windows 10 x64, Mac OS X 10.9.x / 10.10.x / 10.11.x and Ubuntu 14.04 / 14.10 / 15.04 / 15.10 with both Python 2 and Python 3. import sys import glob import serial def serial_ports(): “”” Lists serial port names :raises EnvironmentError: On … Read more

Full examples of using pySerial package [closed]

Blog post Serial RS232 connections in Python import time import serial # configure the serial connections (the parameters differs on the device you are connecting to) ser = serial.Serial( port=”/dev/ttyUSB1″, baudrate=9600, parity=serial.PARITY_ODD, stopbits=serial.STOPBITS_TWO, bytesize=serial.SEVENBITS ) ser.isOpen() print ‘Enter your commands below.\r\nInsert “exit” to leave the application.’ input=1 while 1 : # get keyboard input input … Read more