<https://lh3.googleusercontent.com/-TiQCy8w7klw/WnLL5F8F0-I/AAAAAAAAX3Y/eZeMXhOPsN8nUYBjh5W_darBTnxjW0zdACLcBGAs/s1600/2018-01-23-070917_1824x984_scrot.png>
Hey,
I recently got to know about pyqtgraph and I simply love it. I am making a
project that involves taking 20 readings from a GPIO and then plotting then
on a graph. This needs to happen repeatedly. I used fragments from the
example code plotting.py given in the examples folder and the code used to
collect GPIO data. It is shown below.
import time
import os
import Adafruit_GPIO.SPI as SPI
import Adafruit_MCP3008
import RPi.GPIO as GPIO
import time
from time import sleep
##BELOW ARE STUFF ASSOCIATED WITH THE PLOTTING
import initExample ## Add path to library (just for examples; you do not
need this)
from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
#-------------------------------------------#
# Software SPI configuration:
#CLK = 18
#MISO = 23
#MOSI = 24
#CS = 25
#mcp = Adafruit_MCP3008.MCP3008(clk=CLK, cs=CS, miso=MISO, mosi=MOSI)
# Hardware SPI configuration:
SPI_PORT = 0
SPI_DEVICE = 0
mcp = Adafruit_MCP3008.MCP3008(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))
#QtGui.QApplication.setGraphicsSystem('raster')
app = QtGui.QApplication([])
#mw = QtGui.QMainWindow()
#mw.resize(800,800)
#-------------------------------------------#
win = pg.GraphicsWindow(title="Basic plotting examples")
win.resize(1000,600)
win.setWindowTitle('pyqtgraph example: Plotting')
# Enable antialiasing for prettier plots
pg.setConfigOptions(antialias=True)
newArray = []
for x in range(20):
values = [0]*8
#for i in range(8):
#The read_adc function will get the value of the specified channel
(0-7).
values[0] = mcp.read_adc(0)
# Print the ADC values.
print('Current value is')
print(values[0])
newArray.append([values[0]])
print(newArray)
time.sleep(0.5)
##ranArray = np.random
ranArray = np.asarray(newArray)
print(ranArray)
p6 = win.addPlot(title="S11")
curve = p6.plot(pen='w')
data = np.asarray(newArray)
##.normal(size=(20,20))
ptr = 0
def update():
global curve, data, ptr, p6
curve.setData(data[ptr%10])
if ptr == 0:
p6.enableAutoRange('xy', False) ## stop auto-scaling after the
first data set is plotted
ptr += 1
print(data)
timer = QtCore.QTimer()
timer.timeout.connect(update)
timer.start(1000) #1000 = 1 second
## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
This code will show the data getting appended into an array, but then show
a blank graph.
<https://lh3.googleusercontent.com/-TiQCy8w7klw/WnLL5F8F0-I/AAAAAAAAX3Y/eZeMXhOPsN8nUYBjh5W_darBTnxjW0zdACLcBGAs/s1600/2018-01-23-070917_1824x984_scrot.png>
I think it has to do with the data type that is plotted?
--
You received this message because you are subscribed to the Google Groups
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyqtgraph/c523205c-2700-419b-ba92-b45ac79071cb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.