forked from harvie256/MaynuoPy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIV_plot_w_matplotlib_test.py
58 lines (49 loc) · 1.59 KB
/
IV_plot_w_matplotlib_test.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
#-------------------------------------------------------------------------------
# Name: IV ploting test script for Maynuo eload using Matplotlib
# Purpose:
#
# Author: Derryn Harvie
#
# Created: 16/04/2014
# Licence: Public Domain
#-------------------------------------------------------------------------------
import Maynuo, time, sys
import matplotlib.pyplot as plt
def main():
startCurrent = 0.0
stopCurrent = 4.60
stepCurrent = 0.01
stepDelayTime = 0.5
testCurrent = startCurrent
I_List = []
V_List = []
load = Maynuo.Maynuo(19,57600,1)
load.setCCurrent(testCurrent)
load.setInputOn()
time.sleep(stepDelayTime)
print('System Test')
print('Time (ms), Voltage (V), Current (A)')
while(1):
# get the operating point and write out
opPoint = load.getOperatingPoint()
I_List.append(opPoint.getCurrent())
V_List.append(opPoint.getVoltage())
sys.stdout.write(str(int(round(time.time() * 1000))) + ', ')
sys.stdout.write("{0:.4f}".format(opPoint.getVoltage()) + ', ')
print("{0:.4f}".format(opPoint.getCurrent()))
# step the current and test for ending
testCurrent += stepCurrent
if(testCurrent > stopCurrent):
break
load.setCCurrent(testCurrent)
time.sleep(stepDelayTime)
load.setInputOff()
print('IV sweep complete')
plt.plot(I_List,V_List,'r-')
plt.title('85W magsafe charger (18.5V @ 4.6A rated)')
plt.xlabel('Current (A)')
plt.ylabel('Voltage (V)')
plt.grid(True)
plt.show()
if __name__ == '__main__':
main()