Project Autus - Automated Plant Chamber
Fork of keypad_test by
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)
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.
peltier/peltier.cpp@7:1d691f81d455, 2014-04-11 (annotated)
- Committer:
- umairaftab
- Date:
- Fri Apr 11 03:50:38 2014 +0000
- Revision:
- 7:1d691f81d455
- Child:
- 14:72176f1e4907
Merged Plamens, and mine Branches; ; Air Humidity; Soil Moisture; Peltier ; Peltier temp; Keypad; Buzzer; Led Lights ; Pumps
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
umairaftab | 7:1d691f81d455 | 1 | #include "mbed.h" |
umairaftab | 7:1d691f81d455 | 2 | |
umairaftab | 7:1d691f81d455 | 3 | #include "TextLCD.h" |
umairaftab | 7:1d691f81d455 | 4 | #include "DS18B20.h" |
umairaftab | 7:1d691f81d455 | 5 | #include "peltier.h" |
umairaftab | 7:1d691f81d455 | 6 | //Serial pc(USBTX, USBRX); // tx, rx |
umairaftab | 7:1d691f81d455 | 7 | |
umairaftab | 7:1d691f81d455 | 8 | unsigned int peltier_hot_pulsewidth=1000; |
umairaftab | 7:1d691f81d455 | 9 | unsigned int peltier_cold_pulsewidth=1000; |
umairaftab | 7:1d691f81d455 | 10 | unsigned int peltier_period =1000; |
umairaftab | 7:1d691f81d455 | 11 | unsigned int peltier_pulsewidth = 0; |
umairaftab | 7:1d691f81d455 | 12 | unsigned int peltier_step = 10; |
umairaftab | 7:1d691f81d455 | 13 | |
umairaftab | 7:1d691f81d455 | 14 | bool alarm_hi_temp_in=false; |
umairaftab | 7:1d691f81d455 | 15 | bool alarm_lo_temp_in=false; |
umairaftab | 7:1d691f81d455 | 16 | bool alarm_hi_temp_out=false; |
umairaftab | 7:1d691f81d455 | 17 | bool alarm_lo_temp_out=false; |
umairaftab | 7:1d691f81d455 | 18 | |
umairaftab | 7:1d691f81d455 | 19 | //TextLCD lcd(PTE29, PTE30, PTC12, PTD0, PTD5, PTA13, TextLCD::LCD20x2); // rs, e, d4-d7 ok |
umairaftab | 7:1d691f81d455 | 20 | |
umairaftab | 7:1d691f81d455 | 21 | //unsigned int peltier_hot_pulsewidth=1000; |
umairaftab | 7:1d691f81d455 | 22 | //unsigned int peltier_cold_pulsewidth=1000; |
umairaftab | 7:1d691f81d455 | 23 | //unsigned int peltier_period =1000; |
umairaftab | 7:1d691f81d455 | 24 | //unsigned int peltier_pulsewidth = 0; |
umairaftab | 7:1d691f81d455 | 25 | //unsigned int peltier_step = 10; |
umairaftab | 7:1d691f81d455 | 26 | //bool alarm_hi_temp_in=false; |
umairaftab | 7:1d691f81d455 | 27 | //bool alarm_lo_temp_in=false; |
umairaftab | 7:1d691f81d455 | 28 | //bool alarm_hi_temp_out=false; |
umairaftab | 7:1d691f81d455 | 29 | //bool alarm_lo_temp_out=false; |
umairaftab | 7:1d691f81d455 | 30 | float dsen_temp; |
umairaftab | 7:1d691f81d455 | 31 | |
umairaftab | 7:1d691f81d455 | 32 | unsigned int pwm_cold_peltier(int brightness ) |
umairaftab | 7:1d691f81d455 | 33 | { |
umairaftab | 7:1d691f81d455 | 34 | if (brightness==1) { |
umairaftab | 7:1d691f81d455 | 35 | peltier_cold_pulsewidth=peltier_cold_pulsewidth+peltier_step; |
umairaftab | 7:1d691f81d455 | 36 | peltier_cold.pulsewidth_us(peltier_cold_pulsewidth); |
umairaftab | 7:1d691f81d455 | 37 | }; |
umairaftab | 7:1d691f81d455 | 38 | if (brightness==0) { |
umairaftab | 7:1d691f81d455 | 39 | peltier_cold_pulsewidth=peltier_cold_pulsewidth-peltier_step; |
umairaftab | 7:1d691f81d455 | 40 | peltier_cold.pulsewidth_us(peltier_cold_pulsewidth); |
umairaftab | 7:1d691f81d455 | 41 | }; |
umairaftab | 7:1d691f81d455 | 42 | return peltier_cold_pulsewidth; |
umairaftab | 7:1d691f81d455 | 43 | } |
umairaftab | 7:1d691f81d455 | 44 | unsigned int pwm_hot_peltier(int brightness) |
umairaftab | 7:1d691f81d455 | 45 | { |
umairaftab | 7:1d691f81d455 | 46 | if (brightness==1) { |
umairaftab | 7:1d691f81d455 | 47 | peltier_hot_pulsewidth=peltier_hot_pulsewidth+peltier_step; |
umairaftab | 7:1d691f81d455 | 48 | peltier_hot.pulsewidth_us(peltier_hot_pulsewidth); |
umairaftab | 7:1d691f81d455 | 49 | } |
umairaftab | 7:1d691f81d455 | 50 | if (brightness==0) { |
umairaftab | 7:1d691f81d455 | 51 | peltier_hot_pulsewidth=peltier_hot_pulsewidth-peltier_step; |
umairaftab | 7:1d691f81d455 | 52 | peltier_hot.pulsewidth_us(peltier_hot_pulsewidth); |
umairaftab | 7:1d691f81d455 | 53 | } |
umairaftab | 7:1d691f81d455 | 54 | return peltier_hot_pulsewidth; |
umairaftab | 7:1d691f81d455 | 55 | } |
umairaftab | 7:1d691f81d455 | 56 | void peltier(bool fan_in,bool fan_out,bool cold,bool hot,int pwm_procent) |
umairaftab | 7:1d691f81d455 | 57 | { |
umairaftab | 7:1d691f81d455 | 58 | sensor.mode(PullUp); |
umairaftab | 7:1d691f81d455 | 59 | dsen_temp=mytemp(); |
umairaftab | 7:1d691f81d455 | 60 | // ROM_Code_t ROM_Code = ReadROM(); |
umairaftab | 7:1d691f81d455 | 61 | // lcd.setCursor(TextLCD::CurOff_BlkOn); |
umairaftab | 7:1d691f81d455 | 62 | // lcd.locate(0,0); |
umairaftab | 7:1d691f81d455 | 63 | // lcd.printf("Family code: 0x%X\n\r", ROM_Code.BYTES.familyCode); |
umairaftab | 7:1d691f81d455 | 64 | // wait(5.0); |
umairaftab | 7:1d691f81d455 | 65 | |
umairaftab | 7:1d691f81d455 | 66 | en_drv1=0;//disable |
umairaftab | 7:1d691f81d455 | 67 | en_drv2=0;//disable |
umairaftab | 7:1d691f81d455 | 68 | fan_in_peltier=0;//disable |
umairaftab | 7:1d691f81d455 | 69 | fan_out_peltier=0;//disable |
umairaftab | 7:1d691f81d455 | 70 | |
umairaftab | 7:1d691f81d455 | 71 | |
umairaftab | 7:1d691f81d455 | 72 | if(fan_in==true) { |
umairaftab | 7:1d691f81d455 | 73 | fan_in_peltier=1;//enable |
umairaftab | 7:1d691f81d455 | 74 | } |
umairaftab | 7:1d691f81d455 | 75 | if(fan_out==true) { |
umairaftab | 7:1d691f81d455 | 76 | fan_out_peltier=1;//enable |
umairaftab | 7:1d691f81d455 | 77 | } |
umairaftab | 7:1d691f81d455 | 78 | if ((cold==true)||(hot==true)) { |
umairaftab | 7:1d691f81d455 | 79 | en_drv1=1; |
umairaftab | 7:1d691f81d455 | 80 | en_drv2=1; |
umairaftab | 7:1d691f81d455 | 81 | } |
umairaftab | 7:1d691f81d455 | 82 | |
umairaftab | 7:1d691f81d455 | 83 | if ((cold==true)&&(hot==false)) { |
umairaftab | 7:1d691f81d455 | 84 | |
umairaftab | 7:1d691f81d455 | 85 | peltier_cold.period_us(peltier_period); |
umairaftab | 7:1d691f81d455 | 86 | peltier_cold_pulsewidth=pwm_procent*10; |
umairaftab | 7:1d691f81d455 | 87 | peltier_cold.pulsewidth_us(peltier_cold_pulsewidth); |
umairaftab | 7:1d691f81d455 | 88 | } |
umairaftab | 7:1d691f81d455 | 89 | if ((hot==true)&&(cold==false)) { |
umairaftab | 7:1d691f81d455 | 90 | |
umairaftab | 7:1d691f81d455 | 91 | peltier_hot.period_us(peltier_period); |
umairaftab | 7:1d691f81d455 | 92 | peltier_hot_pulsewidth=pwm_procent*10; |
umairaftab | 7:1d691f81d455 | 93 | peltier_hot.pulsewidth_us(peltier_hot_pulsewidth); |
umairaftab | 7:1d691f81d455 | 94 | } |
umairaftab | 7:1d691f81d455 | 95 | //pc.printf("Temp is %2.1fC,dsen temp= %d \n\r", dsen_temp,10); |
umairaftab | 7:1d691f81d455 | 96 | |
umairaftab | 7:1d691f81d455 | 97 | } |
umairaftab | 7:1d691f81d455 | 98 | void pel_c(int pwm) |
umairaftab | 7:1d691f81d455 | 99 | { |
umairaftab | 7:1d691f81d455 | 100 | peltier_cold.period_us(peltier_period); |
umairaftab | 7:1d691f81d455 | 101 | peltier_cold_pulsewidth=pwm*10; |
umairaftab | 7:1d691f81d455 | 102 | peltier_cold.pulsewidth_us(peltier_cold_pulsewidth); |
umairaftab | 7:1d691f81d455 | 103 | |
umairaftab | 7:1d691f81d455 | 104 | } |
umairaftab | 7:1d691f81d455 | 105 | void pel_h(int pwm) |
umairaftab | 7:1d691f81d455 | 106 | { |
umairaftab | 7:1d691f81d455 | 107 | peltier_hot.period_us(peltier_period); |
umairaftab | 7:1d691f81d455 | 108 | peltier_hot_pulsewidth=pwm*10; |
umairaftab | 7:1d691f81d455 | 109 | peltier_hot.pulsewidth_us(peltier_hot_pulsewidth); |
umairaftab | 7:1d691f81d455 | 110 | } |
umairaftab | 7:1d691f81d455 | 111 | void peltier_auto(int degree) |
umairaftab | 7:1d691f81d455 | 112 | { |
umairaftab | 7:1d691f81d455 | 113 | sensor.mode(PullUp); |
umairaftab | 7:1d691f81d455 | 114 | en_drv1=1; |
umairaftab | 7:1d691f81d455 | 115 | en_drv2=1; |
umairaftab | 7:1d691f81d455 | 116 | fan_in_peltier=1;//enable |
umairaftab | 7:1d691f81d455 | 117 | fan_out_peltier=1;//enable |
umairaftab | 7:1d691f81d455 | 118 | while(1) { |
umairaftab | 7:1d691f81d455 | 119 | |
umairaftab | 7:1d691f81d455 | 120 | dsen_temp=mytemp(); |
umairaftab | 7:1d691f81d455 | 121 | |
umairaftab | 7:1d691f81d455 | 122 | if (degree>dsen_temp) { |
umairaftab | 7:1d691f81d455 | 123 | pel_h(0); |
umairaftab | 7:1d691f81d455 | 124 | pel_c(100); |
umairaftab | 7:1d691f81d455 | 125 | } |
umairaftab | 7:1d691f81d455 | 126 | if (degree<dsen_temp) { |
umairaftab | 7:1d691f81d455 | 127 | pel_c(0); |
umairaftab | 7:1d691f81d455 | 128 | pel_h(100); |
umairaftab | 7:1d691f81d455 | 129 | |
umairaftab | 7:1d691f81d455 | 130 | } |
umairaftab | 7:1d691f81d455 | 131 | if (degree==dsen_temp) { |
umairaftab | 7:1d691f81d455 | 132 | pel_c(0); |
umairaftab | 7:1d691f81d455 | 133 | pel_h(0); |
umairaftab | 7:1d691f81d455 | 134 | |
umairaftab | 7:1d691f81d455 | 135 | } |
umairaftab | 7:1d691f81d455 | 136 | |
umairaftab | 7:1d691f81d455 | 137 | /*lcd.cls(); |
umairaftab | 7:1d691f81d455 | 138 | lcd.locate(0,1); |
umairaftab | 7:1d691f81d455 | 139 | pc.printf("Temp is %2.1fC,dsen temp= %d \n\r", dsen_temp,degree); |
umairaftab | 7:1d691f81d455 | 140 | lcd.printf("Temp is %2.1fC\n\r", dsen_temp);*/ |
umairaftab | 7:1d691f81d455 | 141 | |
umairaftab | 7:1d691f81d455 | 142 | |
umairaftab | 7:1d691f81d455 | 143 | |
umairaftab | 7:1d691f81d455 | 144 | //peltier_hot.period_us(peltier_period); |
umairaftab | 7:1d691f81d455 | 145 | //peltier_hot_pulsewidth=1000;//at 50% |
umairaftab | 7:1d691f81d455 | 146 | //pwm_hot_peltier(1); |
umairaftab | 7:1d691f81d455 | 147 | // wait(1.0); |
umairaftab | 7:1d691f81d455 | 148 | |
umairaftab | 7:1d691f81d455 | 149 | |
umairaftab | 7:1d691f81d455 | 150 | |
umairaftab | 7:1d691f81d455 | 151 | /* peltier_cold.period_us(peltier_period); |
umairaftab | 7:1d691f81d455 | 152 | peltier_cold_pulsewidth=peltier_pulsewidth; |
umairaftab | 7:1d691f81d455 | 153 | for (int i=1; i<=100; i++) { |
umairaftab | 7:1d691f81d455 | 154 | pwm_cold_peltier(1); |
umairaftab | 7:1d691f81d455 | 155 | wait (0.1); |
umairaftab | 7:1d691f81d455 | 156 | } |
umairaftab | 7:1d691f81d455 | 157 | for (int i=1; i<=100; i++) { |
umairaftab | 7:1d691f81d455 | 158 | pwm_cold_peltier(0); |
umairaftab | 7:1d691f81d455 | 159 | wait (0.1); |
umairaftab | 7:1d691f81d455 | 160 | } |
umairaftab | 7:1d691f81d455 | 161 | peltier_cold_pulsewidth=10; // set to 0 |
umairaftab | 7:1d691f81d455 | 162 | pwm_cold_peltier(0); // set to 0 |
umairaftab | 7:1d691f81d455 | 163 | |
umairaftab | 7:1d691f81d455 | 164 | peltier_hot.period_us(peltier_period); |
umairaftab | 7:1d691f81d455 | 165 | peltier_hot_pulsewidth=peltier_pulsewidth; |
umairaftab | 7:1d691f81d455 | 166 | for (int i=1; i<=100; i++) { |
umairaftab | 7:1d691f81d455 | 167 | pwm_hot_peltier(1); |
umairaftab | 7:1d691f81d455 | 168 | wait (0.1); |
umairaftab | 7:1d691f81d455 | 169 | } |
umairaftab | 7:1d691f81d455 | 170 | for (int i=1; i<=100; i++) { |
umairaftab | 7:1d691f81d455 | 171 | pwm_hot_peltier(0); |
umairaftab | 7:1d691f81d455 | 172 | wait (0.1); |
umairaftab | 7:1d691f81d455 | 173 | } |
umairaftab | 7:1d691f81d455 | 174 | peltier_hot_pulsewidth=10; // set to 0 |
umairaftab | 7:1d691f81d455 | 175 | pwm_hot_peltier(0); // set to 0 |
umairaftab | 7:1d691f81d455 | 176 | */ |
umairaftab | 7:1d691f81d455 | 177 | } |
umairaftab | 7:1d691f81d455 | 178 | |
umairaftab | 7:1d691f81d455 | 179 | } |