-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathina260_plot.py
59 lines (45 loc) · 1.44 KB
/
ina260_plot.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
#import thermal_zone
NUM_BUF_POINTS = 180
PLOT_INTERVAL = 1000
Data = None
import board
import adafruit_ina260
i2c = board.I2C()
ina260 = adafruit_ina260.INA260(i2c)
def get_names():
return(['current', 'voltage', 'power'])
def get_values():
return([float("{0:.2f}".format(ina260.current / 1000)), float("{0:.2f}".format(ina260.voltage)), float("{0:.2f}".format(ina260.power / 1000))])
def plot(i):
global Data
zone_names = get_names()
zone_temps = get_values()
print(zone_temps)
Data = np.append(Data, np.array([zone_temps]), axis = 0)
if i >= NUM_BUF_POINTS:
Data = np.delete(Data, 0, axis = 0)
plt.cla()
plt.plot(Data, marker = 'x')
plt.xlim(0, NUM_BUF_POINTS)
plt.ylim(0.0, 10.0)
plt.title('Current Monitor', fontsize = 14)
plt.xlabel('Time', fontsize = 10)
plt.ylabel('Current[A],Voltage[V],Power[W]', fontsize = 10)
plt.tick_params(labelsize=10)
plt.grid(True)
plt.legend(labels = zone_names, loc = 'upper left', fontsize = 10)
def main():
global Data
zone_names = get_names()
print(zone_names)
Data = np.empty((0, len(zone_names)), float)
fig = plt.figure(figsize=(10, 4))
ani = animation.FuncAnimation(fig, plot, fargs = (), interval = PLOT_INTERVAL)
plt.show()
if __name__ == "__main__":
main()