So I am new to pyqtgraph and I need to collect 20 values from a GPIO pin and then update it into a graph. This needs to keep happening repeatedly as fast as possible. I managed to get it to happen on a loop, only problem is a new plot opens every time. Any way of making sure the same plot is reused?
My code is as shown. # Simple example of reading the MCP3008 analog input channels and printing # them all out. import time import os # Import SPI library (for hardware SPI) and MCP3008 library. import Adafruit_GPIO.SPI as SPI import Adafruit_MCP3008 # include RPi libraries in to Python code import RPi.GPIO as GPIO import time from time import sleep ##BELOW ARE STUFF ASSOCIATED WITH THE PLOTTING 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) #-------------------------------------------# pg.setConfigOptions(antialias=True) def updateSensor1(): global newArray, values, data, reshaped 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.05) ##ranArray = np.random ranArray = np.asarray(newArray) data = np.asarray(newArray) print(data) reshaped = np.reshape(data, (20,)) print(reshaped) p6 = pg.PlotWindow(title = "S11") finitecurve = pg.PlotDataItem(reshaped, pen=(255, 255, 0)) p6.addItem(finitecurve) p6.show() timer1 = QtCore.QTimer() timer1.timeout.connect(updateSensor1) timer1.start(50) if __name__ == '__main__': import sys if sys.flags.interactive != 1 or not hasattr(pg.QtCore, 'PYQT_VERSION'): pg.QtGui.QApplication.exec_() Thanks in advance. -- 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 pyqtgraph+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/9e952f1a-7508-45b2-91cb-31d426dab29c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.