diff --git a/read_arduino.py b/read_arduino.py index a482891..58d4dea 100644 --- a/read_arduino.py +++ b/read_arduino.py @@ -23,6 +23,7 @@ def read(): file_name = settings["file_name"] port = settings["port"] delay = settings["delay"] + if np.any(sensor_ports >= SENSORS_MAX): raise ValueError("Port range is 0-3!") @@ -46,9 +47,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) + # According to the actual req, the data in the data list should be (v_in-data) for x in range(dat_list.size): - np.put(dat_list, x, 3.3 - dat_list[x]) + np.put(dat_list, x, v_in - 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 @@ -88,9 +89,9 @@ def read(): print(read_data) # Debug # 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) + # According to the actual req, the data in the data list should be (votage-data) for x in range(dat_list.size): - np.put(dat_list, x, 3.3 - dat_list[x]) + np.put(dat_list, x, v_in - 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