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

peltier/peltier.cpp

Committer:
umairaftab
Date:
2014-04-12
Revision:
14:72176f1e4907
Parent:
7:1d691f81d455
Child:
38:9f4107db1bff

File content as of revision 14:72176f1e4907:

#include "mbed.h"

#include "TextLCD.h"
#include "DS18B20.h"
#include "peltier.h"
//Serial pc(USBTX, USBRX); // tx, rx

unsigned int peltier_hot_pulsewidth=1000;
unsigned int peltier_cold_pulsewidth=1000;
unsigned int peltier_period =1000;
unsigned int peltier_pulsewidth = 0;
unsigned int peltier_step = 10;

bool alarm_hi_temp_in=false;
bool alarm_lo_temp_in=false;
bool alarm_hi_temp_out=false;
bool alarm_lo_temp_out=false;

//TextLCD lcd(PTE29, PTE30, PTC12, PTD0, PTD5, PTA13, TextLCD::LCD20x2);   // rs, e, d4-d7 ok

//unsigned int peltier_hot_pulsewidth=1000;
//unsigned int peltier_cold_pulsewidth=1000;
//unsigned int peltier_period =1000;
//unsigned int peltier_pulsewidth = 0;
//unsigned int peltier_step = 10;
//bool alarm_hi_temp_in=false;
//bool alarm_lo_temp_in=false;
//bool alarm_hi_temp_out=false;
//bool alarm_lo_temp_out=false;
float dsen_temp;

unsigned int pwm_cold_peltier(int brightness )
{
    if (brightness==1) {
        peltier_cold_pulsewidth=peltier_cold_pulsewidth+peltier_step;
        peltier_cold.pulsewidth_us(peltier_cold_pulsewidth);
    };
    if (brightness==0) {
        peltier_cold_pulsewidth=peltier_cold_pulsewidth-peltier_step;
        peltier_cold.pulsewidth_us(peltier_cold_pulsewidth);
    };
    return peltier_cold_pulsewidth;
}
unsigned int pwm_hot_peltier(int brightness)
{
    if (brightness==1) {
        peltier_hot_pulsewidth=peltier_hot_pulsewidth+peltier_step;
        peltier_hot.pulsewidth_us(peltier_hot_pulsewidth);
    }
    if (brightness==0) {
        peltier_hot_pulsewidth=peltier_hot_pulsewidth-peltier_step;
        peltier_hot.pulsewidth_us(peltier_hot_pulsewidth);
    }
    return peltier_hot_pulsewidth;
}
void peltier(bool fan_in,bool fan_out,bool cold,bool hot,int pwm_procent)
{
    //sensor.mode(PullUp);
    //dsen_temp=mytemp();
    //  ROM_Code_t ROM_Code = ReadROM();
    //  lcd.setCursor(TextLCD::CurOff_BlkOn);
    //  lcd.locate(0,0);
    //  lcd.printf("Family code: 0x%X\n\r", ROM_Code.BYTES.familyCode);
    //  wait(5.0);

    en_drv1=0;//disable
    en_drv2=0;//disable
    fan_in_peltier=0;//disable
    fan_out_peltier=0;//disable


    if(fan_in==true) {
        fan_in_peltier=1;//enable
    }
    if(fan_out==true) {
        fan_out_peltier=1;//enable
    }
    if ((cold==true)||(hot==true)) {
        en_drv1=1;
        en_drv2=1;
    }

    if ((cold==true)&&(hot==false)) {

        peltier_cold.period_us(peltier_period);
        peltier_cold_pulsewidth=pwm_procent*10;
        peltier_cold.pulsewidth_us(peltier_cold_pulsewidth);
    }
    if ((hot==true)&&(cold==false)) {

        peltier_hot.period_us(peltier_period);
        peltier_hot_pulsewidth=pwm_procent*10;
        peltier_hot.pulsewidth_us(peltier_hot_pulsewidth);
    }
    //pc.printf("Temp is %2.1fC,dsen temp= %d \n\r", dsen_temp,10);

}
void pel_c(int pwm)
{
    peltier_cold.period_us(peltier_period);
    peltier_cold_pulsewidth=pwm*10;
    peltier_cold.pulsewidth_us(peltier_cold_pulsewidth);

}
void pel_h(int pwm)
{
    peltier_hot.period_us(peltier_period);
    peltier_hot_pulsewidth=pwm*10;
    peltier_hot.pulsewidth_us(peltier_hot_pulsewidth);
}
void peltier_auto(int degree)
{
    sensor.mode(PullUp);
    en_drv1=1;
    en_drv2=1;
    fan_in_peltier=1;//enable
    fan_out_peltier=1;//enable
    while(1) {

        dsen_temp=mytemp();

        if (degree>dsen_temp) {
            pel_h(0);
            pel_c(100);
        }
        if (degree<dsen_temp) {
            pel_c(0);
            pel_h(100);

        }
        if (degree==dsen_temp) {
            pel_c(0);
            pel_h(0);

        }

        /*lcd.cls();
        lcd.locate(0,1);
        pc.printf("Temp is %2.1fC,dsen temp= %d \n\r", dsen_temp,degree);
        lcd.printf("Temp is %2.1fC\n\r", dsen_temp);*/



        //peltier_hot.period_us(peltier_period);
        //peltier_hot_pulsewidth=1000;//at 50%
        //pwm_hot_peltier(1);
        // wait(1.0);



        /* peltier_cold.period_us(peltier_period);
         peltier_cold_pulsewidth=peltier_pulsewidth;
         for (int i=1; i<=100; i++) {
             pwm_cold_peltier(1);
             wait (0.1);
         }
         for (int i=1; i<=100; i++) {
             pwm_cold_peltier(0);
             wait (0.1);
         }
         peltier_cold_pulsewidth=10;    // set to 0
         pwm_cold_peltier(0);           // set to 0

         peltier_hot.period_us(peltier_period);
         peltier_hot_pulsewidth=peltier_pulsewidth;
         for (int i=1; i<=100; i++) {
             pwm_hot_peltier(1);
             wait (0.1);
         }
         for (int i=1; i<=100; i++) {
             pwm_hot_peltier(0);
             wait (0.1);
         }
         peltier_hot_pulsewidth=10;    // set to 0
         pwm_hot_peltier(0);           // set to 0
         */
    }

}