From 978bf6f6edad35df4e05043b80110856b9f87434 Mon Sep 17 00:00:00 2001 From: Patrick Chwalek Date: Sun, 6 Nov 2022 15:50:43 -0500 Subject: [PATCH 01/10] added code to skip day if power loss during task and to skip multiple days if blackout longer than 1 day --- .../MicroPET_Launch_code.ino | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino b/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino index 42f10ea..751f857 100644 --- a/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino +++ b/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino @@ -521,19 +521,25 @@ void recoverSystemStart(){ /* (1) check for hard faults */ // (1.1) if system failed during an experiment, generate fault if(systemStateStructVar.testDayComplete != 1){ - Serial.println("System was interrupted during an experiment! No way to resume!"); - while(1); - return; + Serial.print("System was interrupted during experiment: "); + Serial.println(systemStateStructVar.testDay); } // (1.2) if system paused for longer than test day interval, generate fault uint32_t timeSinceLastExperiment = rtc.now().unixtime() - systemStateStructVar.epoch; + uint16_t skipDays; if(timeSinceLastExperiment >= DELAY_SECONDS_PER_EXPERIMENT){ - Serial.println("System was off for longer than experiment interval! No way to resume!"); - while(1); - return; + Serial.println("System was off for longer than experiment interval!"); + + skipDays = int( timeSinceLastExperiment / DELAY_SECONDS_PER_EXPERIMENT ); + for(int i = 0; i < skipDays; i++){ + systemStateStructVar.testDay++; + Serial.print(" Skipping day: "); + Serial.println(systemStateStructVar.testDay); + } } + timeSinceLastExperiment = int( timeSinceLastExperiment % DELAY_SECONDS_PER_EXPERIMENT ); // (1.3) check if tests had already ended if(systemStateStructVar.testDay == TOTAL_EXPERIMENTS - 1){ Serial.println("Power failure occured after experiment finished! No reason to resume!"); From f933194f9246dac047d9a5286593db56006a48df Mon Sep 17 00:00:00 2001 From: Patrick Chwalek Date: Sun, 6 Nov 2022 16:05:58 -0500 Subject: [PATCH 02/10] added SD card power failure logging --- Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino b/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino index 751f857..3d93328 100644 --- a/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino +++ b/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino @@ -523,6 +523,7 @@ void recoverSystemStart(){ if(systemStateStructVar.testDayComplete != 1){ Serial.print("System was interrupted during experiment: "); Serial.println(systemStateStructVar.testDay); + saveExperimentalLog("System was interrupted during experiment: " + String(systemStateStructVar.testDay)); } // (1.2) if system paused for longer than test day interval, generate fault @@ -536,6 +537,8 @@ void recoverSystemStart(){ systemStateStructVar.testDay++; Serial.print(" Skipping day: "); Serial.println(systemStateStructVar.testDay); + + saveExperimentalLog(" Skipping day: " + String(systemStateStructVar.testDay)); } } @@ -543,6 +546,9 @@ void recoverSystemStart(){ // (1.3) check if tests had already ended if(systemStateStructVar.testDay == TOTAL_EXPERIMENTS - 1){ Serial.println("Power failure occured after experiment finished! No reason to resume!"); + + saveExperimentalLog("Power failure occured after experiment finished! No reason to resume!"); + while(1); return; } From 8e59023a6f261b5d359a058532ed9d0b49f33d60 Mon Sep 17 00:00:00 2001 From: Patrick Chwalek Date: Mon, 7 Nov 2022 12:11:33 -0500 Subject: [PATCH 03/10] added code if day 1 is interrupted, restart day_1 --- Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino b/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino index 3d93328..e79a2aa 100644 --- a/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino +++ b/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino @@ -524,6 +524,13 @@ void recoverSystemStart(){ Serial.print("System was interrupted during experiment: "); Serial.println(systemStateStructVar.testDay); saveExperimentalLog("System was interrupted during experiment: " + String(systemStateStructVar.testDay)); + + if(systemStateStructVar.testDay == 1){ + Serial.print("Restarting entire experiment since lost power on day 1"); + saveExperimentalLog("Restarting entire experiment since lost power on day 1"); + day_1(); + return; + } } // (1.2) if system paused for longer than test day interval, generate fault From c45e4b44cc7400d9423394508510032fd271ee7c Mon Sep 17 00:00:00 2001 From: Patrick Chwalek Date: Mon, 7 Nov 2022 12:14:10 -0500 Subject: [PATCH 04/10] added systemState boolean toggle --- Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino b/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino index e79a2aa..2b247da 100644 --- a/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino +++ b/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino @@ -529,6 +529,7 @@ void recoverSystemStart(){ Serial.print("Restarting entire experiment since lost power on day 1"); saveExperimentalLog("Restarting entire experiment since lost power on day 1"); day_1(); + systemState = true; return; } } @@ -572,6 +573,8 @@ void recoverSystemStart(){ // } Serial.println("System has recovered gracefully!"); + + systemState = true; } From f3c3ac03dedf9155df62f32db795b4f6abd2acae Mon Sep 17 00:00:00 2001 From: pat pataranutaporn Date: Tue, 8 Nov 2022 09:47:32 -0600 Subject: [PATCH 05/10] finish the dummy code --- .DS_Store | Bin 10244 -> 10244 bytes Teensey Code/.DS_Store | Bin 12292 -> 12292 bytes .../MicroPET_Launch_code.ino | 29 ++++++++---------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/.DS_Store b/.DS_Store index 4cf95a961c4bf3c78477898b04f76f1cd4268314..5331ff2b652fe5f238ff9d6e2ab47e151f2cc362 100644 GIT binary patch delta 56 zcmZn(XbITRBh0vKa<6b9w^Vhtk)@fAf}ye5WOfl*#-7QJLh_8glM7^IHYbWK;oi)y M@QY>he-UP8000~jng9R* delta 45 zcmZn(XbITRBRsiUpp?zRTt~s&a5ATe>||j Date: Tue, 8 Nov 2022 16:30:39 -0600 Subject: [PATCH 06/10] Update day test function + comments --- .../MicroPET_Launch_code.ino | 92 ++++++++++--------- Teensey Code/move_liquid/move_liquid.ino | 50 +++++++++- 2 files changed, 93 insertions(+), 49 deletions(-) diff --git a/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino b/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino index 5162285..2e311d5 100644 --- a/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino +++ b/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino @@ -612,6 +612,8 @@ bool checkForStartSerialCommand() { //Print the message (or do other things) Serial.println("Executing Test Script"); + + day_functionTest(); } @@ -624,18 +626,14 @@ bool checkForStartSerialCommand() { } void day_functionTest(){ - - // DUMMY TASK - - //EXP1 - moveLiquid (experimentOne, e_buffer, chamberA, 2000); //buffer to chamber A - 2 ml (flexible) + //EXP2 - moveLiquid (experimentTwo, e_buffer, chamberA, 2000); //buffer to chamber A - 2 ml (flexible) - -Serial.println("revival pumping..."); -motorSensorBrdCtrl(1, forward); -delay (5000); -motorSensorBrdCtrl(1, halt); + Serial.println("EXP2 revival pumping..."); + saveExperimentalLog("EXP2 revived"); + switchCollection(experimentTwo, waste);//back to waste bag + motorSensorBrdCtrl(1, forward); + delay (5000); //~10ML + motorSensorBrdCtrl(1, halt); } @@ -669,7 +667,7 @@ void day_1() { //DUMMY CODE moveLiquid (experimentOne, e_buffer, chamberA, 1000); //buffer to chamber A - 1 ml (flexible) moveLiquid (experimentTwo, e_buffer, chamberA, 1000); //buffer to chamber A - 1 ml (flexible) - Serial.println("finish the summy code..."); + Serial.println("finish the dummy code..."); saveExperimentalLog("Finish dummy code!"); //EXP1 - liquid in dummy code @@ -1786,15 +1784,15 @@ void moveLiquid(int experiment, int origin, int target, float liquid_volume) if (experiment == 1 && origin == 0) { switch_conn_pin(BASEBD_J10_PIN2, LOW); //Experiment 1 valveA - Serial.println("_E1_exp1 move from e_buffer"); - saveExperimentalLog("_E1_move from e_buffer"); + Serial.println("E1_exp1 move from e_buffer"); + saveExperimentalLog("E1_move from e_buffer"); } if (experiment == 1 && origin == 1) { switch_conn_pin(BASEBD_J10_PIN2, HIGH); //Experiment 1 valveA - Serial.println("_E1 move from enzyme"); - saveExperimentalLog("_E1_move from enzyme"); + Serial.println("E1 move from enzyme"); + saveExperimentalLog("E1_move from enzyme"); } if (experiment == 1 && target == 2) @@ -1802,7 +1800,7 @@ void moveLiquid(int experiment, int origin, int target, float liquid_volume) switch_conn_pin(BASEBD_J9_PIN2, HIGH); //Experiment 1 valveB high, waste line open int move_pulse = liquid_volume / 25; //1ml = 1000uL and the pump moves 25uL at a time Serial.println("move to chamberA"); - saveExperimentalLog("exp1_move to chamberA" + String(move_pulse * 25) + "uL"); + saveExperimentalLog("E1_move to chamberA" + String(move_pulse * 25) + "uL"); for (int i = 0; i <= move_pulse; i++) { switch_conn_pin(BASEBD_J10_PIN4, HIGH); //Experiment 1 pumpA digitalWrite(LED, HIGH); @@ -1811,6 +1809,7 @@ void moveLiquid(int experiment, int origin, int target, float liquid_volume) digitalWrite(LED, LOW); delay(200); Serial.println( i * 25); //print out the moving volume + saveExperimentalLog("STEP_exp1_move to chamberA" + String(i * 25) + "uL"); } switch_conn_pin(BASEBD_J10_PIN2, LOW); //Reset eperiment 1 valveA so enzyme is blocked } @@ -1840,8 +1839,8 @@ void moveLiquid(int experiment, int origin, int target, float liquid_volume) if (experiment == 1 && origin == 3 && target == 4) { int move_pulse = liquid_volume / 25; //1ml = 1000uL and the pump moves 25uL at a time - Serial.println("_E1 move to chamberB"); - saveExperimentalLog("_E1_move to chamberB " + String(move_pulse * 25) + "uL"); + Serial.println("E1 move to chamberB"); + saveExperimentalLog("E1_move to chamberB " + String(move_pulse * 25) + "uL"); for (int i = 0; i <= move_pulse; i++) { switch_conn_pin(BASEBD_J9_PIN4, HIGH); //Experiment 1 pumpB digitalWrite(LED, HIGH); @@ -1850,6 +1849,7 @@ void moveLiquid(int experiment, int origin, int target, float liquid_volume) digitalWrite(LED, LOW); delay(200); Serial.println( i * 25); //print out the moving volume + saveExperimentalLog("STEP_E1_move to chamberB " + String(i * 25) + "uL"); } // switch_conn_pin(BASEBD_J9_PIN2, LOW); //Reset experiment 1 valveB so chamberA is blocked } @@ -1859,23 +1859,23 @@ void moveLiquid(int experiment, int origin, int target, float liquid_volume) if (experiment == 2 && origin == 0) { switch_conn_pin(BASEBD_J12_PIN2, LOW); //Experiment 2 valveA - Serial.println("_E2 move from e_buffer"); - saveExperimentalLog("_E2_move from e_buffer"); + Serial.println("E2 move from e_buffer"); + saveExperimentalLog("E2_move from e_buffer"); } if (experiment == 2 && origin == 1) { switch_conn_pin(BASEBD_J12_PIN2, HIGH); //Experiment 2 valveA - saveExperimentalLog("_E2_move from enzyme"); - Serial.println("_E2 move from Enzyme"); + saveExperimentalLog("E2_move from enzyme"); + Serial.println("E2 move from Enzyme"); } if (experiment == 2 && target == 2) { switch_conn_pin(BASEBD_J11_PIN2, HIGH); //Experiment 2 valveB high, waste line open int move_pulse = liquid_volume / 25; //1ml = 1000uL and the pump moves 25uL at a time - Serial.println("_E2 move to chamberA"); - saveExperimentalLog("_E2_move to chamberA " + String(move_pulse * 25) + "uL"); + Serial.println("E2 move to chamberA"); + saveExperimentalLog("E2_move to chamberA " + String(move_pulse * 25) + "uL"); for (int i = 0; i <= move_pulse; i++) { switch_conn_pin(BASEBD_J12_PIN4, HIGH); //Experiment 2 pumpA digitalWrite(LED, HIGH); @@ -1884,6 +1884,7 @@ void moveLiquid(int experiment, int origin, int target, float liquid_volume) digitalWrite(LED, LOW); delay(200); Serial.println( i * 25); + saveExperimentalLog("STEP_E2_move to chamberA " + String(i * 25) + "uL"); } switch_conn_pin(BASEBD_J12_PIN2, LOW); //Reset xperiment 1 valveA so enzyme is blocked } @@ -1914,8 +1915,8 @@ void moveLiquid(int experiment, int origin, int target, float liquid_volume) if (experiment == 2 && origin == 3 && target == 4) { int move_pulse = liquid_volume / 25; //1ml = 1000uL and the pump moves 35uL at a time - Serial.println("_E2 media move to chamberB"); - saveExperimentalLog("_E2_media_move to chamberB " + String(move_pulse * 25) + "uL"); + Serial.println("E2 media move to chamberB"); + saveExperimentalLog("E2_media_move to chamberB " + String(move_pulse * 25) + "uL"); for (int i = 0; i <= move_pulse; i++){ switch_conn_pin(BASEBD_J11_PIN4, HIGH); //Experiment 2 pumpB digitalWrite(LED, HIGH); @@ -1924,6 +1925,7 @@ void moveLiquid(int experiment, int origin, int target, float liquid_volume) digitalWrite(LED, LOW); delay(200); Serial.println( i * 25); + saveExperimentalLog("STEP_E2_media_move to chamberB " + String(i * 25) + "uL"); } } } @@ -1933,23 +1935,23 @@ void switchCollection(int experiment, int bag) if (experiment == 1 && bag == 0) { switch_conn_pin(BASEBD_J5_PIN4, LOW); //Experiment 1 waste V6 - Serial.println("exp1 open waste bag"); - saveExperimentalLog("exp1_opem waste bag"); + Serial.println("E1 open waste bag"); + saveExperimentalLog("E1_opem waste bag"); } if (experiment == 1 && bag == 1) { switch_conn_pin(BASEBD_J5_PIN4, HIGH); //NOT V6 switch_conn_pin(BASEBD_J5_PIN2, LOW); //Experiment 1 preservativeOne V5 - Serial.println("exp1 open preservativeOne bag"); - saveExperimentalLog("exp1_open preservativeOne bag"); + Serial.println("E1 open preservativeOne bag"); + saveExperimentalLog("E1_open preservativeOne bag"); } if (experiment == 1 && bag == 2) { switch_conn_pin(BASEBD_J5_PIN4, HIGH); //NOT V6 switch_conn_pin(BASEBD_J5_PIN2, HIGH); //NOT V5 switch_conn_pin(BASEBD_J3_PIN4, LOW); ////Experiment 1 preservativeTwo V4 - Serial.println("exp1 open preservativeTwo bag"); - saveExperimentalLog("exp1_open preservativeTwo bag"); + Serial.println("E1 open preservativeTwo bag"); + saveExperimentalLog("E1_open preservativeTwo bag"); } if (experiment == 1 && bag == 3) { @@ -1958,7 +1960,7 @@ void switchCollection(int experiment, int bag) switch_conn_pin(BASEBD_J3_PIN4, HIGH); //NOT V4 switch_conn_pin(BASEBD_J3_PIN2, LOW); //Experiment 1 preservativeThree V3 Serial.println("open preservativeThree bag"); - saveExperimentalLog("exp1_open preservativeThree bag"); + saveExperimentalLog("E1_open preservativeThree bag"); } if (experiment == 1 && bag == 4) { @@ -1967,7 +1969,7 @@ void switchCollection(int experiment, int bag) switch_conn_pin(BASEBD_J3_PIN4, HIGH); //NOT V4 switch_conn_pin(BASEBD_J3_PIN2, HIGH); //NOT V3 switch_conn_pin(BASEBD_J1_PIN4, LOW); //Experiment 1 preservativeFour V2 - Serial.println("open preservativeFour bag"); + Serial.println("E1_open preservativeFour bag"); } //experiment two collection @@ -1975,23 +1977,23 @@ void switchCollection(int experiment, int bag) if (experiment == 2 && bag == 0) { switch_conn_pin(BASEBD_J2_PIN2, LOW); //Experiment 2 waste V7 - Serial.println("exp2 open waste bag"); - saveExperimentalLog("exp2_opem waste bag"); + Serial.println("E2 open waste bag"); + saveExperimentalLog("E2_opem waste bag"); } if (experiment == 2 && bag == 1) { switch_conn_pin(BASEBD_J2_PIN2, HIGH); //NOT V7 switch_conn_pin(BASEBD_J2_PIN4, LOW); //Experiment 2 preservativeOne V8 - Serial.println("exp2 open preservativeOne bag"); - saveExperimentalLog("exp2_open preservativeOne bag"); + Serial.println("E2 open preservativeOne bag"); + saveExperimentalLog("E2_open preservativeOne bag"); } if (experiment == 2 && bag == 2) { switch_conn_pin(BASEBD_J2_PIN2, HIGH); //NOT V7 switch_conn_pin(BASEBD_J2_PIN4, HIGH); //NOT V8 switch_conn_pin(BASEBD_J4_PIN2, LOW); ////Experiment 2 preservativeTwo V9 - Serial.println("exp2 open preservativeTwo bag"); - saveExperimentalLog("exp2_open preservativeTwo bag"); + Serial.println("E2 open preservativeTwo bag"); + saveExperimentalLog("E2_open preservativeTwo bag"); } if (experiment == 2 && bag == 3) { @@ -1999,8 +2001,8 @@ void switchCollection(int experiment, int bag) switch_conn_pin(BASEBD_J2_PIN4, HIGH); //NOT V8 switch_conn_pin(BASEBD_J4_PIN2, HIGH); //NOT V9 switch_conn_pin(BASEBD_J4_PIN4, LOW); //Experiment 2 preservativeThree V10 - Serial.println("open preservativeThree bag"); - saveExperimentalLog("exp2_open preservativeThree bag"); + Serial.println("E2_open preservativeThree bag"); + saveExperimentalLog("E2_open preservativeThree bag"); } if (experiment == 2 && bag == 4) { @@ -2009,8 +2011,8 @@ if (experiment == 2 && bag == 4) switch_conn_pin(BASEBD_J4_PIN2, HIGH); //NOT V9 switch_conn_pin(BASEBD_J4_PIN4, HIGH); //NOT V10 switch_conn_pin(BASEBD_J6_PIN2, LOW); //Experiment 2 preservativeFour V11 - Serial.println("open preservativeFour bag"); - saveExperimentalLog("exp2_open preservativeFour bag"); + Serial.println("E2_open preservativeFour bag"); + saveExperimentalLog("E2_open preservativeFour bag"); } } diff --git a/Teensey Code/move_liquid/move_liquid.ino b/Teensey Code/move_liquid/move_liquid.ino index d645cab..db5e48a 100644 --- a/Teensey Code/move_liquid/move_liquid.ino +++ b/Teensey Code/move_liquid/move_liquid.ino @@ -202,16 +202,58 @@ void setup() { int stop_move = 0; +//CHAM A + +//moveLiquid (experimentOne, enzyme, chamberA, 10000); +//moveLiquid (experimentOne, e_buffer, chamberA, 10000); +//moveLiquid (experimentTwo, enzyme, chamberA, 10000); +//moveLiquid (experimentTwo, e_buffer, chamberA, 10000); + +//CHAM B EXP 1 + +//switchCollection(experimentOne, waste); +//moveLiquid (experimentOne, media, chamberB, 10000); + +//switchCollection(experimentOne, preservativeOne); +//moveLiquid (experimentOne, media, chamberB, 10000); + +//switchCollection(experimentOne, preservativeTwo); +//moveLiquid (experimentOne, media, chamberB, 10000); + + +//switchCollection(experimentOne, preservativeThree); +//moveLiquid (experimentOne, media, chamberB, 10000); + +//switchCollection(experimentOne, preservativeFour); +//moveLiquid (experimentOne, media, chamberB, 10000); + +//CHAM B EXP 2 + +//switchCollection(experimentTwo, waste); +//moveLiquid (experimentTwo, media, chamberB, 10000); + +//switchCollection(experimentTwo, preservativeOne); +//moveLiquid (experimentTwo, media, chamberB, 10000); + +//switchCollection(experimentTwo, preservativeTwo); +//moveLiquid (experimentTwo, media, chamberB, 10000); + +//switchCollection(experimentTwo, preservativeThree); +//moveLiquid (experimentTwo, media, chamberB, 10000); + +switchCollection(experimentTwo, preservativeFour); +moveLiquid (experimentTwo, media, chamberB, 10000); } void loop() { +//moveLiquid (experimentTwo, enzyme, chamberA, 5000); - Serial.println("revival pumping..."); - motorSensorBrdCtrl(1, forward); - delay (5000); - motorSensorBrdCtrl(1, halt); +// Serial.println("revival pumping..."); +// motorSensorBrdCtrl(1, forward); +// delay (5000); +// motorSensorBrdCtrl(1, halt); //Experiment1 liquid system cleaning // moveLiquid (experimentOne, e_buffer, chamberA, 50); From 184dd94f690fa4cc254f7e3b7d0870a205d366bc Mon Sep 17 00:00:00 2001 From: pat pataranutaporn Date: Tue, 8 Nov 2022 16:40:00 -0600 Subject: [PATCH 07/10] fix second in day --- .DS_Store | Bin 10244 -> 10244 bytes Teensey Code/.DS_Store | Bin 12292 -> 12292 bytes .../MicroPET_Launch_code.ino | 4 ++-- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.DS_Store b/.DS_Store index 5331ff2b652fe5f238ff9d6e2ab47e151f2cc362..2b4c2bb9e0f2b2cc37160e6fcb6a7642f027ea4a 100644 GIT binary patch delta 77 zcmZn(XbIR*EiiexU@5zyv5tbFf%#-k5!uNOLMoHZ1)s7Tn!v?2I|%tOVpV7$EV(&Z HWT7wsPSg~t delta 133 zcmZn(XbIR*Ex@>Aa-VRaxdZ7nBP<{cbQCO%O(u(r7;jD$(qLrV1u~Xfs=C_9 d(hR81*laSVh%93d*nr;2dcrcBlSLK^0|4;gB#r<8 diff --git a/Teensey Code/.DS_Store b/Teensey Code/.DS_Store index 2f270885c2e85f27b6d6e08845e2146cadfe4dac..bfc9c4641d9136515d78309ef1ea70f6137b3abd 100644 GIT binary patch delta 50 zcmZokXi3;`RbcWW Date: Tue, 8 Nov 2022 16:57:25 -0600 Subject: [PATCH 08/10] Clear Day Function --- .../MicroPET_Launch_code/MicroPET_Launch_code.ino | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino b/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino index 7525f66..cf87179 100644 --- a/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino +++ b/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino @@ -627,14 +627,12 @@ bool checkForStartSerialCommand() { void day_functionTest(){ - //EXP2 - Serial.println("EXP2 revival pumping..."); - saveExperimentalLog("EXP2 revived"); - switchCollection(experimentTwo, waste);//back to waste bag - motorSensorBrdCtrl(1, forward); - delay (5000); //~10ML - motorSensorBrdCtrl(1, halt); - + /////DAYFUNCTION + + /////DAYFUNCTION + + /////DAYFUNCTION + } From c9ac1959a5756ad39ff693e2593bfc93d29471e9 Mon Sep 17 00:00:00 2001 From: pat pataranutaporn Date: Thu, 10 Nov 2022 17:13:34 -0600 Subject: [PATCH 09/10] FINAL LOAD CODE TO GO TO SPACE --- Teensey Code/.DS_Store | Bin 12292 -> 12292 bytes .../MicroPET_Launch_code.ino | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Teensey Code/.DS_Store b/Teensey Code/.DS_Store index bfc9c4641d9136515d78309ef1ea70f6137b3abd..475e69de2a0cf2d08f323029f0c59c1e42318e1e 100644 GIT binary patch delta 19 acmZokXi3=MEy!l6qhM%gxj9g9vm5|E>;>Tf delta 19 acmZokXi3=MEy!l9qhM%YzBy2Evm5|Emj&1W diff --git a/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino b/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino index cf87179..a7e4d8b 100644 --- a/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino +++ b/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino @@ -453,10 +453,10 @@ void rtcInit() { Serial.println("RTC is NOT initialized, let's set the time!"); // When time needs to be set on a new device, or after a power loss, the // following line sets the RTC to the date & time this sketch was compiled - rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); + //rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // This line sets the RTC with an explicit date & time, for example to set // January 21, 2014 at 3am you would call: - // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0)); + // rtc.adjust(DateTime(2022, 11, 10, 2, 3, 3)); // // Note: allow 2 seconds after inserting battery or applying external power // without battery before calling adjust(). This gives the PCF8523's From 55dc16c6f602f80cd0abca0a220d55b8b89fc20a Mon Sep 17 00:00:00 2001 From: pat pataranutaporn Date: Sat, 1 Jul 2023 10:46:52 -0400 Subject: [PATCH 10/10] Clean up the code --- .DS_Store | Bin 10244 -> 8196 bytes Teensey Code/mux_multi_sensor.zip | Bin 2843 -> 0 bytes archive/.DS_Store | Bin 0 -> 10244 bytes {Python => archive/Python}/.idea/.gitignore | 0 {Python => archive/Python}/.idea/Python.iml | 0 .../inspectionProfiles/profiles_settings.xml | 0 {Python => archive/Python}/.idea/misc.xml | 0 {Python => archive/Python}/.idea/modules.xml | 0 {Python => archive/Python}/.idea/vcs.xml | 0 {Python => archive/Python}/main.py | 0 .../Teensey Code}/.DS_Store | Bin 12292 -> 12292 bytes .../Teensey Code}/Clock_test/Clock_test.ino | 0 .../MicroPET_DressRehearsal_202202/.DS_Store | Bin .../MicroPET_DressRehearsal_202202.ino | 0 .../MicroPET_DressRehearsal_202204/.DS_Store | Bin .../MicroPET_DressRehearsal_202204.ino | 0 .../MicroPET_DressRehearsal_202206/.DS_Store | Bin .../MicroPET_DressRehearsal_202206.ino | 0 .../MicroPET_FunctionalTest_202201.ino | 0 .../MicroPET_FunctionalTest_202208.ino | 0 .../MicroPET_Integration_20211208.ino | 0 .../MicroPET_Launch_code/.DS_Store | Bin .../MicroPET_Launch_code.ino | 0 .../Teensy_integration_1.ino | 0 .../Teensy_integration_2.ino | 0 .../Teensy_sensor_debug.ino | 0 .../Teensy_sensor_test/.DS_Store | Bin .../Teensy_sensor_test/Teensy_sensor_test.ino | 0 .../Teensy_test_RTC_/Teensy_test_RTC_.ino | 0 .../Teensy_writing_CSV/Teensy_writing_CSV.ino | 0 .../Teensy_writing_file.ino | 0 .../Teensey Code}/Time_test/Time_test.ino | 0 .../Teensey Code}/Topboard/Topboard.ino | 0 .../Teensey Code}/move_liquid/move_liquid.ino | 0 .../mux_multi_sensor/mux_multi_sensor.ino | 0 .../switch_connector_pins.ino | 0 .../teensy_test_var/teensy_test_var.ino | 0 launch_code/.DS_Store | Bin 0 -> 6148 bytes launch_code/launch_code.ino | 2284 +++++++++++++++++ 39 files changed, 2284 insertions(+) delete mode 100644 Teensey Code/mux_multi_sensor.zip create mode 100644 archive/.DS_Store rename {Python => archive/Python}/.idea/.gitignore (100%) rename {Python => archive/Python}/.idea/Python.iml (100%) rename {Python => archive/Python}/.idea/inspectionProfiles/profiles_settings.xml (100%) rename {Python => archive/Python}/.idea/misc.xml (100%) rename {Python => archive/Python}/.idea/modules.xml (100%) rename {Python => archive/Python}/.idea/vcs.xml (100%) rename {Python => archive/Python}/main.py (100%) rename {Teensey Code => archive/Teensey Code}/.DS_Store (93%) rename {Teensey Code => archive/Teensey Code}/Clock_test/Clock_test.ino (100%) rename {Teensey Code => archive/Teensey Code}/MicroPET_DressRehearsal_202202/.DS_Store (100%) rename {Teensey Code => archive/Teensey Code}/MicroPET_DressRehearsal_202202/MicroPET_DressRehearsal_202202.ino (100%) rename {Teensey Code => archive/Teensey Code}/MicroPET_DressRehearsal_202204/.DS_Store (100%) rename {Teensey Code => archive/Teensey Code}/MicroPET_DressRehearsal_202204/MicroPET_DressRehearsal_202204.ino (100%) rename {Teensey Code => archive/Teensey Code}/MicroPET_DressRehearsal_202206/.DS_Store (100%) rename {Teensey Code => archive/Teensey Code}/MicroPET_DressRehearsal_202206/MicroPET_DressRehearsal_202206.ino (100%) rename {Teensey Code => archive/Teensey Code}/MicroPET_FunctionalTest_202201/MicroPET_FunctionalTest_202201.ino (100%) rename {Teensey Code => archive/Teensey Code}/MicroPET_FunctionalTest_202208/MicroPET_FunctionalTest_202208.ino (100%) rename {Teensey Code => archive/Teensey Code}/MicroPET_Integration_20211208/MicroPET_Integration_20211208.ino (100%) rename {Teensey Code => archive/Teensey Code}/MicroPET_Launch_code/.DS_Store (100%) rename {Teensey Code => archive/Teensey Code}/MicroPET_Launch_code/MicroPET_Launch_code.ino (100%) rename {Teensey Code => archive/Teensey Code}/Teensy_integration_1/Teensy_integration_1.ino (100%) rename {Teensey Code => archive/Teensey Code}/Teensy_integration_2/Teensy_integration_2.ino (100%) rename {Teensey Code => archive/Teensey Code}/Teensy_sensor_debug/Teensy_sensor_debug.ino (100%) rename {Teensey Code => archive/Teensey Code}/Teensy_sensor_test/.DS_Store (100%) rename {Teensey Code => archive/Teensey Code}/Teensy_sensor_test/Teensy_sensor_test.ino (100%) rename {Teensey Code => archive/Teensey Code}/Teensy_test_RTC_/Teensy_test_RTC_.ino (100%) rename {Teensey Code => archive/Teensey Code}/Teensy_writing_CSV/Teensy_writing_CSV.ino (100%) rename {Teensey Code => archive/Teensey Code}/Teensy_writing_file/Teensy_writing_file.ino (100%) rename {Teensey Code => archive/Teensey Code}/Time_test/Time_test.ino (100%) rename {Teensey Code => archive/Teensey Code}/Topboard/Topboard.ino (100%) rename {Teensey Code => archive/Teensey Code}/move_liquid/move_liquid.ino (100%) rename {Teensey Code => archive/Teensey Code}/mux_multi_sensor/mux_multi_sensor.ino (100%) rename {Teensey Code => archive/Teensey Code}/switch_connector_pins/switch_connector_pins.ino (100%) rename {Teensey Code => archive/Teensey Code}/teensy_test_var/teensy_test_var.ino (100%) create mode 100644 launch_code/.DS_Store create mode 100644 launch_code/launch_code.ino diff --git a/.DS_Store b/.DS_Store index 2b4c2bb9e0f2b2cc37160e6fcb6a7642f027ea4a..f7cfe036da6010f0ea1411424a0e4da713d86c7d 100644 GIT binary patch delta 437 zcmZn(XmOBWU|?W$DortDU;r^WfEYvza8E20o2aMAD6lbLH$S7mWF7(SdUl3Hh9ZV! zh75*GhBAg!&z$_^q@4UDkaD0QvOwDFKNtX63=C+hbJ7iilk;;6z;X}*O+{|Liwo2| zj{RF^U9;3U>WFNP7R1`z{1m*(K&mDu$cVagGvojrT*{CKc5*zB%x6eJcQyma3U?%D zW9XV(BitrxYG9zFU}S1gtD{hDXk==rqhMifGFe>2SR6w=#Fojfg653wlWPSR;MO}i vRp`v*xiV6l)p;H;3o=6jMS>ehyMkh1W8rt^$^0sT9E^~7Vb~ncGlv-fv1Mc} literal 10244 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 VE~!Q3AOB~7cmDUz|Nryz|6g5$oi_jg literal 0 HcmV?d00001 diff --git a/Python/.idea/.gitignore b/archive/Python/.idea/.gitignore similarity index 100% rename from Python/.idea/.gitignore rename to archive/Python/.idea/.gitignore diff --git a/Python/.idea/Python.iml b/archive/Python/.idea/Python.iml similarity index 100% rename from Python/.idea/Python.iml rename to archive/Python/.idea/Python.iml diff --git a/Python/.idea/inspectionProfiles/profiles_settings.xml b/archive/Python/.idea/inspectionProfiles/profiles_settings.xml similarity index 100% rename from Python/.idea/inspectionProfiles/profiles_settings.xml rename to archive/Python/.idea/inspectionProfiles/profiles_settings.xml diff --git a/Python/.idea/misc.xml b/archive/Python/.idea/misc.xml similarity index 100% rename from Python/.idea/misc.xml rename to archive/Python/.idea/misc.xml diff --git a/Python/.idea/modules.xml b/archive/Python/.idea/modules.xml similarity index 100% rename from Python/.idea/modules.xml rename to archive/Python/.idea/modules.xml diff --git a/Python/.idea/vcs.xml b/archive/Python/.idea/vcs.xml similarity index 100% rename from Python/.idea/vcs.xml rename to archive/Python/.idea/vcs.xml diff --git a/Python/main.py b/archive/Python/main.py similarity index 100% rename from Python/main.py rename to archive/Python/main.py diff --git a/Teensey Code/.DS_Store b/archive/Teensey Code/.DS_Store similarity index 93% rename from Teensey Code/.DS_Store rename to archive/Teensey Code/.DS_Store index 475e69de2a0cf2d08f323029f0c59c1e42318e1e..9d4d92563a6e7a5a6df2dbfb683d29e362f8ecf8 100644 GIT binary patch delta 83 zcmZokXi1ph&uFqSU^hRb@?-%fyTx7tjH0Fn2098xrUtb-3e|>2riMBS7Um|K;{~5G gZtfAT=b6~xv6)+8Is0S>39-on5;mJzG}gg60O^evg#Z8m delta 113 zcmZokXi1ph&uF?aU^hRb%47j1yTx7tjO>P%Itqq{mXqfS$!^XQyvE2VGMQCaL4rY# zp^71sp};dIKRGEUKZ${XL4bjQdE;hN;Xa?u?|fL E0GxmvIRF3v diff --git a/Teensey Code/Clock_test/Clock_test.ino b/archive/Teensey Code/Clock_test/Clock_test.ino similarity index 100% rename from Teensey Code/Clock_test/Clock_test.ino rename to archive/Teensey Code/Clock_test/Clock_test.ino diff --git a/Teensey Code/MicroPET_DressRehearsal_202202/.DS_Store b/archive/Teensey Code/MicroPET_DressRehearsal_202202/.DS_Store similarity index 100% rename from Teensey Code/MicroPET_DressRehearsal_202202/.DS_Store rename to archive/Teensey Code/MicroPET_DressRehearsal_202202/.DS_Store diff --git a/Teensey Code/MicroPET_DressRehearsal_202202/MicroPET_DressRehearsal_202202.ino b/archive/Teensey Code/MicroPET_DressRehearsal_202202/MicroPET_DressRehearsal_202202.ino similarity index 100% rename from Teensey Code/MicroPET_DressRehearsal_202202/MicroPET_DressRehearsal_202202.ino rename to archive/Teensey Code/MicroPET_DressRehearsal_202202/MicroPET_DressRehearsal_202202.ino diff --git a/Teensey Code/MicroPET_DressRehearsal_202204/.DS_Store b/archive/Teensey Code/MicroPET_DressRehearsal_202204/.DS_Store similarity index 100% rename from Teensey Code/MicroPET_DressRehearsal_202204/.DS_Store rename to archive/Teensey Code/MicroPET_DressRehearsal_202204/.DS_Store diff --git a/Teensey Code/MicroPET_DressRehearsal_202204/MicroPET_DressRehearsal_202204.ino b/archive/Teensey Code/MicroPET_DressRehearsal_202204/MicroPET_DressRehearsal_202204.ino similarity index 100% rename from Teensey Code/MicroPET_DressRehearsal_202204/MicroPET_DressRehearsal_202204.ino rename to archive/Teensey Code/MicroPET_DressRehearsal_202204/MicroPET_DressRehearsal_202204.ino diff --git a/Teensey Code/MicroPET_DressRehearsal_202206/.DS_Store b/archive/Teensey Code/MicroPET_DressRehearsal_202206/.DS_Store similarity index 100% rename from Teensey Code/MicroPET_DressRehearsal_202206/.DS_Store rename to archive/Teensey Code/MicroPET_DressRehearsal_202206/.DS_Store diff --git a/Teensey Code/MicroPET_DressRehearsal_202206/MicroPET_DressRehearsal_202206.ino b/archive/Teensey Code/MicroPET_DressRehearsal_202206/MicroPET_DressRehearsal_202206.ino similarity index 100% rename from Teensey Code/MicroPET_DressRehearsal_202206/MicroPET_DressRehearsal_202206.ino rename to archive/Teensey Code/MicroPET_DressRehearsal_202206/MicroPET_DressRehearsal_202206.ino diff --git a/Teensey Code/MicroPET_FunctionalTest_202201/MicroPET_FunctionalTest_202201.ino b/archive/Teensey Code/MicroPET_FunctionalTest_202201/MicroPET_FunctionalTest_202201.ino similarity index 100% rename from Teensey Code/MicroPET_FunctionalTest_202201/MicroPET_FunctionalTest_202201.ino rename to archive/Teensey Code/MicroPET_FunctionalTest_202201/MicroPET_FunctionalTest_202201.ino diff --git a/Teensey Code/MicroPET_FunctionalTest_202208/MicroPET_FunctionalTest_202208.ino b/archive/Teensey Code/MicroPET_FunctionalTest_202208/MicroPET_FunctionalTest_202208.ino similarity index 100% rename from Teensey Code/MicroPET_FunctionalTest_202208/MicroPET_FunctionalTest_202208.ino rename to archive/Teensey Code/MicroPET_FunctionalTest_202208/MicroPET_FunctionalTest_202208.ino diff --git a/Teensey Code/MicroPET_Integration_20211208/MicroPET_Integration_20211208.ino b/archive/Teensey Code/MicroPET_Integration_20211208/MicroPET_Integration_20211208.ino similarity index 100% rename from Teensey Code/MicroPET_Integration_20211208/MicroPET_Integration_20211208.ino rename to archive/Teensey Code/MicroPET_Integration_20211208/MicroPET_Integration_20211208.ino diff --git a/Teensey Code/MicroPET_Launch_code/.DS_Store b/archive/Teensey Code/MicroPET_Launch_code/.DS_Store similarity index 100% rename from Teensey Code/MicroPET_Launch_code/.DS_Store rename to archive/Teensey Code/MicroPET_Launch_code/.DS_Store diff --git a/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino b/archive/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino similarity index 100% rename from Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino rename to archive/Teensey Code/MicroPET_Launch_code/MicroPET_Launch_code.ino diff --git a/Teensey Code/Teensy_integration_1/Teensy_integration_1.ino b/archive/Teensey Code/Teensy_integration_1/Teensy_integration_1.ino similarity index 100% rename from Teensey Code/Teensy_integration_1/Teensy_integration_1.ino rename to archive/Teensey Code/Teensy_integration_1/Teensy_integration_1.ino diff --git a/Teensey Code/Teensy_integration_2/Teensy_integration_2.ino b/archive/Teensey Code/Teensy_integration_2/Teensy_integration_2.ino similarity index 100% rename from Teensey Code/Teensy_integration_2/Teensy_integration_2.ino rename to archive/Teensey Code/Teensy_integration_2/Teensy_integration_2.ino diff --git a/Teensey Code/Teensy_sensor_debug/Teensy_sensor_debug.ino b/archive/Teensey Code/Teensy_sensor_debug/Teensy_sensor_debug.ino similarity index 100% rename from Teensey Code/Teensy_sensor_debug/Teensy_sensor_debug.ino rename to archive/Teensey Code/Teensy_sensor_debug/Teensy_sensor_debug.ino diff --git a/Teensey Code/Teensy_sensor_test/.DS_Store b/archive/Teensey Code/Teensy_sensor_test/.DS_Store similarity index 100% rename from Teensey Code/Teensy_sensor_test/.DS_Store rename to archive/Teensey Code/Teensy_sensor_test/.DS_Store diff --git a/Teensey Code/Teensy_sensor_test/Teensy_sensor_test.ino b/archive/Teensey Code/Teensy_sensor_test/Teensy_sensor_test.ino similarity index 100% rename from Teensey Code/Teensy_sensor_test/Teensy_sensor_test.ino rename to archive/Teensey Code/Teensy_sensor_test/Teensy_sensor_test.ino diff --git a/Teensey Code/Teensy_test_RTC_/Teensy_test_RTC_.ino b/archive/Teensey Code/Teensy_test_RTC_/Teensy_test_RTC_.ino similarity index 100% rename from Teensey Code/Teensy_test_RTC_/Teensy_test_RTC_.ino rename to archive/Teensey Code/Teensy_test_RTC_/Teensy_test_RTC_.ino diff --git a/Teensey Code/Teensy_writing_CSV/Teensy_writing_CSV.ino b/archive/Teensey Code/Teensy_writing_CSV/Teensy_writing_CSV.ino similarity index 100% rename from Teensey Code/Teensy_writing_CSV/Teensy_writing_CSV.ino rename to archive/Teensey Code/Teensy_writing_CSV/Teensy_writing_CSV.ino diff --git a/Teensey Code/Teensy_writing_file/Teensy_writing_file.ino b/archive/Teensey Code/Teensy_writing_file/Teensy_writing_file.ino similarity index 100% rename from Teensey Code/Teensy_writing_file/Teensy_writing_file.ino rename to archive/Teensey Code/Teensy_writing_file/Teensy_writing_file.ino diff --git a/Teensey Code/Time_test/Time_test.ino b/archive/Teensey Code/Time_test/Time_test.ino similarity index 100% rename from Teensey Code/Time_test/Time_test.ino rename to archive/Teensey Code/Time_test/Time_test.ino diff --git a/Teensey Code/Topboard/Topboard.ino b/archive/Teensey Code/Topboard/Topboard.ino similarity index 100% rename from Teensey Code/Topboard/Topboard.ino rename to archive/Teensey Code/Topboard/Topboard.ino diff --git a/Teensey Code/move_liquid/move_liquid.ino b/archive/Teensey Code/move_liquid/move_liquid.ino similarity index 100% rename from Teensey Code/move_liquid/move_liquid.ino rename to archive/Teensey Code/move_liquid/move_liquid.ino diff --git a/Teensey Code/mux_multi_sensor/mux_multi_sensor.ino b/archive/Teensey Code/mux_multi_sensor/mux_multi_sensor.ino similarity index 100% rename from Teensey Code/mux_multi_sensor/mux_multi_sensor.ino rename to archive/Teensey Code/mux_multi_sensor/mux_multi_sensor.ino diff --git a/Teensey Code/switch_connector_pins/switch_connector_pins.ino b/archive/Teensey Code/switch_connector_pins/switch_connector_pins.ino similarity index 100% rename from Teensey Code/switch_connector_pins/switch_connector_pins.ino rename to archive/Teensey Code/switch_connector_pins/switch_connector_pins.ino diff --git a/Teensey Code/teensy_test_var/teensy_test_var.ino b/archive/Teensey Code/teensy_test_var/teensy_test_var.ino similarity index 100% rename from Teensey Code/teensy_test_var/teensy_test_var.ino rename to archive/Teensey Code/teensy_test_var/teensy_test_var.ino diff --git a/launch_code/.DS_Store b/launch_code/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..e6ec13ef2582b97bf741c24b55011a2c66eb93f2 GIT binary patch literal 6148 zcmeHKO>5gg5S?}0MkWM&NTIougZtfBs)GBgYL;6 z${*?P>6_hkX>f81w5H6MnYTM1yV6^;t0f}UpN{s3+C&sU85=E_M}*_7E7I^DMrFq^ z^qG$6goZR&$ri^tGQey1hCWe77gW-p>sQj4D*TRtSI`9U3O2{;b}59i{gBS8>ohkh z#<@?g^Q@YL;ZN1rXuf#48Eghy!C8D|X7MDMOsjrUe&ybYF?qUdC+U}LJR7!mKAK{Z zWW~6&1=(nfly9e5F*38hnHHnU*2XRnw1U>Ky*rPpD_By(^-(4(P z!K=6L4v&Z5^B;w|b<8XLNv&*qT*4h1&m!R_E{oh0ml$U`$8u~zVL%uV2G)=Pzf}cW zYxr#PNWy?H@NXI5{Xs(+BagL1yLG_u=Of3Pj4WvLU4l`2j6Bv35rHUI3UsB)Uon&` zhhO`=$Ybr$m6NhFV;n!T@;4M^XNOvJzqxdz{3jCTIz{q3m5FUtp2v{1# J2m^nWfnQYNS|9)b literal 0 HcmV?d00001 diff --git a/launch_code/launch_code.ino b/launch_code/launch_code.ino new file mode 100644 index 0000000..a7e4d8b --- /dev/null +++ b/launch_code/launch_code.ino @@ -0,0 +1,2284 @@ +/*************************************************************************** + Base Board Connection: + E1VA + E1PA - J10 + E1VB + E1PB - J09 + E2VA + E2PA - J12 + E2VB + E2PB - J11 + the valve board connector J1-6 are the same on the base board + + ***************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include "RTClib.h" + +/* Experiment Prototypes and supporting defines */ +#define TOTAL_EXPERIMENTS 26 +void day_1(); +void day_2(); +void day_3(); +void day_4(); +void day_5(); +void day_6(); +void day_7(); +void day_8(); +void day_9(); +void day_10(); +void day_11(); +void day_12(); +void day_13(); +void day_14(); +void day_15(); +void day_16(); +void day_17(); +void day_18(); +void day_19(); +void day_20(); +void day_21(); +void day_22(); +void day_23(); +void day_24(); +void day_25(); +void day_26(); + +void (*experimentArray[TOTAL_EXPERIMENTS])() = {day_1, day_2, day_3, day_4, day_5, day_6, day_7, day_8, day_9, day_10, day_11, day_12, day_13, day_14, day_15, day_16, day_17, day_18, day_19, day_20, day_21, day_22, day_23, day_24, day_25, day_26}; +//Teensey 4.1 - SCL 19 - yellow /SDA 18 - blue + +#define BME_SCK 13 +#define BME_MISO 12 +#define BME_MOSI 11 +#define BME_CS 10 +#define SEALEVELPRESSURE_HPA (1013.25) + +RTC_PCF8523 rtc; + +uint16_t experimentIndex = 0; + +// Native I2C address of the mux +#define MUX_ADDR 0x70 +// Native I2C address of both AS7262 sensors +#define AS7262_ADDR 0x49 +// Native I2C address of both BME280 sensors +#define BME280_ADDR 0x76 +// Sensor positions on the mux +#define AS7262_SENSOR1 3 +#define AS7262_SENSOR2 0 +#define BME280_SENSOR1 2 +#define BME280_SENSOR2 1 + +Adafruit_BME280 bme; +Adafruit_AS726x ams; + +unsigned long delayTime; +#define SEALEVELPRESSURE_HPA (1013.25) +uint16_t sensorValues[AS726x_NUM_CHANNELS]; + +//SD Card +#include +#include + +typedef struct { + byte experimentStarted; + time_t epoch; + byte testDay; + byte testDayComplete; + byte testInterval; +} systemStateStruct; + +File myFile; +File expLogFile; +const int chipSelect = BUILTIN_SDCARD; +const int ledPin = 5; + +systemStateStruct systemStateStructVar = {0, 0, 0, 0}; + +//IO ports + +#define MCP_ADDR0 0x20 // IC5 on base board +#define MCP_ADDR1 0x21 // IC4 on base board +#define MCP_ADDR2 0x22 // IC1 on sensor board + +enum motion { forward, reverse, halt }; +#define PUMP1_A 8 +#define PUMP1_B 9 +#define PUMP2_A 10 +#define PUMP2_B 11 +#define PUMP3_A 12 +#define PUMP3_B 13 + +#define LED 13 + +// Double check these pin assignments +#define GPA0 0 +#define GPA1 1 +#define GPA2 2 +#define GPA3 3 +#define GPA4 4 +#define GPA5 5 +#define GPA6 6 +#define GPA7 7 + +#define GPB0 8 +#define GPB1 9 +#define GPB2 10 +#define GPB3 11 +#define GPB4 12 +#define GPB5 13 +#define GPB6 14 +#define GPB7 15 + +#define experimentOne 1 +#define experimentTwo 2 + +#define e_buffer 0 +#define enzyme 1 +#define chamberA 2 +#define media 3 +#define chamberB 4 + +#define waste 0 +#define preservativeOne 1 +#define preservativeTwo 2 +#define preservativeThree 3 +#define preservativeFour 4 +#define preservativeFive 5 + + +Adafruit_MCP23X17 mcp0; +Adafruit_MCP23X17 mcp1; +Adafruit_MCP23X17 mcp2; + +typedef enum { + // MCP0 - IC5 on base board + BASEBD_J4_PIN2 = 0, + BASEBD_J4_PIN4, + BASEBD_J3_PIN2, + BASEBD_J3_PIN4, + BASEBD_J2_PIN2, + BASEBD_J2_PIN4, + BASEBD_J1_PIN2, + BASEBD_J1_PIN4, + BASEBD_J5_PIN2, + BASEBD_J5_PIN4, + BASEBD_J6_PIN2, + BASEBD_J6_PIN4, + BASEBD_J7_PIN2, + BASEBD_J7_PIN4, + BASEBD_J8_PIN2, + BASEBD_J8_PIN4, + + // MCP1 - IC4 on base board + BASEBD_J12_PIN2, + BASEBD_J12_PIN4, + BASEBD_J11_PIN2, + BASEBD_J11_PIN4, + BASEBD_J10_PIN2, + BASEBD_J10_PIN4, + BASEBD_J9_PIN2, + BASEBD_J9_PIN4, + + //MCP2 - IC1 on sensor board + SENSEBD_J2_PIN1, + SENSEBD_J2_PIN2, + SENSEBD_J2_PIN3, + SENSEBD_J2_PIN4, + SENSEBD_J3_PIN1, + SENSEBD_J3_PIN2 +} CONN_PIN_T; // Connector and Pin type + +#define MCP1_PIN_OFFSET 16 +#define MCP2_PIN_OFFSET 16 + +/****************************************/ + +boolean switch_conn_pin(CONN_PIN_T conn_pin, byte level) +{ + if ((level != HIGH) && (level != LOW)) { + return false; + } + + if (conn_pin <= BASEBD_J8_PIN4) { + mcp0.digitalWrite(conn_pin, level); + } else if (conn_pin <= BASEBD_J9_PIN4) { + mcp1.digitalWrite((conn_pin - MCP1_PIN_OFFSET), level); + } else if (conn_pin <= SENSEBD_J3_PIN2) { + mcp2.digitalWrite((conn_pin - MCP2_PIN_OFFSET), level); + } else { + return false; + } + + return true; +} + + +String experimenta_log = ""; +unsigned int whichsensor = 0; + +#define SECONDS_IN_DAY 86400 +#define DELAY_SECONDS_PER_EXPERIMENT SECONDS_IN_DAY +//#define DELAY_SECONDS_PER_EXPERIMENT 120 // 2 mins for the functional testing +#define SERIAL_TIMEOUT 10000 //milliseconds + +const unsigned int MAX_MESSAGE_LENGTH = 12; +bool systemState = 0; + +//AlarmID_t Alarm_Day1_ID; +//AlarmID_t Alarm_Day2_ID; +//AlarmID_t Alarm_Day3_ID; +//AlarmID_t Alarm_Day4_ID; +//AlarmID_t Alarm_Day5_ID; +//AlarmID_t Alarm_Day6_ID; +//AlarmID_t Alarm_Day7_ID; +//AlarmID_t Alarm_Day8_ID; +//AlarmID_t Alarm_Day9_ID; + +// Function to select a sensor +void tcaselect(uint8_t sensor_addr) { + Wire.beginTransmission(MUX_ADDR); + Wire.write(1 << sensor_addr); + Wire.endTransmission(); +} + +void setup() { + pinMode(3, OUTPUT); + pinMode(4, OUTPUT); + pinMode(ledPin, OUTPUT); + + Serial.begin(9600); + + long unsigned startup_time = millis(); + // the below code waits for a serial monitor session to be opened + // but times out in SERIAL_TIMEOUT milliseconds if none exist + while (!Serial) { + // timeout check + if ( (millis() - startup_time) > SERIAL_TIMEOUT) { + break; + } + } + + Serial.println(F("Begin Serial")); + + init_card(); + initExpLogFile(); + rtcInit(); + + pinMode(LED, OUTPUT); + // uncomment appropriate mcp.begin + if (!mcp0.begin_I2C(MCP_ADDR0)) { + Serial.println("Error initializing chip 0."); + // while (1); + } + + if (!mcp1.begin_I2C(MCP_ADDR1)) { + Serial.println("Error initializing chip 1."); + // while (1); + } + + // IC5 on base board + mcp0.pinMode(GPA0, OUTPUT); + mcp0.pinMode(GPA1, OUTPUT); + mcp0.pinMode(GPA2, OUTPUT); + mcp0.pinMode(GPA3, OUTPUT); + mcp0.pinMode(GPA4, OUTPUT); + mcp0.pinMode(GPA5, OUTPUT); + mcp0.pinMode(GPA6, OUTPUT); + mcp0.pinMode(GPA7, OUTPUT); + + mcp0.pinMode(GPB0, OUTPUT); + mcp0.pinMode(GPB1, OUTPUT); + mcp0.pinMode(GPB2, OUTPUT); + mcp0.pinMode(GPB3, OUTPUT); + mcp0.pinMode(GPB4, OUTPUT); + mcp0.pinMode(GPB5, OUTPUT); + mcp0.pinMode(GPB6, OUTPUT); + mcp0.pinMode(GPB7, OUTPUT); + + // IC4 on base board + mcp1.pinMode(GPA0, OUTPUT); + mcp1.pinMode(GPA1, OUTPUT); + mcp1.pinMode(GPA2, OUTPUT); + mcp1.pinMode(GPA3, OUTPUT); + mcp1.pinMode(GPA4, OUTPUT); + mcp1.pinMode(GPA5, OUTPUT); + mcp1.pinMode(GPA6, OUTPUT); + mcp1.pinMode(GPA7, OUTPUT); + + //Revial + + if (!mcp2.begin_I2C(MCP_ADDR2)) { + Serial.println("Error initializing chip 2."); + // while (1); + } + Serial.println("setup revival pumping..."); + mcp2.pinMode(PUMP1_A, OUTPUT); + mcp2.pinMode(PUMP1_B, OUTPUT); +// mcp.pinMode(PUMP2_A, OUTPUT); +// mcp.pinMode(PUMP2_B, OUTPUT); + mcp2.pinMode(PUMP3_A, OUTPUT); + mcp2.pinMode(PUMP3_B, OUTPUT); + + // halt both motors upon initialization + + motorSensorBrdCtrl(1, halt); + motorSensorBrdCtrl(3, halt); + Serial.println("revival pumping halted"); + + +// Set up the sensors + unsigned bme_status; + unsigned ams_status; + + //Start the sensors line 1 + tcaselect(BME280_SENSOR1); + delay(1000); + // start the sensor + bme_status = bme.begin(); + ams_status = ams.begin(); + delay(1000); + + if(!ams_status){ + Serial.println("could not connect to AS726x sensor1, Please check your wiring."); + // while(1); delay(10); + } + + if (!bme_status) { + Serial.println("Could not find a valid BME280 sensor1, check wiring, address, sensor ID!"); + // while (1) delay(10); + } + + //Start the sensors line 2 + tcaselect(BME280_SENSOR2); + delay(1000); + // start the sensor + bme_status = bme.begin(); + ams_status = ams.begin(); + delay(1000); + + if(!ams_status){ + Serial.println("could not connect to AS726x sensor2, Please check your wiring."); + // while(1); delay(10); + } + + if (!bme_status) { + Serial.println("Could not find a valid BME280 sensor2, check wiring, address, sensor ID!"); + // while (1) delay(10); + } + + + Serial.println("-- Default Test --"); + delayTime = 1000; + + Serial.println(); + + // EXPERIMENTAL SETUP + + //STARTING DATE +// setTime(11,0,0,12,2,2022); // hr,min,sec,day,mnth,yr + Serial.println("Setting time from RTC"); + setTime(rtc.now().unixtime()); //sets time from RTC + Serial.print("Time is now: "); + Serial.println(now()); + + if(!grabStateFromSD(&systemStateStructVar)){ + Serial.println("No log file exists so will create one!"); + // no prior state exists so saving a new file with current rtc time + systemStateStructVar.experimentStarted = 0; + systemStateStructVar.epoch = rtc.now().unixtime(); + saveStateToSD(&systemStateStructVar); + } + else if(systemStateStructVar.experimentStarted==0){ + Serial.println("Previous log file exists but experiment hasn't started!"); + // if a file exists and shows no prior experiment has started, update time + systemStateStructVar.experimentStarted = 0; + systemStateStructVar.epoch = rtc.now().unixtime(); + saveStateToSD(&systemStateStructVar); + } + else if (systemStateStructVar.experimentStarted==1){ + Serial.println("Power Failure Event Detected!"); + // log file has shown that experiment has started already + // todo: implement schedule correction + systemState = true; + recoverSystemStart(); + } + + Serial.println("Start Looping..."); + + // EVERYDAY TASK + Alarm.timerRepeat(60, Taking_Sensor_Data); + + +} + + +// for(int i = 1+systemStateStructVar.testDay; i= DELAY_SECONDS_PER_EXPERIMENT){ + Serial.println("System was off for longer than experiment interval!"); + + skipDays = int( timeSinceLastExperiment / DELAY_SECONDS_PER_EXPERIMENT ); + for(int i = 0; i < skipDays; i++){ + systemStateStructVar.testDay++; + Serial.print(" Skipping day: "); + Serial.println(systemStateStructVar.testDay); + + saveExperimentalLog(" Skipping day: " + String(systemStateStructVar.testDay)); + } + } + + timeSinceLastExperiment = int( timeSinceLastExperiment % DELAY_SECONDS_PER_EXPERIMENT ); + // (1.3) check if tests had already ended + if(systemStateStructVar.testDay == TOTAL_EXPERIMENTS - 1){ + Serial.println("Power failure occured after experiment finished! No reason to resume!"); + + saveExperimentalLog("Power failure occured after experiment finished! No reason to resume!"); + + while(1); + return; + } + + /* (2) setup timers */ + uint32_t timeRemaining = DELAY_SECONDS_PER_EXPERIMENT - timeSinceLastExperiment; + experimentIndex = systemStateStructVar.testDay; + Alarm.timerOnce(timeRemaining,(*experimentArray[experimentIndex])); + +// uint16_t inc = 0; +// for(int i = 1+systemStateStructVar.testDay; i 0) { + //Create a place to hold the incoming message + static char message[MAX_MESSAGE_LENGTH]; + static unsigned int message_pos = 0; + + //Read the next available byte in the serial receive buffer + char inByte = Serial.read(); + //Message coming in (check not terminating character) and guard for over message size + if ( inByte != '\n' && (message_pos < MAX_MESSAGE_LENGTH - 1) ) + { + //Add the incoming byte to our message + message[message_pos] = inByte; + message_pos++; + } + //Full message received... + else + { + //Add null character to string + message[message_pos] = '\0'; + + if (strcmp(message, "START") == 0) { + startCondition = true; + + //Print the message (or do other things) + Serial.println("Start Message Received"); + } + + + if (strcmp(message, "TEST") == 0) { + //Print the message (or do other things) + Serial.println("Executing Test Script"); + + + + day_functionTest(); + } + + //Reset for the next message + message_pos = 0; + } + } + + return startCondition; +} + +void day_functionTest(){ + + /////DAYFUNCTION + + /////DAYFUNCTION + + /////DAYFUNCTION + +} + + +void day_1() { + // =============== SET == NEXT == ALARM ============ + setNextAlarm(); + + +//================================================== +//================================================== +//================================================== +//================================================== +//================================================== +// =============== UPDATE STATUS =================== + systemState = 1; + + systemStateStructVar.experimentStarted = 1; + systemStateStructVar.epoch = rtc.now().unixtime(); + systemStateStructVar.testDay = 1; + systemStateStructVar.testInterval = 1; + systemStateStructVar.testDayComplete = 0; + saveStateToSD(&systemStateStructVar); + + Serial.println("Executing Day 1"); + saveExperimentalLog("Executing Day 1"); + + + // =============== ENZYME EXP ===================== + + //DUMMY CODE + moveLiquid (experimentOne, e_buffer, chamberA, 1000); //buffer to chamber A - 1 ml (flexible) + moveLiquid (experimentTwo, e_buffer, chamberA, 1000); //buffer to chamber A - 1 ml (flexible) + Serial.println("finish the dummy code..."); + saveExperimentalLog("Finish dummy code!"); + + //EXP1 - liquid in dummy code + moveLiquid (experimentOne, enzyme, chamberA, 75); //enzyme to chamber A - 0.075 ml + moveLiquid (experimentOne, e_buffer, chamberA, 1525); //buffer to chamber A - 1.525 ml (flexible) + //EXP2 - liquid in dummy code + moveLiquid (experimentTwo, enzyme, chamberA, 75); //enzyme to chamber A - 0.075 ml + moveLiquid (experimentTwo, e_buffer, chamberA, 1525); //buffer to chamber A - 1.525 ml (flexible) + + + // =============== MICROBE EXP ===================== + + //EXP1 + Serial.println("EXP1 revival pumping..."); + saveExperimentalLog("EXP1 revived"); + switchCollection(experimentOne, waste);//back to waste bag + motorSensorBrdCtrl(1, forward); + delay (5000); //~10ML + motorSensorBrdCtrl(1, halt); + + //EXP2 + Serial.println("EXP2 revival pumping..."); + saveExperimentalLog("EXP2 revived"); + switchCollection(experimentTwo, waste);//back to waste bag + motorSensorBrdCtrl(3, forward); + delay (5000); //~10ML + motorSensorBrdCtrl(3, halt); + + + // =============== UPDATE STATUS =================== + systemStateStructVar.testDayComplete = 1; + saveStateToSD(&systemStateStructVar); + + Serial.println("Day 1 Finishes"); + saveExperimentalLog("Day 1 Finishes"); +} + +void day_2() { + // =============== SET == NEXT == ALARM ============ + setNextAlarm(); + + +// =============== UPDATE === STATUS =============== + + systemStateStructVar.experimentStarted = 1; + systemStateStructVar.epoch = rtc.now().unixtime(); + systemStateStructVar.testDay = 2; + systemStateStructVar.testInterval = 1; + systemStateStructVar.testDayComplete = 0; + saveStateToSD(&systemStateStructVar); + + Serial.println("Executing Day 1"); + saveExperimentalLog("Executing Day 1"); + + + // =============== MICROBE EXP ===================== + + // DO NOTHING + + // =============== ENZYME EXP ===================== + + // DO NOTHING + + // =============== UPDATE === STATUS =============== + + + systemStateStructVar.testDayComplete = 1; + saveStateToSD(&systemStateStructVar); + + Serial.println("Day 2 Finishes"); + saveExperimentalLog("Day 2 Finishes"); + + + +} + +void day_3() { + // =============== SET == NEXT == ALARM ============ + setNextAlarm(); + + +// =============== UPDATE === STATUS =============== + + systemStateStructVar.experimentStarted = 1; + systemStateStructVar.epoch = rtc.now().unixtime(); + systemStateStructVar.testDay = 3; + systemStateStructVar.testInterval = 1; + systemStateStructVar.testDayComplete = 0; + saveStateToSD(&systemStateStructVar); + + Serial.println("Executing Day 3"); + saveExperimentalLog("Executing Day 3"); + + + // =============== MICROBE EXP ===================== + + // DO NOTHING + + // =============== ENZYME EXP ===================== + + // DO NOTHING + + // =============== UPDATE === STATUS =============== + + + systemStateStructVar.testDayComplete = 1; + saveStateToSD(&systemStateStructVar); + + Serial.println("Day 3 Finishes"); + saveExperimentalLog("Day 3 Finishes"); + + + +} + +void day_4() { + // =============== SET == NEXT == ALARM ============ + setNextAlarm(); + + +// =============== UPDATE === STATUS =============== + + systemStateStructVar.experimentStarted = 1; + systemStateStructVar.epoch = rtc.now().unixtime(); + systemStateStructVar.testDay = 4; + systemStateStructVar.testInterval = 1; + systemStateStructVar.testDayComplete = 0; + saveStateToSD(&systemStateStructVar); + + Serial.println("Executing Day 4"); + saveExperimentalLog("Executing Day 4"); + + + // =============== MICROBE EXP ===================== + + // DO NOTHING + + // =============== ENZYME EXP ===================== + + //EXP1 + moveLiquid (experimentOne, enzyme, chamberA, 75); //enzyme to chamber A - 0.075 ml + moveLiquid (experimentOne, e_buffer, chamberA, 2525); //buffer to chamber A - 2.925 ml (flexible) + //EXP2 + moveLiquid (experimentTwo, enzyme, chamberA, 75); //enzyme to chamber A - 0.075 ml + moveLiquid (experimentTwo, e_buffer, chamberA, 2525); //buffer to chamber A - 2.925 ml (flexible) + + + // =============== UPDATE === STATUS =============== + + + systemStateStructVar.testDayComplete = 1; + saveStateToSD(&systemStateStructVar); + + Serial.println("Day 4 Finishes"); + saveExperimentalLog("Day 4 Finishes"); + + +} + +void day_5() { + // =============== SET == NEXT == ALARM ============ + setNextAlarm(); + + +// =============== UPDATE === STATUS =============== + + systemStateStructVar.experimentStarted = 1; + systemStateStructVar.epoch = rtc.now().unixtime(); + systemStateStructVar.testDay = 5; + systemStateStructVar.testInterval = 1; + systemStateStructVar.testDayComplete = 0; + saveStateToSD(&systemStateStructVar); + + Serial.println("Executing Day 5"); + saveExperimentalLog("Executing Day 5"); + + + // =============== MICROBE EXP ===================== + + // DO NOTHING + + // =============== ENZYME EXP ===================== + + // DO NOTHING + + // =============== UPDATE === STATUS =============== + + + systemStateStructVar.testDayComplete = 1; + saveStateToSD(&systemStateStructVar); + + Serial.println("Day 5 Finishes"); + saveExperimentalLog("Day 5 Finishes"); + + +} + +void day_6() { + // =============== SET == NEXT == ALARM ============ + setNextAlarm(); + + +// =============== UPDATE === STATUS =============== + + systemStateStructVar.experimentStarted = 1; + systemStateStructVar.epoch = rtc.now().unixtime(); + systemStateStructVar.testDay = 6; + systemStateStructVar.testInterval = 1; + systemStateStructVar.testDayComplete = 0; + saveStateToSD(&systemStateStructVar); + + Serial.println("Executing Day 6"); + saveExperimentalLog("Executing Day 6"); + + + // =============== MICROBE EXP ===================== + + //EXP1 + switchCollection(experimentOne, preservativeOne);//Open valve to preservative MRNA1 - with BKA + moveLiquid (experimentOne, media, chamberB, 5000);//move medium to chamber B - 6ml + switchCollection(experimentOne, waste);//back to waste bag + + //EXP2 + switchCollection(experimentTwo, preservativeOne);//Open valve to preservative MRNA1 - with BKA + moveLiquid (experimentTwo, media, chamberB, 5000);//move medium to chamber B - 6ml + switchCollection(experimentTwo, waste);//back to waste bag + + // =============== ENZYME EXP ===================== + + // DO NOTHING + + // =============== UPDATE === STATUS =============== + + + systemStateStructVar.testDayComplete = 1; + saveStateToSD(&systemStateStructVar); + + Serial.println("Day 6 Finishes"); + saveExperimentalLog("Day 6 Finishes"); + + +} + +void day_7() { + // =============== SET == NEXT == ALARM ============ + setNextAlarm(); + + +// =============== UPDATE === STATUS =============== + + systemStateStructVar.experimentStarted = 1; + systemStateStructVar.epoch = rtc.now().unixtime(); + systemStateStructVar.testDay = 7; + systemStateStructVar.testInterval = 1; + systemStateStructVar.testDayComplete = 0; + saveStateToSD(&systemStateStructVar); + + Serial.println("Executing Day 7"); + saveExperimentalLog("Executing Day 7"); + + + // =============== MICROBE EXP ===================== + + // DO NOTHING + + // =============== ENZYME EXP ===================== + + //EXP1 + moveLiquid (experimentOne, enzyme, chamberA, 75); //enzyme to chamber A - 0.075 ml + moveLiquid (experimentOne, e_buffer, chamberA, 2525); //buffer to chamber A - 2.525 ml (flexible) + //EXP2 + moveLiquid (experimentTwo, enzyme, chamberA, 75); //enzyme to chamber A - 0.075 ml + moveLiquid (experimentTwo, e_buffer, chamberA, 2525); //buffer to chamber A - 2.525 ml (flexible) + + + // =============== UPDATE === STATUS =============== + + + systemStateStructVar.testDayComplete = 1; + saveStateToSD(&systemStateStructVar); + + Serial.println("Day 7 Finishes"); + saveExperimentalLog("Day 7 Finishes"); + + +} + +void day_8() { + // =============== SET == NEXT == ALARM ============ + setNextAlarm(); + + +// =============== UPDATE === STATUS =============== + + systemStateStructVar.experimentStarted = 1; + systemStateStructVar.epoch = rtc.now().unixtime(); + systemStateStructVar.testDay = 8; + systemStateStructVar.testInterval = 1; + systemStateStructVar.testDayComplete = 0; + saveStateToSD(&systemStateStructVar); + + Serial.println("Executing Day 8"); + saveExperimentalLog("Executing Day 8"); + + + // =============== MICROBE EXP ===================== + + // DO NOTHING + + // =============== ENZYME EXP ===================== + + // DO NOTHING + + // =============== UPDATE === STATUS =============== + + + systemStateStructVar.testDayComplete = 1; + saveStateToSD(&systemStateStructVar); + + Serial.println("Day 8 Finishes"); + saveExperimentalLog("Day 8 Finishes"); + + +} + +void day_9() { + // =============== SET == NEXT == ALARM ============ + setNextAlarm(); + + +// =============== UPDATE === STATUS =============== + + systemStateStructVar.experimentStarted = 1; + systemStateStructVar.epoch = rtc.now().unixtime(); + systemStateStructVar.testDay = 9; + systemStateStructVar.testInterval = 1; + systemStateStructVar.testDayComplete = 0; + saveStateToSD(&systemStateStructVar); + + Serial.println("Executing Day 9"); + saveExperimentalLog("Executing Day 9"); + + + // =============== MICROBE EXP ===================== + + // DO NOTHING + + // =============== ENZYME EXP ===================== + + // DO NOTHING + + // =============== UPDATE === STATUS =============== + + + systemStateStructVar.testDayComplete = 1; + saveStateToSD(&systemStateStructVar); + + Serial.println("Day 9 Finishes"); + saveExperimentalLog("Day 9 Finishes"); + + +} + +void day_10() { + // =============== SET == NEXT == ALARM ============ + setNextAlarm(); + + +// =============== UPDATE === STATUS =============== + + systemStateStructVar.experimentStarted = 1; + systemStateStructVar.epoch = rtc.now().unixtime(); + systemStateStructVar.testDay = 10; + systemStateStructVar.testInterval = 1; + systemStateStructVar.testDayComplete = 0; + saveStateToSD(&systemStateStructVar); + + Serial.println("Executing Day 10"); + saveExperimentalLog("Executing Day 10"); + + + // =============== MICROBE EXP ===================== + + //EXP1 + switchCollection(experimentOne, preservativeOne);//Open valve to preservative MRNA1 - with BKA + moveLiquid (experimentOne, media, chamberB, 5000);//move medium to chamber B - 6ml + Serial.println("Exp1_SDS collection"); + saveExperimentalLog("Exp1_SDS collection"); + + switchCollection(experimentOne, preservativeFour);//Open valve to preservative MRNA1 - with BKA + moveLiquid (experimentOne, media, chamberB, 10000);//move medium to chamber B - 6ml + switchCollection(experimentOne, waste);//back to waste bag + + + + //EXP2 + switchCollection(experimentTwo, preservativeOne);//Open valve to preservative MRNA1 - with BKA + moveLiquid (experimentTwo, media, chamberB, 5000);//move medium to chamber B - 6ml + Serial.println("Exp2_SDS collection"); + saveExperimentalLog("Exp2_SDS collection"); + + switchCollection(experimentTwo, preservativeFour);//Open valve to preservative MRNA1 - with BKA + moveLiquid (experimentTwo, media, chamberB, 10000);//move medium to chamber B - 6ml + switchCollection(experimentTwo, waste);//back to waste bag + + + // =============== ENZYME EXP ===================== + + //EXP1 + moveLiquid (experimentOne, enzyme, chamberA, 75); //enzyme to chamber A - 0.075 ml + moveLiquid (experimentOne, e_buffer, chamberA, 2525); //buffer to chamber A - 2.525 ml (flexible) + //EXP2 + moveLiquid (experimentTwo, enzyme, chamberA, 75); //enzyme to chamber A - 0.075 ml + moveLiquid (experimentTwo, e_buffer, chamberA, 2525); //buffer to chamber A - 2.525 ml (flexible) + + + // =============== UPDATE === STATUS =============== + + + systemStateStructVar.testDayComplete = 1; + saveStateToSD(&systemStateStructVar); + + Serial.println("Day 10 Finishes"); + saveExperimentalLog("Day 10 Finishes"); + + +} + +void day_11() { + // =============== SET == NEXT == ALARM ============ + setNextAlarm(); + + +// =============== UPDATE === STATUS =============== + + systemStateStructVar.experimentStarted = 1; + systemStateStructVar.epoch = rtc.now().unixtime(); + systemStateStructVar.testDay = 11; + systemStateStructVar.testInterval = 1; + systemStateStructVar.testDayComplete = 0; + saveStateToSD(&systemStateStructVar); + + Serial.println("Executing Day 11"); + saveExperimentalLog("Executing Day 11"); + + + // =============== MICROBE EXP ===================== + + // DO NOTHING + + // =============== ENZYME EXP ===================== + + // DO NOTHING + + // =============== UPDATE === STATUS =============== + + + systemStateStructVar.testDayComplete = 1; + saveStateToSD(&systemStateStructVar); + + Serial.println("Day 11 Finishes"); + saveExperimentalLog("Day 11 Finishes"); + + +} + +void day_12() { + // =============== SET == NEXT == ALARM ============ + setNextAlarm(); + + +// =============== UPDATE === STATUS =============== + + systemStateStructVar.experimentStarted = 1; + systemStateStructVar.epoch = rtc.now().unixtime(); + systemStateStructVar.testDay = 12; + systemStateStructVar.testInterval = 1; + systemStateStructVar.testDayComplete = 0; + saveStateToSD(&systemStateStructVar); + + Serial.println("Executing Day 12"); + saveExperimentalLog("Executing Day 12"); + + + // =============== MICROBE EXP ===================== + + // DO NOTHING + + // =============== ENZYME EXP ===================== + + // DO NOTHING + + // =============== UPDATE === STATUS =============== + + + systemStateStructVar.testDayComplete = 1; + saveStateToSD(&systemStateStructVar); + + Serial.println("Day 12 Finishes"); + saveExperimentalLog("Day 12 Finishes"); + + +} + +void day_13() { + // =============== SET == NEXT == ALARM ============ + setNextAlarm(); + + +// =============== UPDATE === STATUS =============== + + systemStateStructVar.experimentStarted = 1; + systemStateStructVar.epoch = rtc.now().unixtime(); + systemStateStructVar.testDay = 13; + systemStateStructVar.testInterval = 1; + systemStateStructVar.testDayComplete = 0; + saveStateToSD(&systemStateStructVar); + + Serial.println("Executing Day 13"); + saveExperimentalLog("Executing Day 13"); + + + // =============== MICROBE EXP ===================== + + // DO NOTHING + + // =============== ENZYME EXP ===================== + + //EXP1 + moveLiquid (experimentOne, enzyme, chamberA, 75); //enzyme to chamber A - 0.075 ml + moveLiquid (experimentOne, e_buffer, chamberA, 2525); //buffer to chamber A - 2.525 ml (flexible) + //EXP2 + moveLiquid (experimentTwo, enzyme, chamberA, 75); //enzyme to chamber A - 0.075 ml + moveLiquid (experimentTwo, e_buffer, chamberA, 2525); //buffer to chamber A - 2.525 ml (flexible) + + + // =============== UPDATE === STATUS =============== + + + systemStateStructVar.testDayComplete = 1; + saveStateToSD(&systemStateStructVar); + + Serial.println("Day 13 Finishes"); + saveExperimentalLog("Day 13 Finishes"); + + +} + +void day_14() { + // =============== SET == NEXT == ALARM ============ + setNextAlarm(); + + +// =============== UPDATE === STATUS =============== + + systemStateStructVar.experimentStarted = 1; + systemStateStructVar.epoch = rtc.now().unixtime(); + systemStateStructVar.testDay = 14; + systemStateStructVar.testInterval = 1; + systemStateStructVar.testDayComplete = 0; + saveStateToSD(&systemStateStructVar); + + Serial.println("Executing Day 14"); + saveExperimentalLog("Executing Day 14"); + + + // =============== MICROBE EXP ===================== + + //EXP1 + switchCollection(experimentOne, preservativeTwo);//Open valve to preservative MRNA1 - with BKA + moveLiquid (experimentOne, media, chamberB, 5000);//move medium to chamber B - 6ml + switchCollection(experimentOne, waste);//back to waste bag + + //EXP2 + switchCollection(experimentTwo, preservativeTwo);//Open valve to preservative MRNA1 - with BKA + moveLiquid (experimentTwo, media, chamberB, 5000);//move medium to chamber B - 6ml + switchCollection(experimentTwo, waste);//back to waste bag + + // =============== ENZYME EXP ===================== + + // DO NOTHING + + // =============== UPDATE === STATUS =============== + + + systemStateStructVar.testDayComplete = 1; + saveStateToSD(&systemStateStructVar); + + Serial.println("Day 14 Finishes"); + saveExperimentalLog("Day 14 Finishes"); + + +} + +void day_15() { + // =============== SET == NEXT == ALARM ============ + setNextAlarm(); + + +// =============== UPDATE === STATUS =============== + + systemStateStructVar.experimentStarted = 1; + systemStateStructVar.epoch = rtc.now().unixtime(); + systemStateStructVar.testDay = 15; + systemStateStructVar.testInterval = 1; + systemStateStructVar.testDayComplete = 0; + saveStateToSD(&systemStateStructVar); + + Serial.println("Executing Day 15"); + saveExperimentalLog("Executing Day 15"); + + + // =============== MICROBE EXP ===================== + + // DO NOTHING + + // =============== ENZYME EXP ===================== + + // DO NOTHING + + // =============== UPDATE === STATUS =============== + + + systemStateStructVar.testDayComplete = 1; + saveStateToSD(&systemStateStructVar); + + Serial.println("Day 15 Finishes"); + saveExperimentalLog("Day 15 Finishes"); + + +} + +void day_16() { + // =============== SET == NEXT == ALARM ============ + setNextAlarm(); + + +// =============== UPDATE === STATUS =============== + + systemStateStructVar.experimentStarted = 1; + systemStateStructVar.epoch = rtc.now().unixtime(); + systemStateStructVar.testDay = 16; + systemStateStructVar.testInterval = 1; + systemStateStructVar.testDayComplete = 0; + saveStateToSD(&systemStateStructVar); + + Serial.println("Executing Day 16"); + saveExperimentalLog("Executing Day 16"); + + + // =============== MICROBE EXP ===================== + + // DO NOTHING + + // =============== ENZYME EXP ===================== + + //EXP1 + moveLiquid (experimentOne, enzyme, chamberA, 75); //enzyme to chamber A - 0.075 ml + moveLiquid (experimentOne, e_buffer, chamberA, 2525); //buffer to chamber A - 2.925 ml (flexible) + //EXP2 + moveLiquid (experimentTwo, enzyme, chamberA, 75); //enzyme to chamber A - 0.075 ml + moveLiquid (experimentTwo, e_buffer, chamberA, 2525); //buffer to chamber A - 2.925 ml (flexible) + + + // =============== UPDATE === STATUS =============== + + + systemStateStructVar.testDayComplete = 1; + saveStateToSD(&systemStateStructVar); + + Serial.println("Day 16 Finishes"); + saveExperimentalLog("Day 16 Finishes"); + + +} + +void day_17() { + // =============== SET == NEXT == ALARM ============ + setNextAlarm(); + + +// =============== UPDATE === STATUS =============== + + systemStateStructVar.experimentStarted = 1; + systemStateStructVar.epoch = rtc.now().unixtime(); + systemStateStructVar.testDay = 17; + systemStateStructVar.testInterval = 1; + systemStateStructVar.testDayComplete = 0; + saveStateToSD(&systemStateStructVar); + + Serial.println("Executing Day 17"); + saveExperimentalLog("Executing Day 17"); + + + // =============== MICROBE EXP ===================== + + // DO NOTHING + + // =============== ENZYME EXP ===================== + + // DO NOTHING + + // =============== UPDATE === STATUS =============== + + + systemStateStructVar.testDayComplete = 1; + saveStateToSD(&systemStateStructVar); + + Serial.println("Day 17 Finishes"); + saveExperimentalLog("Day 17 Finishes"); + + +} + +void day_18() { + // =============== SET == NEXT == ALARM ============ + setNextAlarm(); + + +// =============== UPDATE === STATUS =============== + + systemStateStructVar.experimentStarted = 1; + systemStateStructVar.epoch = rtc.now().unixtime(); + systemStateStructVar.testDay = 18; + systemStateStructVar.testInterval = 1; + systemStateStructVar.testDayComplete = 0; + saveStateToSD(&systemStateStructVar); + + Serial.println("Executing Day 18"); + saveExperimentalLog("Executing Day 18"); + + + // =============== MICROBE EXP ===================== + + //EXP1 + switchCollection(experimentOne, preservativeTwo);//Open valve to preservative MRNA1 - with BKA + moveLiquid (experimentOne, media, chamberB, 5000);//move medium to chamber B - 6ml + switchCollection(experimentOne, waste);//back to waste bag + + //EXP2 + switchCollection(experimentTwo, preservativeTwo);//Open valve to preservative MRNA1 - with BKA + moveLiquid (experimentTwo, media, chamberB, 5000);//move medium to chamber B - 6ml + switchCollection(experimentTwo, waste);//back to waste bag + + // =============== ENZYME EXP ===================== + + // DO NOTHING + + // =============== UPDATE === STATUS =============== + + + systemStateStructVar.testDayComplete = 1; + saveStateToSD(&systemStateStructVar); + + Serial.println("Day 18 Finishes"); + saveExperimentalLog("Day 18 Finishes"); + + +} + +void day_19() { + // =============== SET == NEXT == ALARM ============ + setNextAlarm(); + + +// =============== UPDATE === STATUS =============== + + systemStateStructVar.experimentStarted = 1; + systemStateStructVar.epoch = rtc.now().unixtime(); + systemStateStructVar.testDay = 19; + systemStateStructVar.testInterval = 1; + systemStateStructVar.testDayComplete = 0; + saveStateToSD(&systemStateStructVar); + + Serial.println("Executing Day 19"); + saveExperimentalLog("Executing Day 19"); + + + // =============== MICROBE EXP ===================== + + // DO NOTHING + + // =============== ENZYME EXP ===================== + + //EXP1 + moveLiquid (experimentOne, enzyme, chamberA, 75); //enzyme to chamber A - 0.075 ml + moveLiquid (experimentOne, e_buffer, chamberA, 2525); //buffer to chamber A - 2.925 ml (flexible) + //EXP2 + moveLiquid (experimentTwo, enzyme, chamberA, 75); //enzyme to chamber A - 0.075 ml + moveLiquid (experimentTwo, e_buffer, chamberA, 2525); //buffer to chamber A - 2.925 ml (flexible) + + + // =============== UPDATE === STATUS =============== + + + systemStateStructVar.testDayComplete = 1; + saveStateToSD(&systemStateStructVar); + + Serial.println("Day 19 Finishes"); + saveExperimentalLog("Day 19 Finishes"); + + +} + +void day_20() { + // =============== SET == NEXT == ALARM ============ + setNextAlarm(); + + +// =============== UPDATE === STATUS =============== + + systemStateStructVar.experimentStarted = 1; + systemStateStructVar.epoch = rtc.now().unixtime(); + systemStateStructVar.testDay = 20; + systemStateStructVar.testInterval = 1; + systemStateStructVar.testDayComplete = 0; + saveStateToSD(&systemStateStructVar); + + Serial.println("Executing Day 20"); + saveExperimentalLog("Executing Day 20"); + + + // =============== MICROBE EXP ===================== + + // DO NOTHING + + // =============== ENZYME EXP ===================== + + // DO NOTHING + + // =============== UPDATE === STATUS =============== + + + systemStateStructVar.testDayComplete = 1; + saveStateToSD(&systemStateStructVar); + + Serial.println("Day 20 Finishes"); + saveExperimentalLog("Day 20 Finishes"); + + +} + +void day_21() { + // =============== SET == NEXT == ALARM ============ + setNextAlarm(); + + +// =============== UPDATE === STATUS =============== + + systemStateStructVar.experimentStarted = 1; + systemStateStructVar.epoch = rtc.now().unixtime(); + systemStateStructVar.testDay = 21; + systemStateStructVar.testInterval = 1; + systemStateStructVar.testDayComplete = 0; + saveStateToSD(&systemStateStructVar); + + Serial.println("Executing Day 21"); + saveExperimentalLog("Executing Day 21"); + + + // =============== MICROBE EXP ===================== + + // DO NOTHING + + // =============== ENZYME EXP ===================== + + // DO NOTHING + + // =============== UPDATE === STATUS =============== + + + systemStateStructVar.testDayComplete = 1; + saveStateToSD(&systemStateStructVar); + + Serial.println("Day 21 Finishes"); + saveExperimentalLog("Day 21 Finishes"); + + +} + +void day_22() { + // =============== SET == NEXT == ALARM ============ + setNextAlarm(); + + +// =============== UPDATE === STATUS =============== + + systemStateStructVar.experimentStarted = 1; + systemStateStructVar.epoch = rtc.now().unixtime(); + systemStateStructVar.testDay = 22; + systemStateStructVar.testInterval = 1; + systemStateStructVar.testDayComplete = 0; + saveStateToSD(&systemStateStructVar); + + Serial.println("Executing Day 22"); + saveExperimentalLog("Executing Day 22"); + + + // =============== MICROBE EXP ===================== + + //EXP1 + switchCollection(experimentOne, preservativeThree);//Open valve to preservative MRNA1 - with BKA + moveLiquid (experimentOne, media, chamberB, 5000);//move medium to chamber B - 6ml + switchCollection(experimentOne, waste);//back to waste bag + + //EXP2 + switchCollection(experimentTwo, preservativeThree);//Open valve to preservative MRNA1 - with BKA + moveLiquid (experimentTwo, media, chamberB, 5000);//move medium to chamber B - 6ml + switchCollection(experimentTwo, waste);//back to waste bag + + + // =============== ENZYME EXP ===================== + + //EXP1 + moveLiquid (experimentOne, enzyme, chamberA, 75); //enzyme to chamber A - 0.075 ml + moveLiquid (experimentOne, e_buffer, chamberA, 2525); //buffer to chamber A - 2.925 ml (flexible) + //EXP2 + moveLiquid (experimentTwo, enzyme, chamberA, 75); //enzyme to chamber A - 0.075 ml + moveLiquid (experimentTwo, e_buffer, chamberA, 2525); //buffer to chamber A - 2.925 ml (flexible) + + + // =============== UPDATE === STATUS =============== + + + systemStateStructVar.testDayComplete = 1; + saveStateToSD(&systemStateStructVar); + + Serial.println("Day 22 Finishes"); + saveExperimentalLog("Day 22 Finishes"); + + +} + +void day_23() { + // =============== SET == NEXT == ALARM ============ + setNextAlarm(); + + +// =============== UPDATE === STATUS =============== + + systemStateStructVar.experimentStarted = 1; + systemStateStructVar.epoch = rtc.now().unixtime(); + systemStateStructVar.testDay = 23; + systemStateStructVar.testInterval = 1; + systemStateStructVar.testDayComplete = 0; + saveStateToSD(&systemStateStructVar); + + Serial.println("Executing Day 23"); + saveExperimentalLog("Executing Day 23"); + + + // =============== MICROBE EXP ===================== + + // DO NOTHING + + // =============== ENZYME EXP ===================== + + // DO NOTHING + + // =============== UPDATE === STATUS =============== + + + systemStateStructVar.testDayComplete = 1; + saveStateToSD(&systemStateStructVar); + + Serial.println("Day 23 Finishes"); + saveExperimentalLog("Day 23 Finishes"); + + +} + +void day_24() { + // =============== SET == NEXT == ALARM ============ + setNextAlarm(); + + +// =============== UPDATE === STATUS =============== + + systemStateStructVar.experimentStarted = 1; + systemStateStructVar.epoch = rtc.now().unixtime(); + systemStateStructVar.testDay = 24; + systemStateStructVar.testInterval = 1; + systemStateStructVar.testDayComplete = 0; + saveStateToSD(&systemStateStructVar); + + Serial.println("Executing Day 24"); + saveExperimentalLog("Executing Day 24"); + + + // =============== MICROBE EXP ===================== + + // DO NOTHING + + // =============== ENZYME EXP ===================== + + // DO NOTHING + + // =============== UPDATE === STATUS =============== + + + systemStateStructVar.testDayComplete = 1; + saveStateToSD(&systemStateStructVar); + + Serial.println("Day 24 Finishes"); + saveExperimentalLog("Day 24 Finishes"); + + +} + +void day_25() { + // =============== SET == NEXT == ALARM ============ + setNextAlarm(); + + +// =============== UPDATE === STATUS =============== + + systemStateStructVar.experimentStarted = 1; + systemStateStructVar.epoch = rtc.now().unixtime(); + systemStateStructVar.testDay = 25; + systemStateStructVar.testInterval = 1; + systemStateStructVar.testDayComplete = 0; + saveStateToSD(&systemStateStructVar); + + Serial.println("Executing Day 25"); + saveExperimentalLog("Executing Day 25"); + + + // =============== MICROBE EXP ===================== + + // DO NOTHING + + // =============== ENZYME EXP ===================== + + //EXP1 + moveLiquid (experimentOne, enzyme, chamberA, 75); //enzyme to chamber A - 0.075 ml + moveLiquid (experimentOne, e_buffer, chamberA, 2525); //buffer to chamber A - 2.925 ml (flexible) + //EXP2 + moveLiquid (experimentTwo, enzyme, chamberA, 75); //enzyme to chamber A - 0.075 ml + moveLiquid (experimentTwo, e_buffer, chamberA, 2525); //buffer to chamber A - 2.925 ml (flexible) + + + // =============== UPDATE === STATUS =============== + + + systemStateStructVar.testDayComplete = 1; + saveStateToSD(&systemStateStructVar); + + Serial.println("Day 25 Finishes"); + saveExperimentalLog("Day 25 Finishes"); + + +} + +void day_26() { + // =============== SET == NEXT == ALARM ============ + setNextAlarm(); + + +// =============== UPDATE === STATUS =============== + + systemStateStructVar.experimentStarted = 1; + systemStateStructVar.epoch = rtc.now().unixtime(); + systemStateStructVar.testDay = 26; + systemStateStructVar.testInterval = 1; + systemStateStructVar.testDayComplete = 0; + saveStateToSD(&systemStateStructVar); + + Serial.println("Executing Day 26"); + saveExperimentalLog("Executing Day 26"); + + + // =============== MICROBE EXP ===================== + + //EXP1 + switchCollection(experimentOne, preservativeThree);//Open valve to preservative MRNA1 - with BKA + moveLiquid (experimentOne, media, chamberB, 5000);//move medium to chamber B - 6ml + switchCollection(experimentOne, waste);//back to waste bag + + //EXP2 + switchCollection(experimentTwo, preservativeThree);//Open valve to preservative MRNA1 - with BKA + moveLiquid (experimentTwo, media, chamberB, 5000);//move medium to chamber B - 6ml + switchCollection(experimentTwo, waste);//back to waste bag + + + // =============== ENZYME EXP ===================== + + // DO NOTHING + + // =============== UPDATE === STATUS =============== + + + systemStateStructVar.testDayComplete = 1; + saveStateToSD(&systemStateStructVar); + + Serial.println("Day 26 Finishes"); + saveExperimentalLog("Day 26 Finishes"); + + +} + + +void setNextAlarm(){ + experimentIndex++; + if(experimentIndex < TOTAL_EXPERIMENTS){ + Alarm.timerOnce(DELAY_SECONDS_PER_EXPERIMENT, (*experimentArray[experimentIndex])); + } +} + + +void moveLiquid(int experiment, int origin, int target, float liquid_volume) +{ + //experiment ONE_Enyzme Part + + if (experiment == 1 && origin == 0) + { + switch_conn_pin(BASEBD_J10_PIN2, LOW); //Experiment 1 valveA + Serial.println("E1_exp1 move from e_buffer"); + saveExperimentalLog("E1_move from e_buffer"); + } + + if (experiment == 1 && origin == 1) + { + switch_conn_pin(BASEBD_J10_PIN2, HIGH); //Experiment 1 valveA + Serial.println("E1 move from enzyme"); + saveExperimentalLog("E1_move from enzyme"); + } + + if (experiment == 1 && target == 2) + { + switch_conn_pin(BASEBD_J9_PIN2, HIGH); //Experiment 1 valveB high, waste line open + int move_pulse = liquid_volume / 25; //1ml = 1000uL and the pump moves 25uL at a time + Serial.println("move to chamberA"); + saveExperimentalLog("E1_move to chamberA" + String(move_pulse * 25) + "uL"); + for (int i = 0; i <= move_pulse; i++) { + switch_conn_pin(BASEBD_J10_PIN4, HIGH); //Experiment 1 pumpA + digitalWrite(LED, HIGH); + delay(200); + switch_conn_pin(BASEBD_J10_PIN4, LOW); //Experiment 1 pumpA + digitalWrite(LED, LOW); + delay(200); + Serial.println( i * 25); //print out the moving volume + saveExperimentalLog("STEP_exp1_move to chamberA" + String(i * 25) + "uL"); + } + switch_conn_pin(BASEBD_J10_PIN2, LOW); //Reset eperiment 1 valveA so enzyme is blocked + } + /* Uncomment and edit line above switch_conn_pin(BASEBD_J9_PIN2, HIGH); to LOW + if we want to control chamberA and waste flow + if (experiment == 1 && target == 0) + { + switch_conn_pin(BASEBD_J9_PIN2, HIGH); //Experiment 2 valveB high, go to waste + int move_pulse = liquid_volume / 25; //1ml = 1000uL and the pump moves 25uL at a time + Serial.println("move to waste"); + saveExperimentalLog("_move to waste " + move_pulse * 25 + "uL"); + for (int i = 0; i <= move_pulse; i++) { + switch_conn_pin(BASEBD_J10_PIN4, HIGH); //Experiment 2 pumpA + digitalWrite(LED, HIGH); + delay(200); + switch_conn_pin(BASEBD_J10_PIN4, LOW); //Experiment 2 pumpA + digitalWrite(LED, LOW); + delay(200); + Serial.println( i * 25); + } + switch_conn_pin(BASEBD_J10_PIN2, LOW); //Reset experiment 2 valveA so enzyme is blocked + } +*/ + +//experiment One_BioCell Part + + if (experiment == 1 && origin == 3 && target == 4) + { + int move_pulse = liquid_volume / 25; //1ml = 1000uL and the pump moves 25uL at a time + Serial.println("E1 move to chamberB"); + saveExperimentalLog("E1_move to chamberB " + String(move_pulse * 25) + "uL"); + for (int i = 0; i <= move_pulse; i++) { + switch_conn_pin(BASEBD_J9_PIN4, HIGH); //Experiment 1 pumpB + digitalWrite(LED, HIGH); + delay(200); + switch_conn_pin(BASEBD_J9_PIN4, LOW); //Experiment 1 pumpB + digitalWrite(LED, LOW); + delay(200); + Serial.println( i * 25); //print out the moving volume + saveExperimentalLog("STEP_E1_move to chamberB " + String(i * 25) + "uL"); + } + // switch_conn_pin(BASEBD_J9_PIN2, LOW); //Reset experiment 1 valveB so chamberA is blocked + } + + //experimentTWO, Enzyme + + if (experiment == 2 && origin == 0) + { + switch_conn_pin(BASEBD_J12_PIN2, LOW); //Experiment 2 valveA + Serial.println("E2 move from e_buffer"); + saveExperimentalLog("E2_move from e_buffer"); + } + + if (experiment == 2 && origin == 1) + { + switch_conn_pin(BASEBD_J12_PIN2, HIGH); //Experiment 2 valveA + saveExperimentalLog("E2_move from enzyme"); + Serial.println("E2 move from Enzyme"); + } + + if (experiment == 2 && target == 2) + { + switch_conn_pin(BASEBD_J11_PIN2, HIGH); //Experiment 2 valveB high, waste line open + int move_pulse = liquid_volume / 25; //1ml = 1000uL and the pump moves 25uL at a time + Serial.println("E2 move to chamberA"); + saveExperimentalLog("E2_move to chamberA " + String(move_pulse * 25) + "uL"); + for (int i = 0; i <= move_pulse; i++) { + switch_conn_pin(BASEBD_J12_PIN4, HIGH); //Experiment 2 pumpA + digitalWrite(LED, HIGH); + delay(200); + switch_conn_pin(BASEBD_J12_PIN4, LOW); //Experiment 2 pumpA + digitalWrite(LED, LOW); + delay(200); + Serial.println( i * 25); + saveExperimentalLog("STEP_E2_move to chamberA " + String(i * 25) + "uL"); + } + switch_conn_pin(BASEBD_J12_PIN2, LOW); //Reset xperiment 1 valveA so enzyme is blocked + } + + /* Uncomment and edit line above switch_conn_pin(BASEBD_J11_PIN2, HIGH); to LOW + if we want to control chamberA and waste flow + if (experiment == 2 && target == 0) + { + switch_conn_pin(BASEBD_J11_PIN2, HIGH); //Experiment 2 valveB high, go to waste + int move_pulse = liquid_volume / 25; //1ml = 1000uL and the pump moves 25uL at a time + Serial.println("move to waste"); + saveExperimentalLog("_move to waste " + move_pulse * 25 + "uL"); + for (int i = 0; i <= move_pulse; i++) { + switch_conn_pin(BASEBD_J12_PIN4, HIGH); //Experiment 2 pumpA + digitalWrite(LED, HIGH); + delay(200); + switch_conn_pin(BASEBD_J12_PIN4, LOW); //Experiment 2 pumpA + digitalWrite(LED, LOW); + delay(200); + Serial.println( i * 25); + } + switch_conn_pin(BASEBD_J12_PIN2, LOW); //Reset xperiment 2 valveA so enzyme is blocked + } + */ + + //experimentTWO, Microbe + + if (experiment == 2 && origin == 3 && target == 4) + { + int move_pulse = liquid_volume / 25; //1ml = 1000uL and the pump moves 35uL at a time + Serial.println("E2 media move to chamberB"); + saveExperimentalLog("E2_media_move to chamberB " + String(move_pulse * 25) + "uL"); + for (int i = 0; i <= move_pulse; i++){ + switch_conn_pin(BASEBD_J11_PIN4, HIGH); //Experiment 2 pumpB + digitalWrite(LED, HIGH); + delay(200); + switch_conn_pin(BASEBD_J11_PIN4, LOW); //Experiment 2 pumpB + digitalWrite(LED, LOW); + delay(200); + Serial.println( i * 25); + saveExperimentalLog("STEP_E2_media_move to chamberB " + String(i * 25) + "uL"); + } + } +} + +void switchCollection(int experiment, int bag) +{ + if (experiment == 1 && bag == 0) + { + switch_conn_pin(BASEBD_J5_PIN4, LOW); //Experiment 1 waste V6 + Serial.println("E1 open waste bag"); + saveExperimentalLog("E1_opem waste bag"); + } + if (experiment == 1 && bag == 1) + { + switch_conn_pin(BASEBD_J5_PIN4, HIGH); //NOT V6 + switch_conn_pin(BASEBD_J5_PIN2, LOW); //Experiment 1 preservativeOne V5 + Serial.println("E1 open preservativeOne bag"); + saveExperimentalLog("E1_open preservativeOne bag"); + } + if (experiment == 1 && bag == 2) + { + switch_conn_pin(BASEBD_J5_PIN4, HIGH); //NOT V6 + switch_conn_pin(BASEBD_J5_PIN2, HIGH); //NOT V5 + switch_conn_pin(BASEBD_J3_PIN4, LOW); ////Experiment 1 preservativeTwo V4 + Serial.println("E1 open preservativeTwo bag"); + saveExperimentalLog("E1_open preservativeTwo bag"); + } + if (experiment == 1 && bag == 3) + { + switch_conn_pin(BASEBD_J5_PIN4, HIGH); //NOT V6 + switch_conn_pin(BASEBD_J5_PIN2, HIGH); //NOT V5 + switch_conn_pin(BASEBD_J3_PIN4, HIGH); //NOT V4 + switch_conn_pin(BASEBD_J3_PIN2, LOW); //Experiment 1 preservativeThree V3 + Serial.println("open preservativeThree bag"); + saveExperimentalLog("E1_open preservativeThree bag"); + } + if (experiment == 1 && bag == 4) + { + switch_conn_pin(BASEBD_J5_PIN4, HIGH); //NOT V6 + switch_conn_pin(BASEBD_J5_PIN2, HIGH); //NOT V5 + switch_conn_pin(BASEBD_J3_PIN4, HIGH); //NOT V4 + switch_conn_pin(BASEBD_J3_PIN2, HIGH); //NOT V3 + switch_conn_pin(BASEBD_J1_PIN4, LOW); //Experiment 1 preservativeFour V2 + Serial.println("E1_open preservativeFour bag"); + } + + //experiment two collection + + if (experiment == 2 && bag == 0) + { + switch_conn_pin(BASEBD_J2_PIN2, LOW); //Experiment 2 waste V7 + Serial.println("E2 open waste bag"); + saveExperimentalLog("E2_opem waste bag"); + } + if (experiment == 2 && bag == 1) + { + switch_conn_pin(BASEBD_J2_PIN2, HIGH); //NOT V7 + switch_conn_pin(BASEBD_J2_PIN4, LOW); //Experiment 2 preservativeOne V8 + Serial.println("E2 open preservativeOne bag"); + saveExperimentalLog("E2_open preservativeOne bag"); + } + if (experiment == 2 && bag == 2) + { + switch_conn_pin(BASEBD_J2_PIN2, HIGH); //NOT V7 + switch_conn_pin(BASEBD_J2_PIN4, HIGH); //NOT V8 + switch_conn_pin(BASEBD_J4_PIN2, LOW); ////Experiment 2 preservativeTwo V9 + Serial.println("E2 open preservativeTwo bag"); + saveExperimentalLog("E2_open preservativeTwo bag"); + } + if (experiment == 2 && bag == 3) + { + switch_conn_pin(BASEBD_J2_PIN2, HIGH); //NOT V7 + switch_conn_pin(BASEBD_J2_PIN4, HIGH); //NOT V8 + switch_conn_pin(BASEBD_J4_PIN2, HIGH); //NOT V9 + switch_conn_pin(BASEBD_J4_PIN4, LOW); //Experiment 2 preservativeThree V10 + Serial.println("E2_open preservativeThree bag"); + saveExperimentalLog("E2_open preservativeThree bag"); + } +if (experiment == 2 && bag == 4) +{ + switch_conn_pin(BASEBD_J2_PIN2, HIGH); //NOT V7 + switch_conn_pin(BASEBD_J2_PIN4, HIGH); //NOT V8 + switch_conn_pin(BASEBD_J4_PIN2, HIGH); //NOT V9 + switch_conn_pin(BASEBD_J4_PIN4, HIGH); //NOT V10 + switch_conn_pin(BASEBD_J6_PIN2, LOW); //Experiment 2 preservativeFour V11 + Serial.println("E2_open preservativeFour bag"); + saveExperimentalLog("E2_open preservativeFour bag"); +} +} + +void Taking_Sensor_Data() { + Serial.println("Taking Sensor Data"); + Serial.print("Time is now: "); + Serial.println(now()); + float temp1, temp2; + uint16_t as1_sensorValues[AS726x_NUM_CHANNELS], as2_sensorValues[AS726x_NUM_CHANNELS]; + +// Select the first BME280 and AS726xread some data + tcaselect(BME280_SENSOR1); + Serial.println("Sensor Data Experiment One"); + whichsensor = 1; + delay(100); + get_data(); + delay(2000); +// Select the second BME280 and AS726xread some data + tcaselect(BME280_SENSOR2); + Serial.println("Sensor Data Experiment Two"); + whichsensor = 2; + delay(100); + get_data(); + delay(2000); +} + + +void digitalClockDisplay() +{ + // digital clock display of the time + Serial.print(now()); + Serial.print(hour()); + printDigits(minute()); + printDigits(second()); + Serial.println(); +} + +void printDigits(int digits) +{ + Serial.print(":"); + if (digits < 10) + Serial.print('0'); + Serial.print(digits); +} + + +time_t tmConvert_t(int YYYY, byte MM, byte DD, byte hh, byte mm, byte ss) +{ + tmElements_t tmSet; + tmSet.Year = YYYY - 1970; + tmSet.Month = MM; + tmSet.Day = DD; + tmSet.Hour = hh; + tmSet.Minute = mm; + tmSet.Second = ss; + return makeTime(tmSet); +} + + + + +void get_data() { + //AMS + //read the device temperature + uint8_t temp = ams.readTemperature(); + + ams.drvOn(); //uncomment this if you want to use the driver LED for readings + ams.startMeasurement(); //begin a measurement + + //wait till data is available + bool rdy = false; + while (!rdy) { + delay(5); + rdy = ams.dataReady(); + } + + + //read the values! + ams.readRawValues(sensorValues); + //ams.readCalibratedValues(calibratedValues); + + Serial.print("Temp: "); Serial.print(temp); + Serial.print(" Violet: "); Serial.print(sensorValues[AS726x_VIOLET]); + Serial.print(" Blue: "); Serial.print(sensorValues[AS726x_BLUE]); + Serial.print(" Green: "); Serial.print(sensorValues[AS726x_GREEN]); + Serial.print(" Yellow: "); Serial.print(sensorValues[AS726x_YELLOW]); + Serial.print(" Orange: "); Serial.print(sensorValues[AS726x_ORANGE]); + Serial.print(" Red: "); Serial.print(sensorValues[AS726x_RED]); + Serial.println(); + + ams.drvOff(); + + //BME + Serial.print("Temperature = "); + Serial.print(bme.readTemperature()); + Serial.println(" °C"); + Serial.print("Pressure = "); + Serial.print(bme.readPressure() / 100.0F); + Serial.println(" hPa"); + Serial.print("Approx. Altitude = "); + Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); + Serial.println(" m"); + Serial.print("Humidity = "); + Serial.print(bme.readHumidity()); + Serial.println(" %"); + + + + //SAVING + // open the file. + myFile = SD.open("savefile.csv", FILE_WRITE); + if (myFile) + { + Serial.print("Writing to file..."); + //myFile.println(); + + //DT + myFile.print(now()); + myFile.print(','); + + //millis + myFile.print(millis()); + myFile.print(','); + + //whichsensor + myFile.print(whichsensor); + myFile.print(','); + + //Temp + myFile.print(bme.readTemperature()); + myFile.print(','); + + //Pressure + myFile.print(bme.readPressure() / 100.0F); + myFile.print(','); + + //Attitude + myFile.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); + myFile.print(','); + + //Humidity + myFile.print(bme.readHumidity()); + myFile.print(','); + + //Temp2 + myFile.print(temp); + myFile.print(','); + + //Spectral_Violet + myFile.print(sensorValues[AS726x_VIOLET]); + myFile.print(','); + + //Spectral_Blue + myFile.print(sensorValues[AS726x_VIOLET]); + myFile.print(','); + + //Spectral_Green + myFile.print(sensorValues[AS726x_GREEN]); + myFile.print(','); + + //Spectral_Yellow + myFile.print(sensorValues[AS726x_YELLOW]); + myFile.print(','); + + //Spectral_Orange + myFile.print(sensorValues[AS726x_ORANGE]); + myFile.print(','); + + //Spectral_Red + myFile.print(sensorValues[AS726x_RED]); +// myFile.print(','); +// +// //EXP Log +// myFile.print(experimenta_log); + + myFile.println(); + myFile.close(); + Serial.println("done."); + digitalWrite(ledPin, HIGH); // set the LED on + delay(300); // wait for a second + digitalWrite(ledPin, LOW); // set the LED off + delay(300); // wait for a second + } + else { + Serial.println("error opening file"); + } + +} + +void saveExperimentalLog(String logmessage){ + expLogFile = SD.open("explog.csv", FILE_WRITE); + if(expLogFile){ + expLogFile.print(now()); + expLogFile.print(','); + expLogFile.print(logmessage); + expLogFile.println(); + expLogFile.close(); + } +} + +void init_card() { + + Serial.print("Initializing SD card..."); + + if (!SD.begin(chipSelect)) { + Serial.println("initialization failed!"); + return; + } + Serial.println("initialization done."); + + + // open the file. + myFile = SD.open("savefile.csv", FILE_WRITE); + if (myFile) { + Serial.print("Init header to file..."); + digitalWrite(ledPin, HIGH); // set the LED on + delay(1000); // wait for a second + digitalWrite(ledPin, LOW); // set the LED off + delay(1000); // wait for a second + + //Content + myFile.println("DT, millis, Sensorline, Temp, Pressure, Attitude, Humidity, Temp2, Spectral_Violet, Spectral_Blue, Spectral_Green, Spectral_Yellow, Spectral_Orange, Spectral_Red"); + myFile.close(); + Serial.println("done."); + } else { + Serial.println("error opening file"); + } + //Close the file +} + +void initExpLogFile(){ + expLogFile = SD.open("explog.csv", FILE_WRITE); + if (expLogFile) { + expLogFile.print("timestamp"); + expLogFile.print(','); + expLogFile.print("log_message"); + expLogFile.println(); + expLogFile.close(); + } +} + +/* Function to control motors on sensor board */ +/* Input: (1) motor_num is either 1 or 3 + * (2) dir is either forward, reverse, or halt + */ +void motorSensorBrdCtrl(uint8_t motor_num, motion dir){ + if(motor_num == 1){ + if(dir == forward){ + mcp2.digitalWrite(PUMP1_A, HIGH); + mcp2.digitalWrite(PUMP1_B, LOW); + }else if(dir == reverse){ + mcp2.digitalWrite(PUMP1_A, LOW); + mcp2.digitalWrite(PUMP1_B, HIGH); + }else if(dir == halt){ + mcp2.digitalWrite(PUMP1_A, LOW); + mcp2.digitalWrite(PUMP1_B, LOW); + } + }else if(motor_num == 3){ + if(dir == forward){ + mcp2.digitalWrite(PUMP3_A, HIGH); + mcp2.digitalWrite(PUMP3_B, LOW); + }else if(dir == reverse){ + mcp2.digitalWrite(PUMP3_A, LOW); + mcp2.digitalWrite(PUMP3_B, HIGH); + }else if(dir == halt){ + mcp2.digitalWrite(PUMP3_A, LOW); + mcp2.digitalWrite(PUMP3_B, LOW); + } + } + delay (1000); +}