From 81d1b12079781b3e8b675f29fac4bd5291dc8ed2 Mon Sep 17 00:00:00 2001 From: Ryan Xu Date: Sun, 5 Feb 2023 17:51:38 -0800 Subject: [PATCH] integrate the hardware to the software, change the UI and truncate --- read_arduino.py | 24 +++++++++++++++++++----- sealammonia.fbp | 8 ++++---- ui.py | 10 +++++----- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/read_arduino.py b/read_arduino.py index 52c92b7..2b66669 100644 --- a/read_arduino.py +++ b/read_arduino.py @@ -44,9 +44,19 @@ 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 + #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 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) @@ -81,15 +91,19 @@ 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.uint32)[:SENSORS_MAX] - + 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 + #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) diff --git a/sealammonia.fbp b/sealammonia.fbp index 1437921..ca02bd8 100644 --- a/sealammonia.fbp +++ b/sealammonia.fbp @@ -232,7 +232,7 @@ 0 0 wxID_ANY - Resistor 3 + Resistor 2 0 @@ -240,7 +240,7 @@ 0 1 - r3_prompt + r2_prompt 1 @@ -315,7 +315,7 @@ 0 0 wxID_ANY - Resistor 2 + Resistor 3 0 @@ -323,7 +323,7 @@ 0 1 - r2_prompt + r3_prompt 1 diff --git a/ui.py b/ui.py index 40975f1..e3deca0 100644 --- a/ui.py +++ b/ui.py @@ -32,14 +32,14 @@ class Frame ( wx.Frame ): self.r1_prompt = wx.StaticText( ref_entre.GetStaticBox(), wx.ID_ANY, u"Resistor 1", wx.DefaultPosition, wx.DefaultSize, 0 ) self.r1_prompt.Wrap( -1 ) res_grid.Add( self.r1_prompt, 0, wx.ALIGN_BOTTOM|wx.ALIGN_CENTER_HORIZONTAL, 5 ) - - self.r3_prompt = wx.StaticText( ref_entre.GetStaticBox(), wx.ID_ANY, u"Resistor 3", wx.DefaultPosition, wx.DefaultSize, 0 ) - self.r3_prompt.Wrap( -1 ) - res_grid.Add( self.r3_prompt, 0, wx.ALIGN_BOTTOM|wx.ALIGN_CENTER_HORIZONTAL, 5 ) - + self.r2_prompt = wx.StaticText( ref_entre.GetStaticBox(), wx.ID_ANY, u"Resistor 2", wx.DefaultPosition, wx.DefaultSize, 0 ) self.r2_prompt.Wrap( -1 ) res_grid.Add( self.r2_prompt, 0, wx.ALIGN_BOTTOM|wx.ALIGN_CENTER_HORIZONTAL, 5 ) + + self.r3_prompt = wx.StaticText( ref_entre.GetStaticBox(), wx.ID_ANY, u"Resistor 3", wx.DefaultPosition, wx.DefaultSize, 0 ) + self.r3_prompt.Wrap( -1 ) + res_grid.Add( self.r3_prompt, 0, wx.ALIGN_BOTTOM|wx.ALIGN_CENTER_HORIZONTAL, 5 ) self.r4_prompt = wx.StaticText( ref_entre.GetStaticBox(), wx.ID_ANY, u"Resistor 4", wx.DefaultPosition, wx.DefaultSize, 0 ) self.r4_prompt.Wrap( -1 )