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

main.cpp

Committer:
umairaftab
Date:
2014-04-11
Revision:
9:43c339533f7f
Parent:
8:2d462919519e
Child:
10:1a0fe96381b0

File content as of revision 9:43c339533f7f:


//QUICK REFS:
// TICKER is using timer 1 for buzzer. 

#include "mbed.h"

#include "keypad.h"
#include "buzz.h"

#include "pindefs.h" //led pin definitions
#include "led_lights.h"

#include "peltier.h"
#include "peltier_pindefs.h"

#include "pumps.h"
#include "pumps_pindefs.h"

#include "airhumidity.h"
#include "soilmoisture.h"
#include "soilmoisture_pindefs.h"

#include "ui.h"
#include "ui_pindefs.h"
#include "TextLCD.h"

#include "rtcimp.h"

//SERIAL
Serial bluetooth(PTA2, PTA1);  // tx, rx
Serial printer(PTC4,PTC3);  // tx, rx
//TICKERS
Ticker timer1ms;
Ticker clock_mine;
//FLAGS
bool startup_flag=true; 
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 ;
float setpoint_soil_humid1 = 0.3 ;
float setpoint_soil_humid2 = 0.3 ;

//WINDOWING
float window_f = 5 ;
int window_i =2 ;

//GLOBAL VARS
float current_water_level = 0; 

//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(){
    
    //Read values for AIR
    
    //OUTSIDE
    outside_humidity = get_air_humid_outside();
    outside_temp = get_air_temp_outside(temp_unit); 
    outside_dewpoint = get_air_dewpoint_outside();
    
    //INSIDE
    inside_humidity = get_air_humid_inside();
    inside_temp = get_air_temp_inside(temp_unit); 
    inside_dewpoint = get_air_dewpoint_inside();
    
    //Read value for soil
    read_soil_humidity();
    calc_soil_humid_values(); //values in soil1_humid and soil2_humid perecentages
    
}

//****************************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 **********************
void disable_everything(){
    
    //Disable peltier,vac,fans,pumps.
    
}


//*********************************************************************************************
//*                                                                                           *
//*                                                                                           *
//*                                                                                           *
//*                                                                                           *
//*                                    MAIN ROUTINE                                           *
//*                                                                                           *
//*                           DO NOT MODIFY WITHOUT TELLING UMAIR                             *
//*                                                                                           *
//*                                                                                           *
//*********************************************************************************************

int main(void)
{
    
    //call function that disables everything.
    disable_everything();
    
    
    
    //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

        
}