gpt4 book ai didi

python - 如何将Arduino串口数据显示到python gui?

转载 作者:太空宇宙 更新时间:2023-11-03 15:40:12 25 4
gpt4 key购买 nike

我正在开发一个项目,其中我从Arduino串行获取数据并将它们访问到Python。要从arduino访问数据我我正在使用 pyserial。之后,我必须在 Python GUI 上显示该数据。我怎样才能做到这一点?

我正在 Arduino 串行监视器 中获取此数据....

2.00
2.64
3.28
3.92
4.56
5.20
5.84
6.48
7.12
7.76
8.40
9.04
9.68
10.00
9.69
16.59
23.50
30.40
37.31
44.21
51.11
58.02
64.92
71.82
78.73
82.18

并使用pyserial我将此数据作为python输出...

[2.0]
[2.0, 2.64]
[2.0, 2.64, 3.28]
[2.0, 2.64, 3.28, 3.92]
[2.0, 2.64, 3.28, 3.92, 4.56]
[2.0, 2.64, 3.28, 3.92, 4.56, 5.2]
[2.0, 2.64, 3.28, 3.92, 4.56, 5.2, 5.84]
[2.0, 2.64, 3.28, 3.92, 4.56, 5.2, 5.84, 6.48]
[2.0, 2.64, 3.28, 3.92, 4.56, 5.2, 5.84, 6.48, 7.12]
[2.0, 2.64, 3.28, 3.92, 4.56, 5.2, 5.84, 6.48, 7.12, 7.76]
[2.0, 2.64, 3.28, 3.92, 4.56, 5.2, 5.84, 6.48, 7.12, 7.76, 8.4]
[2.0, 2.64, 3.28, 3.92, 4.56, 5.2, 5.84, 6.48, 7.12, 7.76, 8.4, 9.04]
[2.0, 2.64, 3.28, 3.92, 4.56, 5.2, 5.84, 6.48, 7.12, 7.76, 8.4, 9.04, 9.68]
[2.0, 2.64, 3.28, 3.92, 4.56, 5.2, 5.84, 6.48, 7.12, 7.76, 8.4, 9.04, 9.68, 10.0]
[2.0, 2.64, 3.28, 3.92, 4.56, 5.2, 5.84, 6.48, 7.12, 7.76, 8.4, 9.04, 9.68, 10.0, 9.69]
[2.0, 2.64, 3.28, 3.92, 4.56, 5.2, 5.84, 6.48, 7.12, 7.76, 8.4, 9.04, 9.68, 10.0, 9.69, 16.59]
[2.0, 2.64, 3.28, 3.92, 4.56, 5.2, 5.84, 6.48, 7.12, 7.76, 8.4, 9.04, 9.68, 10.0, 9.69, 16.59, 23.5]
[2.0, 2.64, 3.28, 3.92, 4.56, 5.2, 5.84, 6.48, 7.12, 7.76, 8.4, 9.04, 9.68, 10.0, 9.69, 16.59, 23.5, 30.4]
[2.0, 2.64, 3.28, 3.92, 4.56, 5.2, 5.84, 6.48, 7.12, 7.76, 8.4, 9.04, 9.68, 10.0, 9.69, 16.59, 23.5, 30.4, 37.31]
[2.0, 2.64, 3.28, 3.92, 4.56, 5.2, 5.84, 6.48, 7.12, 7.76, 8.4, 9.04, 9.68, 10.0, 9.69, 16.59, 23.5, 30.4, 37.31, 44.21]
[2.0, 2.64, 3.28, 3.92, 4.56, 5.2, 5.84, 6.48, 7.12, 7.76, 8.4, 9.04, 9.68, 10.0, 9.69, 16.59, 23.5, 30.4, 37.31, 44.21, 51.11]
[2.0, 2.64, 3.28, 3.92, 4.56, 5.2, 5.84, 6.48, 7.12, 7.76, 8.4, 9.04, 9.68, 10.0, 9.69, 16.59, 23.5, 30.4, 37.31, 44.21, 51.11, 58.02]
[2.0, 2.64, 3.28, 3.92, 4.56, 5.2, 5.84, 6.48, 7.12, 7.76, 8.4, 9.04, 9.68, 10.0, 9.69, 16.59, 23.5, 30.4, 37.31, 44.21, 51.11, 58.02, 64.92]
[2.0, 2.64, 3.28, 3.92, 4.56, 5.2, 5.84, 6.48, 7.12, 7.76, 8.4, 9.04, 9.68, 10.0, 9.69, 16.59, 23.5, 30.4, 37.31, 44.21, 51.11, 58.02, 64.92, 71.82]
[2.0, 2.64, 3.28, 3.92, 4.56, 5.2, 5.84, 6.48, 7.12, 7.76, 8.4, 9.04, 9.68, 10.0, 9.69, 16.59, 23.5, 30.4, 37.31, 44.21, 51.11, 58.02, 64.92, 71.82, 78.73]
[2.0, 2.64, 3.28, 3.92, 4.56, 5.2, 5.84, 6.48, 7.12, 7.76, 8.4, 9.04, 9.68, 10.0, 9.69, 16.59, 23.5, 30.4, 37.31, 44.21, 51.11, 58.02, 64.92, 71.82, 78.73, 82.18]

python中,我使用此代码来获取串行数据....

import serial
arduino = serial.Serial('COM5', 9600, timeout = .1)
arduino_data = [] # declare a list
while True:
data = arduino.readline()
if data:
arduino_data.append(float(data)) # Append a data to your declared list
print arduino_data

最佳答案

import serial
arduino = serial.Serial('COM3', 9600, timeout = .1)
arduino_data = [] # declare a list
i=0;
while i<5:
data = arduino.readline()
if data:
#arduino_data.append(data) # Append a data to your declared list
print data
i=i+1;


#try this code mate, i am beginner but did this for you i think i will work for you please

关于python - 如何将Arduino串口数据显示到python gui?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42204498/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com