-
Notifications
You must be signed in to change notification settings - Fork 0
/
spectro.py
87 lines (59 loc) · 1.53 KB
/
spectro.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 04 22:15:47 2015
@author: Beat
/dev/cu.usbmodem14123 for red launchpad on mac
"""
import serial
import matplotlib.pyplot as plt
import time
from IPython import display
import pylab as pl
import numpy as np
ser = serial.Serial(
port="/dev/cu.usbmodem14123",
baudrate=115200,
parity=serial.PARITY_ODD,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS
)
#ser.open()
ser.isOpen()
while 1:
print 'Opened serial port'
#get rid of incomplete dataset
while ser.read(1) != '\n' :
pass
#while 1 :
charIn = ser.read(1)
dataBuffer = charIn
while charIn != '\n' :
charIn = ser.read(1)
dataBuffer += charIn
myValuesString = dataBuffer.split(',')
myValuesInt = []
myValuesLength = 0
for singleValue in myValuesString:
try:
myValuesInt.append(int(singleValue))
myValuesLength+=1
except:
pass
print 'plotting'
display.clear_output(wait=True)
display.display(pl.gcf())
#myValuesInt.reverse()
plt.minorticks_on()
plt.grid(color='r', linestyle='-', linewidth=1, which='both')
plt.plot(map(lambda x: x/float(2),range(myValuesLength)), myValuesInt)
#plt.xticks(np.arange(0, 750, 0.5))
plt.axis([150,1200,60,200])
plt.show()
time.sleep(1)
plt.close()
ser.close()