pyserial

ValueError: invalid literal for int() with base 16: '\x0e\xa3' Python

£可爱£侵袭症+ 提交于 2019-12-29 05:37:04
问题 I get bytes from the serial port which represents the voltage on my PIC board. But I can't convert these bytes(strings) to decimal because I get the error message above. Here is the function(in fact, it's associated with tkinter button) def channel8(): ser.write(chr(0xFF)) print "you have select channel8" x=ser.read(2) w=int(x, 16) print w print "Voltage on channel8 is:" , x ValueError: invalid literal for int() with base 16: '\x0e\xa3' def channel8(): ser.write(chr(0xFF)) print "you have

Python to automatically select serial ports (for Arduino)

房东的猫 提交于 2019-12-28 02:35:28
问题 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 again for it to find the device. How can Python (using pySerial ) automatically search for the correct serial port to use? Is it possible for python to correctly identify the device on a serial port as an Arduino? 回答1: Use the following code to see

Arduino Live Serial Plotting with a MatplotlibAnimation gets slow

醉酒当歌 提交于 2019-12-26 03:14:05
问题 I am making a live plotter to show the analog changes from an Arduino Sensor. The Arduino prints a value to the serial with a Baudrate of 9600. The Python code looks as following: import matplotlib.pyplot as plt import matplotlib.animation as animation import serial import time ser = serial.Serial("com3", 9600) ser.readline() optimal_frequency = 100 fig = plt.figure(figsize=(6, 6)) ax1 = fig.add_subplot(1, 1, 1) # the following arrays must be initialized outside the loop xar = [] yar = []

Encoding error, in python3

笑着哭i 提交于 2019-12-25 16:54:47
问题 I have a somewhat similar question here that I can't solve. In another instance of my code, I face similar encoding errors. Do assist! My code: port = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=10, bytesize=8) f_w = open('/home/ryan/python_serial_output.txt','r+') f_o = open('/home/ryan/python_serial_parse.txt','w') port.send_break() sys_reply = port.read(100000) sys_reply_str = sys_reply.decode('utf-8') print(sys_reply_str) sys_reply_str_haha = sys_reply_str.replace("\r","") sys

Arduino 'Error communicating…unicode strings are not supported, please encode to bytes' PySerial

回眸只為那壹抹淺笑 提交于 2019-12-25 09:12:10
问题 I'm trying to connect to my MultiWii over PySerial, however I keep getting this error. Error communicating...unicode strings are not supported, please encode to bytes: '$M<\x00ll' This is the part of the code that's failing: BASIC="\x24\x4d\x3c\x00" MSP_ATTITUDE=BASIC+"\x6C\x6C" ser.write(MSP_ATTITUDE) I've tried encoding the strings with .encode() in which I get this error: Error communicating...'bytes' object has no attribute 'encode' I've tried bytearray(MSP_ATTITUDE,'ascii') and get the

storing serial value after the loop is done from the Arduino side

强颜欢笑 提交于 2019-12-25 09:00:36
问题 I have similar question with the link below. How to store value in list (python) which is coming from arduino serially? For his output will look like [2.00] [2.00,2.64] [2.00,2.64,3.28] etc So I wonder how will be able to use [2.00,2.64,3.28] after the while true loop is done. I want to use that last piece because I want to extract specific index from that list and make use of it. I wish somebody know the answer could help. Greg 回答1: As it is specified in the answer related to your question:

3rd Party Python Modules in PyQt

微笑、不失礼 提交于 2019-12-25 07:57:39
问题 I am trying to decide on a technology for developing a desktop application that can interface with the serial port. I have looked into python and it looks like a console based app would not be difficult - http://pyserial.sourceforge.net/ , and I have also looked at PyQt, which would fulfill the GUI portion of my project. But is it possible to include 3rd party modules like PySerial in PyQt? 回答1: PyQt and pyserial play nice together (in fact, I'm using them in one of my apps.) The examples on

PySerial write errors (baudrate sensitive)

半城伤御伤魂 提交于 2019-12-25 05:33:27
问题 I'm having some issues with pyserial and windows (on linux it works fine with the same code); I seem to be writing erroneous bytes. The code even works fine on the same machine inside a debian VM, So Im pretty sure its a software thing. I'm using Python 2.7.6 32bit, pyserial 2.7 but have tried others (2.5 and 2.4) all exibit the same errors. Interestingly enough, the errors are much less frequent when the baudrate is increased to 115200. This is the relavant bit of my code: ser = serial

pyserial when it is the end of the line stop the while loop

夙愿已清 提交于 2019-12-25 05:20:43
问题 import serial arduino = serial.Serial('COM12', 9600, timeout = .1) arduino_data = [] # declare a list while True: data = arduino.readline() if data: arduino_data.append(data) # Append a data to your declared list print arduino_data I wonder when there is no more new line from Arduino side, how can i jump out the while loop? while True: data = arduino.readline() if data: arduino_data.append(data) # Append a data to your declared list print arduino_data break It only works for 1 line. 回答1: Wait

Clash of connection between serial port read and write codes

随声附和 提交于 2019-12-25 04:32:01
问题 This is the code that reads from the z1 mote while True: if not ser.isOpen(): try: ser = serial.Serial(z1port, z1baudrate,timeout=0, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS) except: sys.exit("Error connecting device") queue = ser.inWaiting() if queue > 0: data = ser.read(1000) print data time.sleep(0.2) And this is the code that I have that I use it to write to the mote # some event-driven code here so that whenever a message is received then do: