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

Committer:
umairaftab
Date:
Mon Apr 14 04:25:50 2014 +0000
Revision:
43:cf893fa88690
Parent:
42:41f6c241a987
Child:
45:ad99cb94f685
pelt temp test 2.1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
umairaftab 7:1d691f81d455 1 #include "mbed.h"
umairaftab 7:1d691f81d455 2
umairaftab 7:1d691f81d455 3 #include "TextLCD.h"
umairaftab 38:9f4107db1bff 4 //#include "DS18B20.h"
umairaftab 38:9f4107db1bff 5 #include "peltier.h"
umairaftab 38:9f4107db1bff 6 //----------------------------------
umairaftab 7:1d691f81d455 7 #include "DS18B20.h"
umairaftab 38:9f4107db1bff 8 #include "OneWireDefs.h"
umairaftab 38:9f4107db1bff 9
umairaftab 38:9f4107db1bff 10 #define THERMOMETER DS18B20
umairaftab 38:9f4107db1bff 11
umairaftab 38:9f4107db1bff 12 float temp;
umairaftab 38:9f4107db1bff 13 float dsen_temp_in;
umairaftab 38:9f4107db1bff 14 float dsen_temp_out;
umairaftab 38:9f4107db1bff 15 // device( mbed pin )
umairaftab 38:9f4107db1bff 16 THERMOMETER device(PTE0);
umairaftab 38:9f4107db1bff 17
umairaftab 38:9f4107db1bff 18
umairaftab 38:9f4107db1bff 19 //-----------------------------------
umairaftab 7:1d691f81d455 20 //Serial pc(USBTX, USBRX); // tx, rx
umairaftab 7:1d691f81d455 21
umairaftab 7:1d691f81d455 22 unsigned int peltier_hot_pulsewidth=1000;
umairaftab 7:1d691f81d455 23 unsigned int peltier_cold_pulsewidth=1000;
umairaftab 7:1d691f81d455 24 unsigned int peltier_period =1000;
umairaftab 7:1d691f81d455 25 unsigned int peltier_pulsewidth = 0;
umairaftab 7:1d691f81d455 26 unsigned int peltier_step = 10;
umairaftab 7:1d691f81d455 27
umairaftab 7:1d691f81d455 28 bool alarm_hi_temp_in=false;
umairaftab 7:1d691f81d455 29 bool alarm_lo_temp_in=false;
umairaftab 7:1d691f81d455 30 bool alarm_hi_temp_out=false;
umairaftab 7:1d691f81d455 31 bool alarm_lo_temp_out=false;
umairaftab 7:1d691f81d455 32
umairaftab 7:1d691f81d455 33 //TextLCD lcd(PTE29, PTE30, PTC12, PTD0, PTD5, PTA13, TextLCD::LCD20x2); // rs, e, d4-d7 ok
umairaftab 38:9f4107db1bff 34 //DigitalOut backlight(PTD6);
umairaftab 7:1d691f81d455 35 //unsigned int peltier_hot_pulsewidth=1000;
umairaftab 7:1d691f81d455 36 //unsigned int peltier_cold_pulsewidth=1000;
umairaftab 7:1d691f81d455 37 //unsigned int peltier_period =1000;
umairaftab 7:1d691f81d455 38 //unsigned int peltier_pulsewidth = 0;
umairaftab 7:1d691f81d455 39 //unsigned int peltier_step = 10;
umairaftab 7:1d691f81d455 40 //bool alarm_hi_temp_in=false;
umairaftab 7:1d691f81d455 41 //bool alarm_lo_temp_in=false;
umairaftab 7:1d691f81d455 42 //bool alarm_hi_temp_out=false;
umairaftab 7:1d691f81d455 43 //bool alarm_lo_temp_out=false;
umairaftab 7:1d691f81d455 44 float dsen_temp;
umairaftab 7:1d691f81d455 45
umairaftab 38:9f4107db1bff 46 void readTemp(int deviceNum)
umairaftab 38:9f4107db1bff 47 {
umairaftab 38:9f4107db1bff 48 temp = device.readTemperature(deviceNum);
umairaftab 43:cf893fa88690 49 printf("Device %d is %f\n\r",deviceNum, temp);
umairaftab 38:9f4107db1bff 50 wait(0.5);
umairaftab 38:9f4107db1bff 51 }
umairaftab 38:9f4107db1bff 52 void tempinit(void)
umairaftab 38:9f4107db1bff 53 {
umairaftab 38:9f4107db1bff 54 while (!device.initialize()); // keep calling until it works
umairaftab 38:9f4107db1bff 55
umairaftab 38:9f4107db1bff 56 int deviceCount = device.getDeviceCount();
umairaftab 43:cf893fa88690 57 printf("Found %d sensors\n\r",deviceCount);
umairaftab 38:9f4107db1bff 58
umairaftab 38:9f4107db1bff 59 device.setResolution(twelveBit);
umairaftab 38:9f4107db1bff 60 }
umairaftab 7:1d691f81d455 61 unsigned int pwm_cold_peltier(int brightness )
umairaftab 7:1d691f81d455 62 {
umairaftab 7:1d691f81d455 63 if (brightness==1) {
umairaftab 7:1d691f81d455 64 peltier_cold_pulsewidth=peltier_cold_pulsewidth+peltier_step;
umairaftab 7:1d691f81d455 65 peltier_cold.pulsewidth_us(peltier_cold_pulsewidth);
umairaftab 7:1d691f81d455 66 };
umairaftab 7:1d691f81d455 67 if (brightness==0) {
umairaftab 7:1d691f81d455 68 peltier_cold_pulsewidth=peltier_cold_pulsewidth-peltier_step;
umairaftab 7:1d691f81d455 69 peltier_cold.pulsewidth_us(peltier_cold_pulsewidth);
umairaftab 7:1d691f81d455 70 };
umairaftab 7:1d691f81d455 71 return peltier_cold_pulsewidth;
umairaftab 7:1d691f81d455 72 }
umairaftab 7:1d691f81d455 73 unsigned int pwm_hot_peltier(int brightness)
umairaftab 7:1d691f81d455 74 {
umairaftab 7:1d691f81d455 75 if (brightness==1) {
umairaftab 7:1d691f81d455 76 peltier_hot_pulsewidth=peltier_hot_pulsewidth+peltier_step;
umairaftab 7:1d691f81d455 77 peltier_hot.pulsewidth_us(peltier_hot_pulsewidth);
umairaftab 7:1d691f81d455 78 }
umairaftab 7:1d691f81d455 79 if (brightness==0) {
umairaftab 7:1d691f81d455 80 peltier_hot_pulsewidth=peltier_hot_pulsewidth-peltier_step;
umairaftab 7:1d691f81d455 81 peltier_hot.pulsewidth_us(peltier_hot_pulsewidth);
umairaftab 7:1d691f81d455 82 }
umairaftab 7:1d691f81d455 83 return peltier_hot_pulsewidth;
umairaftab 7:1d691f81d455 84 }
umairaftab 7:1d691f81d455 85 void peltier(bool fan_in,bool fan_out,bool cold,bool hot,int pwm_procent)
umairaftab 7:1d691f81d455 86 {
umairaftab 38:9f4107db1bff 87 //tempinit();
umairaftab 14:72176f1e4907 88 //sensor.mode(PullUp);
umairaftab 38:9f4107db1bff 89 // readTemp(1);
umairaftab 38:9f4107db1bff 90 // dsen_temp_in=temp;
umairaftab 7:1d691f81d455 91 // ROM_Code_t ROM_Code = ReadROM();
umairaftab 7:1d691f81d455 92 // lcd.setCursor(TextLCD::CurOff_BlkOn);
umairaftab 7:1d691f81d455 93 // lcd.locate(0,0);
umairaftab 7:1d691f81d455 94 // lcd.printf("Family code: 0x%X\n\r", ROM_Code.BYTES.familyCode);
umairaftab 7:1d691f81d455 95 // wait(5.0);
umairaftab 42:41f6c241a987 96 bool read_temp_flag = true;
umairaftab 42:41f6c241a987 97 if( fan_in==false && fan_out==false && cold == false && hot==false){
umairaftab 42:41f6c241a987 98 read_temp_flag = false;
umairaftab 42:41f6c241a987 99 }
umairaftab 7:1d691f81d455 100 en_drv1=0;//disable
umairaftab 7:1d691f81d455 101 en_drv2=0;//disable
umairaftab 7:1d691f81d455 102 fan_in_peltier=0;//disable
umairaftab 7:1d691f81d455 103 fan_out_peltier=0;//disable
umairaftab 7:1d691f81d455 104
umairaftab 7:1d691f81d455 105
umairaftab 7:1d691f81d455 106 if(fan_in==true) {
umairaftab 7:1d691f81d455 107 fan_in_peltier=1;//enable
umairaftab 7:1d691f81d455 108 }
umairaftab 7:1d691f81d455 109 if(fan_out==true) {
umairaftab 7:1d691f81d455 110 fan_out_peltier=1;//enable
umairaftab 7:1d691f81d455 111 }
umairaftab 7:1d691f81d455 112 if ((cold==true)||(hot==true)) {
umairaftab 7:1d691f81d455 113 en_drv1=1;
umairaftab 7:1d691f81d455 114 en_drv2=1;
umairaftab 7:1d691f81d455 115 }
umairaftab 7:1d691f81d455 116
umairaftab 7:1d691f81d455 117 if ((cold==true)&&(hot==false)) {
umairaftab 7:1d691f81d455 118
umairaftab 7:1d691f81d455 119 peltier_cold.period_us(peltier_period);
umairaftab 7:1d691f81d455 120 peltier_cold_pulsewidth=pwm_procent*10;
umairaftab 7:1d691f81d455 121 peltier_cold.pulsewidth_us(peltier_cold_pulsewidth);
umairaftab 7:1d691f81d455 122 }
umairaftab 7:1d691f81d455 123 if ((hot==true)&&(cold==false)) {
umairaftab 7:1d691f81d455 124
umairaftab 7:1d691f81d455 125 peltier_hot.period_us(peltier_period);
umairaftab 7:1d691f81d455 126 peltier_hot_pulsewidth=pwm_procent*10;
umairaftab 7:1d691f81d455 127 peltier_hot.pulsewidth_us(peltier_hot_pulsewidth);
umairaftab 7:1d691f81d455 128 }
umairaftab 42:41f6c241a987 129
umairaftab 42:41f6c241a987 130 if(read_temp_flag){
umairaftab 38:9f4107db1bff 131 readTemp(1);
umairaftab 38:9f4107db1bff 132 dsen_temp_in=temp;
umairaftab 38:9f4107db1bff 133 readTemp(0);
umairaftab 38:9f4107db1bff 134 dsen_temp_out=temp;
umairaftab 42:41f6c241a987 135 }
umairaftab 41:f484ea386062 136 printf("inside Temp is %2.1fC, outside temp plate is %2.1fC\n\r", dsen_temp_in,dsen_temp_out);
umairaftab 38:9f4107db1bff 137 //lcd.cls();
umairaftab 38:9f4107db1bff 138 // lcd.locate(0,1);
umairaftab 38:9f4107db1bff 139 // lcd.printf("Temp is %2.1fC\n\r", dsen_temp_in);
umairaftab 7:1d691f81d455 140
umairaftab 7:1d691f81d455 141 }
umairaftab 7:1d691f81d455 142 void pel_c(int pwm)
umairaftab 7:1d691f81d455 143 {
umairaftab 7:1d691f81d455 144 peltier_cold.period_us(peltier_period);
umairaftab 7:1d691f81d455 145 peltier_cold_pulsewidth=pwm*10;
umairaftab 7:1d691f81d455 146 peltier_cold.pulsewidth_us(peltier_cold_pulsewidth);
umairaftab 7:1d691f81d455 147
umairaftab 7:1d691f81d455 148 }
umairaftab 7:1d691f81d455 149 void pel_h(int pwm)
umairaftab 7:1d691f81d455 150 {
umairaftab 7:1d691f81d455 151 peltier_hot.period_us(peltier_period);
umairaftab 7:1d691f81d455 152 peltier_hot_pulsewidth=pwm*10;
umairaftab 7:1d691f81d455 153 peltier_hot.pulsewidth_us(peltier_hot_pulsewidth);
umairaftab 7:1d691f81d455 154 }
umairaftab 38:9f4107db1bff 155 void peltier_auto(float degree){
umairaftab 38:9f4107db1bff 156 //tempinit();
umairaftab 38:9f4107db1bff 157
umairaftab 38:9f4107db1bff 158 // backlight=1;
umairaftab 38:9f4107db1bff 159
umairaftab 7:1d691f81d455 160 en_drv1=1;
umairaftab 7:1d691f81d455 161 en_drv2=1;
umairaftab 7:1d691f81d455 162 fan_in_peltier=1;//enable
umairaftab 7:1d691f81d455 163 fan_out_peltier=1;//enable
umairaftab 7:1d691f81d455 164 while(1) {
umairaftab 7:1d691f81d455 165
umairaftab 38:9f4107db1bff 166 readTemp(1);
umairaftab 38:9f4107db1bff 167 dsen_temp_in=temp;
umairaftab 7:1d691f81d455 168
umairaftab 38:9f4107db1bff 169 /* (degree>dsen_temp) {
umairaftab 7:1d691f81d455 170 pel_h(0);
umairaftab 38:9f4107db1bff 171 pel_c(90);
umairaftab 38:9f4107db1bff 172 }*/
umairaftab 38:9f4107db1bff 173 if (degree<dsen_temp_in) {
umairaftab 7:1d691f81d455 174 pel_c(0);
umairaftab 38:9f4107db1bff 175 pel_h(90);
umairaftab 7:1d691f81d455 176
umairaftab 7:1d691f81d455 177 }
umairaftab 38:9f4107db1bff 178 if (degree==dsen_temp_in) {
umairaftab 7:1d691f81d455 179 pel_c(0);
umairaftab 7:1d691f81d455 180 pel_h(0);
umairaftab 7:1d691f81d455 181
umairaftab 7:1d691f81d455 182 }
umairaftab 7:1d691f81d455 183
umairaftab 38:9f4107db1bff 184 //lcd.cls();
umairaftab 38:9f4107db1bff 185 //lcd.locate(0,1);
umairaftab 38:9f4107db1bff 186
umairaftab 38:9f4107db1bff 187 readTemp(1);
umairaftab 38:9f4107db1bff 188 dsen_temp_in=temp;
umairaftab 38:9f4107db1bff 189 readTemp(0);
umairaftab 38:9f4107db1bff 190 dsen_temp_out=temp;
umairaftab 38:9f4107db1bff 191 //pc.printf("Temp is %2.1fC,dsen temp= %2.1f , outchamber plate temp =%2.1fC\n\r", dsen_temp_in,degree,dsen_temp_out);
umairaftab 38:9f4107db1bff 192 // lcd.printf("Temp is %2.1fC\n\r", dsen_temp);
umairaftab 7:1d691f81d455 193
umairaftab 7:1d691f81d455 194
umairaftab 7:1d691f81d455 195
umairaftab 7:1d691f81d455 196 //peltier_hot.period_us(peltier_period);
umairaftab 7:1d691f81d455 197 //peltier_hot_pulsewidth=1000;//at 50%
umairaftab 7:1d691f81d455 198 //pwm_hot_peltier(1);
umairaftab 7:1d691f81d455 199 // wait(1.0);
umairaftab 7:1d691f81d455 200
umairaftab 7:1d691f81d455 201
umairaftab 7:1d691f81d455 202
umairaftab 7:1d691f81d455 203 /* peltier_cold.period_us(peltier_period);
umairaftab 7:1d691f81d455 204 peltier_cold_pulsewidth=peltier_pulsewidth;
umairaftab 7:1d691f81d455 205 for (int i=1; i<=100; i++) {
umairaftab 7:1d691f81d455 206 pwm_cold_peltier(1);
umairaftab 7:1d691f81d455 207 wait (0.1);
umairaftab 7:1d691f81d455 208 }
umairaftab 7:1d691f81d455 209 for (int i=1; i<=100; i++) {
umairaftab 7:1d691f81d455 210 pwm_cold_peltier(0);
umairaftab 7:1d691f81d455 211 wait (0.1);
umairaftab 7:1d691f81d455 212 }
umairaftab 7:1d691f81d455 213 peltier_cold_pulsewidth=10; // set to 0
umairaftab 7:1d691f81d455 214 pwm_cold_peltier(0); // set to 0
umairaftab 7:1d691f81d455 215
umairaftab 7:1d691f81d455 216 peltier_hot.period_us(peltier_period);
umairaftab 7:1d691f81d455 217 peltier_hot_pulsewidth=peltier_pulsewidth;
umairaftab 7:1d691f81d455 218 for (int i=1; i<=100; i++) {
umairaftab 7:1d691f81d455 219 pwm_hot_peltier(1);
umairaftab 7:1d691f81d455 220 wait (0.1);
umairaftab 7:1d691f81d455 221 }
umairaftab 7:1d691f81d455 222 for (int i=1; i<=100; i++) {
umairaftab 7:1d691f81d455 223 pwm_hot_peltier(0);
umairaftab 7:1d691f81d455 224 wait (0.1);
umairaftab 7:1d691f81d455 225 }
umairaftab 7:1d691f81d455 226 peltier_hot_pulsewidth=10; // set to 0
umairaftab 7:1d691f81d455 227 pwm_hot_peltier(0); // set to 0
umairaftab 7:1d691f81d455 228 */
umairaftab 7:1d691f81d455 229 }
umairaftab 7:1d691f81d455 230
umairaftab 7:1d691f81d455 231 }