-
Notifications
You must be signed in to change notification settings - Fork 1
/
ser-log.py
50 lines (41 loc) · 914 Bytes
/
ser-log.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
@brief Retrieve and log serial data.
@file ser-log.py
@author drtrigon
...
"""
import serial
import time
#import numpy as np
import matplotlib.pyplot as plt
ser = serial.Serial('/dev/ttyACM0') # open first serial port
print ser.portstr # check which port was really used
plt.axis([0, 20000, -0.1, 3])
plt.ion()
plt.show()
i = 0
x = list()
y = list()
#ser.write("hello") # write a string
while True:
try:
ser.flushInput()
temp_y = ser.readline()
temp_y = temp_y.split()[0]
print i, temp_y
# x.append(i)
# y.append(temp_y)
plt.scatter(i, temp_y, s=0.1)
i += 1
plt.draw()
time.sleep(1.)
except KeyboardInterrupt:
print "...",
break
except BaseException:
#pass
print "<warning>"
ser.close() # close port
print "bye!"