Project Autus - Automated Plant Chamber

Dependencies:   TextLCD mbed

Fork of keypad_test by Plamen Totev

Autus

This is the codebase accompanying the project Autus.

Autus is an automated growth chamber for plants.

Features

Control Humidity inside chamber wrt to external humidity. Control Temperature inside chamber. ( Peltier Heaters/Coolers ) Water and shower plants. Control soil humidity. Monitor water tanks level (Load Cell) /media/uploads/umairaftab/frdm_-_new_page1.png

Code Base Features

Fixed timing and CRC for DHT-11 Sensor. Fixed OneWire bug for ds18b20

Cyclic Executive Scheduler with Priority. Async IPC framework for PC App over bluetooth

Fake RTC systick, I was having some trouble with the on board rtc.

/media/uploads/umairaftab/download.png

Revision:
9:43c339533f7f
Parent:
8:2d462919519e
Child:
10:1a0fe96381b0
--- a/main.cpp	Fri Apr 11 11:05:02 2014 +0000
+++ b/main.cpp	Fri Apr 11 12:49:30 2014 +0000
@@ -34,7 +34,10 @@
 Ticker clock_mine;
 //FLAGS
 bool startup_flag=true; 
-bool watered_plants = false; 
+bool watered_plant1 = false;
+int watered_plant1_time = 0; 
+bool watered_plant2 = false;
+int watered_plant2_time = 0; 
 
 //SETPOINTS
 float setpoint_air_humidity = 30.00 ;
@@ -42,7 +45,7 @@
 float setpoint_soil_humid2 = 0.3 ;
 
 //WINDOWING
-float window_f = 2 ;
+float window_f = 5 ;
 int window_i =2 ;
 
 //GLOBAL VARS
@@ -50,7 +53,8 @@
 
 //SAFETY LIMITS
 const float max_peltier_temp = 68 ; //CELCIUS
-
+const int MAX_WATERING_TIME_GAP = 20;
+const int CYCLE_AIR_TIME = 2;
 //**************************FUNCTION TO READ SENSORS ********************************************** 
 void read_sensors(){
     
@@ -73,10 +77,61 @@
 }
 
 //****************************Functions that perform tasks**************************************
+//Water Plants
 void waterplants(){
     
     
+    if(startup_flag == true){
+        //call for pump function 
+        watered_plant1 = true;
+        watered_plant1_time = hour ; 
+        watered_plant2 = true;
+        watered_plant2_time = hour ; 
+    }
+    else{
+        
+        if( (soil1_humid < 0.3) || (watered_plant1 == false) ){ 
+            //enable pump1
+            watered_plant1 = true;
+            watered_plant1_time = hour ;
+        }
+        if( (soil2_humid < 0.3) || (watered_plant2 == false) ){ 
+            //enable pump2
+            watered_plant2 = true;
+            watered_plant2_time = hour ;
+        }
+    }
     
+    if (watered_plant1 == true){
+        if(abs(hour-watered_plant1_time)>MAX_WATERING_TIME_GAP){
+            watered_plant1 = false;
+        }
+    }   
+    if (watered_plant2 == true){
+        if(abs(hour-watered_plant2_time)>MAX_WATERING_TIME_GAP){
+            watered_plant2 = false;
+        }
+    } 
+    
+}
+
+// Air Humidity Level
+void airhumidity(){
+    
+    if( (setpoint_air_humidity+window_f > inside_humidity) && (setpoint_air_humidity-window_f < inside_humidity) ){
+    
+        //Turn on Air humidity fan 
+        wait(5);
+        //Turn off Air humisity fan
+    }   
+}
+
+//CYCLE AIR 
+void cycleair(){
+    
+    //Turn on fan 
+    wait(CYCLE_AIR_TIME);
+    //turn of fan 
     
 }
 //***************************PLACEHOLDER FUNCTION TO DISABLE EVERYTHING **********************
@@ -106,29 +161,70 @@
     disable_everything();
     
     
-    //FOR BUZZER
-    timer1ms.attach(&timer1, 0.001); //interrupt attached function(timer) with interval (1 ms)
+    
     //FOR INTERNAL CLOCK
     clock_mine.attach(&sec_inc, 1.0);
     char keypad_value;
     
     //call LCD boot
     ui_startup();
-    
+    wait(2);
     //SET TIME
     rtcimp_settime(6,0);
     //call function that reads values
+    
+/*  FOR CRTITICALITY
+    NVIC_DisableIRQ(TIMER3_IRQn);
+ 
+    // critical section
+ 
+    NVIC_EnableIRQ(TIMER3_IRQn);
+*/
+    lcd.cls();
+    lcd.locate(0,0);
+    lcd.printf("Reading Sensors");
+    
     read_sensors();
     
+    wait(2);
+    lcd.cls();
+    lcd.locate(0,0);
+    lcd.printf("Done Reading Sensors");
     //call function that performs functions.
     
+    wait(2);
+    lcd.cls();
+    lcd.locate(0,0);
+    lcd.printf("Watering Plants");
+    
+    waterplants();
+    
+    wait(2);
+    lcd.cls();
+    lcd.locate(0,0);
+    lcd.printf("Air Humidity");
+    
+    airhumidity();
+    
+    wait(2);
+    lcd.cls();
+    lcd.locate(0,0);
+    lcd.printf("Cycling Air");
+    
+    cycleair();
+    
+    wait(5);
+    ui_screen1();
+    wait(5);
     
     startup_flag = false ;  
     while(1) {
        
         wait(1.5);
+        //FOR BUZZER
+        timer1ms.attach(&timer1, 0.001); //interrupt attached function(timer) with interval (1 ms)
         keypad_value = Keypad();
-        
+        timer1ms.detach();
     }//WHILE END