-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgraphingplotter2.py
60 lines (48 loc) · 1.28 KB
/
graphingplotter2.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
import matplotlib.pyplot as plt
import time
import random
from collections import deque
import numpy as np
import datetime
from xbee import XBee,ZigBee
import serial
import time
a1 = deque([0]*100)
ax = plt.axes(xlim=(0, 20), ylim=(0, 10))
line, = plt.plot(a1,linewidth=4)
plt.ion()
plt.ylim([0,100])
plt.show()
PORT = 'your-serial-port'
BAUD_RATE = 9600
# Open serial port
print("about to open serial")
ser = serial.Serial(PORT, BAUD_RATE)
# This creates the graph and will redraw it based on new data that comes through the serial port
def runGraph(i):
# Read a data point from the serial port, this reads 5 characters
try:
item = ser.read(5)
float(item)
# Add the item to the data list
a1.appendleft(item)
except ValueError:
print ("not a float")
return
# Redraw the graph
datatoplot = a1.pop()
line.set_ydata(a1)
plt.draw()
plt.xlabel("Time Passed (Seconds)")
plt.ylabel("Water Level (Meters)")
plt.title("Dynamic Real Time Water Detection Disaster Preventer")
t = datetime.datetime.now().time()
i += 1
time.sleep(0.01)
plt.pause(0.000001)
i = 0
while True:
runGraph(i)
i+=1
ser.close()
# file.close()