Commit dab4b343 authored by Alisson Claudino's avatar Alisson Claudino

Mudança de biblioteca gráfica para PyQtGraph na interface

parent f4fba7f5
import matplotlib.pyplot as plt
import numpy as np
import time
import serial #importacao do modulo serial
import random
leitura =[]
fig, ax = plt.subplots()
ser = serial.Serial('COM6') #abre porta serial COM6
contador = 0
eixo_x = 50
while True:
while (ser.inWaiting()==0):
pass
dados =int( ser.readline()[:-1]) #firmware deve ter um delay de pelo menos 100ms entre cada envio
print dados
ax.clear()
ax.set_xlim([0,eixo_x]) #faixa do eixo horizontal
ax.set_ylim([0,1023]) # faixa do eixo vertical
#leitura.append(random.randint(0,1023)) #teste com numeros aleatorios
leitura.append(dados)
ax.plot(leitura)
plt.pause(.000001)
contador = contador + 1
if (contador > eixo_x):
leitura.pop(0)
ser.close()
from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
import time
import numpy as np
import serial
ser=serial.Serial('/dev/ttyUSB0',115200)
app = QtGui.QApplication([])
win = pg.GraphicsWindow()
p1 = win.addPlot()
curve1 = p1.plot()
readData = [0]
y1=[]
x1=[]
tim=[]
dt=0
t=time.time()
indx = 0
def update():
global curve1, indx, y1,x1,t,dt
dt=time.time()-t
while (ser.inWaiting() == 0):
pass
readData= float(ser.readline())
print(readData)
y1.append(readData)
x1.append(dt)
if indx>50:
y1.pop(0)
x1.pop(0)
indx=0
else:
indx+=1
curve1.setData(x1,y1)
p1.setXRange(0, 100, padding=0)
app.processEvents()
timer = QtCore.QTimer()
timer.timeout.connect(update)
timer.start(0)
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_'):
QtGui.QApplication.instance().exec_()
\ No newline at end of file
......@@ -6,7 +6,7 @@
<h4> Biblioteca HX711 do Arduino (https://github.com/bogde/HX711) </h4>
<h4> Bibliotecas Python: </h4>
<ul>
<li> Matplotlib: https://matplotlib.org/ </li>
<li> PyQtGraph: http://www.pyqtgraph.org/ </li>
<li> Numpy: http://www.numpy.org/ </li>
<li> PySerial: https://github.com/pyserial/pyserial </li>
</ul>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment