diff --git a/read_arduino.py b/read_arduino.py index 2b66669..1da243b 100644 --- a/read_arduino.py +++ b/read_arduino.py @@ -44,19 +44,9 @@ def read(): writer.writerow(header) f.close() while True: - #dat_list = np.random.randint(0, v_in * 1000, SENSORS_MAX) # create a randomized voltage data + dat_list = np.random.randint(0, v_in * 1000, SENSORS_MAX) # create a randomized voltage data # take only the nonzero indices, and truncated to two decimal places to "filter" out some hardware errors - #dat_sel = np.trunc((np.take(dat_list, sensor_ports) / 1000) * 10**2) / 10**2 - '''ser = serial.Serial(port) - ser.flushInput() - while True: - try: - ser_bytes = ser.readline() - decoded_bytes = float(ser_bytes[0:len(ser_bytes)-2].decode("utf-8")) - except: - print("Keyboard Interrupt") - break''' - #dat_sel = np.trunc((np.take(decoded_bytes, sensor_ports) / 1000) * 10**2) / 10**2 + dat_sel = np.trunc((np.take(dat_list, sensor_ports) / 1000) * 10**2) / 10**2 r_arr = np.take(refRes, sensor_ports) * (v_in / dat_sel - 1) # *2 <-- change with actual formula for ammonia concentration # created a new array to convert resistance values to sci notation r_arr2 = np.empty(len(r_arr), dtype=object) @@ -91,17 +81,12 @@ def read(): f.close() while controller.isOpen(): try: - #controller.flushInput() read_data = controller.readline().decode("utf-8") # use numpy so it can make list calculations easier (and possibly faster) dat_list = np.asarray(json.loads(read_data), dtype=np.float32)[:SENSORS_MAX] - #ser_bytes = controller.readline() - #decoded_bytes = float(ser_bytes[0:len(ser_bytes)-2].decode("utf-8")) - #dat_sel = np.trunc((np.take(dat_list, sensor_ports) / 1000) * 10**2) / 10**2 dat_sel = np.take(dat_list, sensor_ports) # if we decided to switch back to analogRead(), replace this line of comment to the algorithm to something like the commented line below # dat_sel = np.take(dat_list, sensor_ports) * v_in / resolution - # take only the nonzero indices, and truncated to two decimal places to "filter" out some hardware errors #dat_sel = np.trunc((np.take(dat_list, sensor_ports) / 1000) * 10**2) / 10**2 r_arr = np.take(refRes, sensor_ports) * (v_in / dat_sel - 1) # *2 <-- change with actual formula for ammonia concentration diff --git a/serial_plotter.py b/serial_plotter.py index d6be973..7705388 100644 --- a/serial_plotter.py +++ b/serial_plotter.py @@ -76,18 +76,23 @@ class SerialPlotter: self.sensorsData[i].append(row[i]) # plot a line # round the number to scientific notation - self.axs.plot(self.timeStamps[i],self.sensorsData[i], color=self.colors[i], + self.axs.plot(self.timeStamps[i], self.sensorsData[i], color=self.colors[i], label=f'sensor {i + 1}, latest: {np.format_float_scientific(self.sensorsData[i][-1], precision = 2)} $\Omega$') - self.axs.set_xlabel('Time (seconds)') - self.axs.set_ylabel(u'Resistance ($\Omega$)') + # Make the font size of values placed on x-axis and y-aixs equal to 16 (large enough) + plt.xticks(fontsize = 16) + plt.yticks(fontsize = 16) + + # make the label of two axes large enough + self.axs.set_xlabel('Time (seconds)', fontsize = 15) + self.axs.set_ylabel(u'Resistance ($\Omega$)', fontsize = 15) i += 1 self.timeElapsed += 1 # increment time # Acknowledgement: https://stackoverflow.com/a/13589144 handles, labels = self.axs.get_legend_handles_labels() by_label = dict(zip(labels, handles)) - self.axs.legend(by_label.values(), by_label.keys(), loc='best') + self.axs.legend(by_label.values(), by_label.keys(), loc='best', fontsize = 15) # Make the legend on graph large enough except: traceback.print_exc()