# 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_()