/
VoltAnmeter.py
41 lines (38 loc) · 975 Bytes
/
VoltAnmeter.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
import serial
import numpy
import matplotlib.pyplot as plt
from drawnow import *
voltage=[]
amps=[]
arduino = serial.Serial("/dev/ttyACM0", 9600)
plt.pause(1)
plt.ion()
cnt=0
def makegraph():
plt.ylim(0, 300)
plt.title("Sensor Tensão X Corrente")
plt.grid(True)
plt.ylabel('Tensão (V)')
plt.plot(voltage, 'ro-', label = 'Tensão (V)')
plt.legend(loc='upper left')
plt2=plt.twinx()
plt.ylim(0, 2)
plt2.plot(amps, 'b^-', label = 'Corrente (A)')
plt2.set_ylabel('Corrente (A)')
plt2.ticklabel_format(useOffset=False)
plt2.legend(loc='upper right')
while True:
while(arduino.inWaiting()==0):
pass
arduinoString = arduino.readline()
dataArray = arduinoString.decode().split(',')
volt = float(dataArray[0])
amp = float(dataArray[1])
voltage.append(volt)
amps.append(amp)
drawnow(makegraph)
plt.pause(.000001)
cnt = cnt+1
if(cnt>50):
voltage.pop(0)
amps.pop(0)