From 2eb6c731a43e6bc6ee412bb92e2cff12144058a7 Mon Sep 17 00:00:00 2001 From: Makayla Hu Date: Tue, 23 Jul 2024 16:59:46 -0700 Subject: [PATCH] display units changed to Kelvin --- CollectingData.py | 26 ++++++++++++------------ gui.py | 50 +++++++++++++++++++---------------------------- 2 files changed, 33 insertions(+), 43 deletions(-) diff --git a/CollectingData.py b/CollectingData.py index 2231bca..e23078c 100644 --- a/CollectingData.py +++ b/CollectingData.py @@ -6,7 +6,7 @@ TIME_INCREMENT = 1 #in seconds -test = True +test = False FILENAME = "test.csv" @@ -40,14 +40,23 @@ def updateFile (filename, row): """DATA COLLECTION""" index = count() +def collectData(): + time = next(index) * TIME_INCREMENT + ch1V = random.randint(0,10) + ch1K = random.randint(0,10) + ch2V = random.randint(0,10) + ch2K = random.randint(0,10) + row = [time, ch1V, ch1K, ch2V, ch2K] + updateFile(FILENAME, row) + if (not test): # Connect to the first available Model 240 over USB my_model_240 = Model240() # Define the channel configuration for a sensor with a negative temperature coefficient, autorange disabled # current reversal disabled, the channel enabled, and set to the 100 kOhm range - rtd_config = Model240InputParameter(my_model_240.SensorTypes.NTC_RTD, False, False, my_model_240.Units.SENSOR, True, - my_model_240.InputRange.RANGE_NTCRTD_100_KIL_OHMS) + rtd_config = Model240InputParameter(my_model_240.SensorTypes.DIODE, False, False, my_model_240.Units.KELVIN, True, + my_model_240.InputRange.RANGE_DIODE) # Apply the configuration to all channels for channel in range(1, 3): @@ -63,13 +72,4 @@ def collectData(): ch2K = my_model_240.get_kelvin_reading(2) row = [time, ch1V, ch1K, ch2V, ch2K] - updateFile(FILENAME, row) - -def testCollect(): - time = next(index) * TIME_INCREMENT - ch1V = random.randint(0,10) - ch1K = random.randint(0,10) - ch2V = random.randint(0,10) - ch2K = random.randint(0,10) - row = [time, ch1V, ch1K, ch2V, ch2K] - updateFile(FILENAME, row) \ No newline at end of file + updateFile(FILENAME, row) \ No newline at end of file diff --git a/gui.py b/gui.py index f8e62c9..4f21ea7 100644 --- a/gui.py +++ b/gui.py @@ -37,8 +37,7 @@ def beginCollecting(): def animate(i): """'loop' for data collection""" if (isRunning): - #CollectingData.collectData() - CollectingData.testCollect() + CollectingData.collectData() pullData = open(FILENAME,"r").read() dataList = pullData.split('\n') @@ -55,22 +54,18 @@ def animate(i): timeList.insert(0, float(vals[0])) ch1VList.insert(0, float(vals[1])) ch1KList.insert(0, float(vals[2])) - ch2VList.insert(0, int(vals[3])) - ch2KList.insert(0, int(vals[4])) + ch2VList.insert(0, float(vals[3])) + ch2KList.insert(0, float(vals[4])) plt.clear() - - if (chChoosen.get() == ' Channel 1'): - if (len(ch1KList) > 0 ): - temp.set(str(ch1KList[len(ch1KList)-1]) + "K") - plt.plot(timeList, ch1VList, label="voltage (V)") - plt.plot(timeList, ch1KList, label="temperature (K)") - - if (chChoosen.get() == ' Channel 2'): - if (len(ch2KList) > 0 ): - temp.set(str(ch2KList[len(ch2KList)-1]) + "K") - plt.plot(timeList, ch2VList, label="voltage (V)") - plt.plot(timeList, ch2KList, label="temperature (K)") + + if (len(ch1KList) > 0 ): + temp1.set(str(ch1KList[len(ch1KList)-1]) + "K") + temp2.set(str(ch2KList[len(ch2KList)-1]) + "K") + #plt.plot(timeList, ch1VList, label="voltage (V)") + plt.plot(timeList, ch1KList, label="Ch1 temperature (K)") + #plt.plot(timeList, ch2VList, label="voltage (V)") + plt.plot(timeList, ch2KList, label="Ch2 temperature (K)") plt.legend(loc="upper right") @@ -97,20 +92,15 @@ def clickButton(): """TEMPERATURE LABEL""" -temp = tk.StringVar() -temp.set("0.0K") -tempLabel = tk.Label(window, textvariable=temp, bd=0, font=("Arial", 40), bg="white") -tempLabel.place(x=500, y=20) - - -"""COMBOBOX FOR SELECTING CHANNEL""" -chLabel = tk.Label(window, text="Channel:", font=("Arial", 10), bg="white") -chLabel.place(x=190, y=25) -n = tk.StringVar() -chChoosen = ttk.Combobox(window, width=27, textvariable=n) -chChoosen['values'] = (' Channel 1', ' Channel 2') -chChoosen.current(0) -chChoosen.place(x=250, y=25) +temp1 = tk.StringVar() +temp1.set("0.0K") +temp1Label = tk.Label(window, textvariable=temp1, bd=0, font=("Arial", 40), bg="white") +temp1Label.place(x=200, y=20) + +temp2 = tk.StringVar() +temp2.set("0.0K") +temp2Label = tk.Label(window, textvariable=temp2, bd=0, font=("Arial", 40), bg="white") +temp2Label.place(x=450, y=20) ani = animation.FuncAnimation(f, animate, interval = 1000 * TIME_INCREMENT, cache_frame_data=False)