Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. from pyqtgraph.Qt import QtGui, QtCore
  5. import numpy as np
  6. import pyqtgraph as pg
  7. from pyqtgraph.ptime import time
  8. import serial
  9.  
  10. app = QtGui.QApplication([])
  11.  
  12. p = pg.plot()
  13. p.setWindowTitle('live plot from serial')
  14. curve = p.plot()
  15.  
  16. data = [0]
  17. raw=serial.Serial("/dev/ttyACM0",9600)
  18. raw.open()
  19.  
  20. def update():
  21. global curve, data
  22. line = raw.readline()
  23. data.append(int(line))
  24. xdata = np.array(data, dtype='float64')
  25. curve.setData(xdata)
  26. app.processEvents()
  27.  
  28. timer = QtCore.QTimer()
  29. timer.timeout.connect(update)
  30. timer.start(0)
  31.  
  32. if __name__ == '__main__':
  33. import sys
  34. if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
  35. QtGui.QApplication.instance().exec_()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement