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:
38:9f4107db1bff
Parent:
37:892872c3fa96
Child:
40:28d1814d367e
--- a/main.cpp	Mon Apr 14 00:52:14 2014 +0000
+++ b/main.cpp	Mon Apr 14 03:34:02 2014 +0000
@@ -67,18 +67,29 @@
 //GLOBAL VARS
 float current_water_level = 0; 
 bool lcd_timeout_flag=false;
+
 int led_set_time=0;
 int led_off_time=0;
 bool lights_startup_flag=true;
+
 int sensor_function_call_time=0;
+
+int pelt_call_time=0;
+
+float desire_temp=40;
+float desire_temp_air=30;
+bool pelt_keypad_enable=false;
+bool pelt_first_time = true;
+bool pelt_overheat = false;
 //SAFETY LIMITS
-const float max_peltier_temp = 68 ; //CELCIUS
+const float max_peltier_temp = 50 ; //CELCIUS
 const int MAX_WATERING_TIME_GAP = 20; //Number of Hours
 const int CYCLE_AIR_TIME = 2; //Wait between on and off seconds
 const int LCD_TIMEOUT_VALUE = 30; //Number of seconds
 const char status = 'F'; //For bluetooth Serial
-const int led_lights_timeout=5; // Timeout afterwhich to turn off/on lights
+const int led_lights_timeout=5; // Timeout afterwhich to turn off/on lights hours
 const int sensor_function_call_timeout=3; //Timeout for sensorcall and function
+const int pelt_call_timeout=30;
 
 //*************************FUNCTION CALLBACK FOR SERIAL INTTERUPTS********************************
 void callback_bluetooth() {
@@ -464,7 +475,22 @@
     // critical section
  
     NVIC_EnableIRQ(TIMER3_IRQn);
-*/
+*/  wait(5);
+    lcd.cls();
+    lcd.locate(0,0);
+    lcd.printf("Find Pelt Temp Sense");
+    
+    tempinit();
+    peltierin_temp = dsen_temp_in;
+    peltierout_temp = dsen_temp_out;
+    
+    wait(2);
+    lcd.cls();
+    lcd.locate(0,0);
+    lcd.printf("Find Pelt Temp Sense");
+    lcd.printf("Found Them");
+    
+    wait(2);
     lcd.cls();
     lcd.locate(0,0);
     lcd.printf("Reading Sensors");
@@ -482,7 +508,7 @@
     lcd.locate(0,0);
     lcd.printf("Watering Plants");
     
-    //waterplants();
+    waterplants();
     
     wait(2);
     lcd.cls();
@@ -582,9 +608,13 @@
         if (keypad_value == 70 ){ //Backlight red down
             lcd_backlight_off();    
         }
+        if(keypad_value == 84){
+            pelt_keypad_enable=true;    
+        }
         printf("%d\n\r",keypad_value);
         //  -> Key pressed
         
+        
         //LEDS Timeout functions
         if(led_set_flag == false){
             if( (abs(hour-led_off_time) > led_lights_timeout)||lights_startup_flag ==true){
@@ -606,7 +636,7 @@
             }
         }
         //printf("MINOFF %d\n\r",::min);
-        if( (abs(::min-sensor_function_call_time) > sensor_function_call_timeout) || startup_flag==true){
+        if( (abs((::min)-sensor_function_call_time) > sensor_function_call_timeout) || startup_flag==true){
             lcd.cls();
             lcd.locate(0,0);
             lcd.printf("Updating Values");
@@ -614,9 +644,80 @@
             lcd.printf("Performing func");
             read_sensors();
             airhumidity();
+            peltierin_temp = dsen_temp_in;
+            peltierout_temp = dsen_temp_out;
             sensor_function_call_time=::min;
             lcd.cls();
         }
+        /**********************PELTIER CALLER************************************************************************/
+        if ( (pelt_keypad_enable == true) && (pelt_overheat == false) ){
+            if ( ( abs( (::min)-pelt_call_time ) > pelt_call_timeout ) || pelt_first_time == true) {
+                
+                lcd.cls();
+                lcd.locate(0,0);
+                lcd.printf("Adjusting Temperature");
+                lcd.locate(0,1);
+                lcd.printf("Pelt Functions");
+            
+                pelt_first_time = false ;
+                 
+                float pelt_inside_temp =0;
+                bool exit_pelt = false;
+                pelt_inside_temp = get_air_temp_inside(0);
+                
+                while (exit_pelt == false){
+                    
+                    pelt_inside_temp = get_air_temp_inside(0);
+                    
+                    if (dsen_temp_in<desire_temp) {
+                        peltier(true,true,false,true,90);
+                    }
+                    if (dsen_temp_in>=desire_temp) {
+                        peltier(true,true,false,true,0);
+                    }
+                    if (dsen_temp_in>=max_peltier_temp){
+                        
+                        peltier(false,false,false,false,0);
+                        lcd.locate(0,0);
+                        lcd.printf("Pelt TEMP LIMIT");
+                        lcd.locate(0,1);
+                        lcd.printf("Pi %4.2f Po%4.2f",dsen_temp_in,dsen_temp_out);
+                        exit_pelt = true;
+                        pelt_overheat = true;
+                    }
+                    else{
+                        //lcd.cls();
+                        lcd.locate(0,0);
+                        lcd.printf("Air Temp %4.2f",pelt_inside_temp);
+                        lcd.locate(0,1);
+                        lcd.printf("Pi%4.2f Po%4.2f",dsen_temp_in,dsen_temp_out);
+                        wait(15);
+                        if ( (pelt_inside_temp-5<=desire_temp_air) && (pelt_inside_temp+5>=desire_temp_air) ){
+                            lcd.cls();
+                            lcd.locate(0,0);
+                            lcd.printf("Exiting Peltier");
+                            lcd.locate(0,1);
+                            lcd.printf("Temp within Range");
+                            exit_pelt = true; 
+                        }
+                    }
+                }//pelt while end 
+                peltier(false,false,false,false,0);
+                lcd.cls();
+                lcd.locate(0,0);
+                lcd.printf("Pelt Off");
+                wait(5);
+                lcd.cls();
+                //lcd.locate(0,1);
+                //lcd.printf("Temp within Range");
+                
+            }//if block time check end 
+            
+            pelt_call_time = ::min ; 
+            //pelt_keypad_enable = false;
+        }//Pelt IF keypad block end
+        
+        
          printf("MIN: %d\n\r",::min);
         startup_flag = false ;
     }//WHILE END