如何向python gui显示Arduino串口数据?

时间:2017-02-13 12:50:28

标签: python user-interface arduino pyserial

我正在处理项目,我从data获取Arduino serially并将其访问到Python。要从arduino访问数据,我使用pyserial。之后,我必须在Python GUI上显示该数据。 我怎么能这样做?

我在Arduino Serial Monitor ....

中获取此数据
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 output ...

[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我使用此代码获取Serial data ....

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

1 个答案:

答案 0 :(得分:1)

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