-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph_Main.py
More file actions
63 lines (53 loc) · 1.57 KB
/
Copy pathGraph_Main.py
File metadata and controls
63 lines (53 loc) · 1.57 KB
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
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import style
import numpy as np
import random
import serial
# initialize serial port
serialPort = serial.Serial(port="COM3", baudrate=115200, bytesize=8, timeout=10, stopbits=serial.STOPBITS_ONE)
serialString = "" # Used to hold data coming over UART
count = 0
NUM_CELLS = 15
# ser = serial.Serial()
# ser.port = '/dev/ttyACM0' # Arduino serial port
# ser.baudrate = 9600
# ser.timeout = 10 # specify timeout when using readline()
# ser.open()
# if ser.is_open == True:
# print("\nAll right, serial port now open. Configuration:\n")
# print(ser, "\n") # print serial parameters
# Create figure for plotting
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
xs = [] # store trials here (n)
yData = [ []*1 for i in range(NUM_CELLS)]
ys = [] # store relative frequency here
y1s =[]
y2s =[]
y3s =[]
y4s =[]
y5s =[]
i=0
# This function is called periodically from FuncAnimation
def animate(i, xs, ys):
# Aquire and parse data from serial port
i+=0.1
cells = []
cells = [0 for i in range(15)]
for j in range(15):
rawData = serialPort.read(5)
cells[j] = rawData.decode('Ascii')
endBits1 = serialPort.read(2)
# Add x and y to lists
xs.append(i)
for ii in range(15):
yData[ii].append(cells[ii])
ax.clear()
for jj in range(15):
ax.plot(xs, yData[jj], label="Cell Voltage")
plt.title('Cell Voltage')
plt.ylabel('Voltage')
plt.legend()
ani = animation.FuncAnimation(fig, animate, fargs=(xs, ys), interval=100)
plt.show()