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:
36:ce0ca02a8253
Parent:
35:8bea464c2028
Child:
37:892872c3fa96
--- a/main.cpp	Sun Apr 13 03:33:42 2014 +0000
+++ b/main.cpp	Sun Apr 13 09:06:37 2014 +0000
@@ -29,11 +29,14 @@
 #include "weight.h"
 #include "weight_pindefs.h"
 
+#include "cycleair.h"
+#include "cycleair_pindef.h"
+
 #include <string>
 using namespace std;
 
 //SERIAL
-Serial bluetooth(PTA2, PTA1);  // tx, rx
+Serial bluetooth_dev(PTA2, PTA1);  // tx, rx
 Serial printer(PTC4,PTC3);  // tx, rx
 //TICKERS
 Ticker timer1ms;
@@ -70,6 +73,20 @@
 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
+
+//*************************FUNCTION CALLBACK FOR SERIAL INTTERUPTS********************************
+void callback_bluetooth() {
+    // Note: you need to actually read from the serial to clear the RX interrupt
+    if(bluetooth_dev.getc()=='S'){
+        
+        printf("Info %c %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f \n\r", status,outside_temp,inside_temp,inside_humidity,outside_humidity,inside_dewpoint,outside_dewpoint,soil1_humid,soil2_humid) ; 
+        
+        //myled = !myled;
+        }
+    //printf("%c\n\r", device.getc());
+    
+}
 
 
 //**************************FUNCTION TO READ SENSORS ********************************************** 
@@ -165,8 +182,10 @@
 void cycleair(){
     
     //Turn on fan 
+    cycle_air_on();
     wait(CYCLE_AIR_TIME);
     //turn of fan 
+    cycle_air_off();
     
 }
 //**********************************LCD TIMEOUT FUNCTION*********************************
@@ -200,8 +219,8 @@
                 lcd.printf("%3.1f",setpoint_air_humidity);
                 key_value2 = Keypad();
                 wait(0.2);
-                if(key_value2 == 73){setpoint_air_humidity++;}
-                else if(key_value2 == 70){setpoint_air_humidity--;}
+                if(key_value2 == 74){setpoint_air_humidity++;}
+                else if(key_value2 == 71){setpoint_air_humidity--;}
                 else if(key_value2 == 75){break_flag=true;} //enter
                 if (setpoint_air_humidity <0 || setpoint_air_humidity >99) {setpoint_air_humidity=30.00;}
             }
@@ -226,11 +245,11 @@
                 lcd.printf(" S2: %4.2f",setpoint_soil_humid2);
                 key_value2 = Keypad();
                 wait(0.2);
-                if(key_value2 == 73){ //up
+                if(key_value2 == 62){ //up
                     setpoint_soil_humid1++;
                     setpoint_soil_humid2++;
                 }
-                else if(key_value2 == 70){//down
+                else if(key_value2 == 59){//down
                     setpoint_soil_humid1--;
                     setpoint_soil_humid2--;
                 }
@@ -257,8 +276,8 @@
                 lcd.printf("%3.1f",setpoint_MAX_air_temp);
                 key_value2 = Keypad();
                 wait(0.2);
-                if(key_value2 == 73){setpoint_MAX_air_temp++;}
-                else if(key_value2 == 70){setpoint_MAX_air_temp--;}
+                if(key_value2 == 74){setpoint_MAX_air_temp++;}
+                else if(key_value2 == 71){setpoint_MAX_air_temp--;}
                 else if(key_value2 == 75){break_flag=true;}
                 if (setpoint_MAX_air_temp <0 || setpoint_MAX_air_temp >99) {setpoint_MAX_air_temp=45.0;}
             }
@@ -316,7 +335,7 @@
             }
             //wait(0.2); 
         }//No Press If Block
-        else if(key_value == 70){//Down Key Pressed if block
+        else if(key_value == 68){//Down Key Pressed if block
             lcd.cls();
             if(overflow_menu==false){
                 counter_menu++;
@@ -325,11 +344,11 @@
             else{overflow_menu=false;}
             
         }//Down Key Pressed if block end
-        else if(key_value == 69){ //OK Key Pressed if block
+        else if(key_value == 65){ //OK Key Pressed if block
             settings_submenu(counter_menu);
             lcd.cls();
         } //OK button if block
-        else if(key_value == 75){ //OK Button
+        else if(key_value == 75){ //ENTR Button
             exit_settings = true;
             lcd.cls();
             lcd.printf("SAVE Config");
@@ -419,6 +438,7 @@
     lcd_backlight_on();   
     //FOR INTERNAL CLOCK
     clock_mine.attach(&sec_inc, 1.0);
+
     char keypad_value;
     int ui_current_screen = 1;
     //************************************BOOT SEQUENCE*********************
@@ -476,7 +496,17 @@
     //led_test();
     
     
+    //INTILIZE SERIAL PARAMETERS
+    wait(2);
+    lcd.cls();
+    lcd.locate(0,0);
+    lcd.printf("Initialize Bluetooth");
+    bluetooth_dev.baud(9600);
+    bluetooth_dev.attach(&callback_bluetooth);
+    
+    
     wait(5);
+    lcd.cls();
     ui_current_screen = 1;
     ui_screen1();
     lcd_timeout.reset();
@@ -498,7 +528,8 @@
         //lcd_timeout_check();
         //process_user_input(keypad_value,ui_current_screen);
         
-        if ( (keypad_value==62) && (ui_current_screen==1) ) {
+        //Press down arrow to change menu
+        if ( (keypad_value==68) && (ui_current_screen==1) ) {
             ui_screen2();
             ui_current_screen=2;
             wait(5);
@@ -507,21 +538,21 @@
             //led_blue.pulsewidth_us(led_blue_pulsewidth);
             //printf("%c\n\r",keypad_value);
         }
-        else if ( (keypad_value==62) && (ui_current_screen==2)) {
+        else if ( (keypad_value==68) && (ui_current_screen==2)) {
             ui_screen3();
             ui_current_screen=3;
             wait(5);
             lcd.cls();
             //printf("%c\n\r",keypad_value);
         }
-        else if ( (keypad_value==62) && (ui_current_screen==3)) {
+        else if ( (keypad_value==68) && (ui_current_screen==3)) {
             ui_screen4();
             ui_current_screen=1;
             wait(5);
             lcd.cls();
             //printf("%c\n\r",keypad_value);
         }
-        else if ( (keypad_value==75) ) {
+        else if ( (keypad_value==75) ) { //Press Enter for settings
             ui_settings();
             ui_current_screen=1;
             lcd.cls();
@@ -533,10 +564,10 @@
             wait(0.1);
         }
         
-        if (keypad_value == 73 ){
+        if (keypad_value == 73 ){ //Backlight red up
             lcd_backlight_on();    
         }
-        if (keypad_value == 70 ){
+        if (keypad_value == 70 ){ //Backlight red down
             lcd_backlight_off();    
         }
         printf("%d\n\r",keypad_value);