From 40a78b81f75e2900af920f77f4c5f88e6ce9d6b3 Mon Sep 17 00:00:00 2001 From: Ryan Xu Date: Sun, 9 Apr 2023 15:55:03 -0700 Subject: [PATCH] add 3.3 - data --- read_arduino.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/read_arduino.py b/read_arduino.py index 1921f63..32a6510 100644 --- a/read_arduino.py +++ b/read_arduino.py @@ -46,6 +46,9 @@ def read(): while True: 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 + # According to the actual req, the data in the data list should be (3.3-data) + for x in range(dat_list.size): + np.put(dat_list, x, 3.3 - dat_list[x]) 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 @@ -84,6 +87,9 @@ def read(): 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] + # According to the actual req, the data in the data list should be (3.3-data) + for x in range(dat_list.size): + np.put(dat_list, x, 3.3 - dat_list[x]) 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