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 19:18:14 2014 +0000
Revision:
57:7ab93ed49b70
Parent:
38:9f4107db1bff
Cosmetic Changes, Menus added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
umairaftab 38:9f4107db1bff 1 /*
umairaftab 38:9f4107db1bff 2 * DS18B20. Maxim DS18B20 One-Wire Thermometer.
umairaftab 38:9f4107db1bff 3 * Uses the OneWireCRC library.
umairaftab 38:9f4107db1bff 4 *
umairaftab 38:9f4107db1bff 5 * Copyright (C) <2010> Petras Saduikis <petras@petras.co.uk>
umairaftab 38:9f4107db1bff 6 *
umairaftab 38:9f4107db1bff 7 * This file is part of OneWireThermometer.
umairaftab 38:9f4107db1bff 8 *
umairaftab 38:9f4107db1bff 9 * OneWireThermometer is free software: you can redistribute it and/or modify
umairaftab 38:9f4107db1bff 10 * it under the terms of the GNU General Public License as published by
umairaftab 38:9f4107db1bff 11 * the Free Software Foundation, either version 3 of the License, or
umairaftab 38:9f4107db1bff 12 * (at your option) any later version.
umairaftab 38:9f4107db1bff 13 *
umairaftab 38:9f4107db1bff 14 * OneWireThermometer is distributed in the hope that it will be useful,
umairaftab 38:9f4107db1bff 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
umairaftab 38:9f4107db1bff 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
umairaftab 38:9f4107db1bff 17 * GNU General Public License for more details.
umairaftab 38:9f4107db1bff 18 *
umairaftab 38:9f4107db1bff 19 * You should have received a copy of the GNU General Public License
umairaftab 38:9f4107db1bff 20 * along with OneWireThermometer. If not, see <http://www.gnu.org/licenses/>.
umairaftab 38:9f4107db1bff 21 */
umairaftab 38:9f4107db1bff 22
umairaftab 38:9f4107db1bff 23 #include "DS18B20.h"
umairaftab 38:9f4107db1bff 24 //#include "DebugTrace.h"
umairaftab 38:9f4107db1bff 25
umairaftab 38:9f4107db1bff 26 //DebugTrace pc_ds18B20(OFF, TO_SERIAL);
umairaftab 38:9f4107db1bff 27
umairaftab 38:9f4107db1bff 28 DS18B20::DS18B20( PinName pin) :
umairaftab 38:9f4107db1bff 29 OneWireThermometer(pin, DS18B20_ID)
umairaftab 38:9f4107db1bff 30 {
umairaftab 38:9f4107db1bff 31 }
umairaftab 38:9f4107db1bff 32
umairaftab 38:9f4107db1bff 33 void DS18B20::setResolution(eResolution resln)
umairaftab 38:9f4107db1bff 34 {
umairaftab 38:9f4107db1bff 35 // as the write to the configuration register involves a write to the
umairaftab 38:9f4107db1bff 36 // high and low alarm bytes, need to read these registers first
umairaftab 38:9f4107db1bff 37 // and copy them back on the write
umairaftab 38:9f4107db1bff 38
umairaftab 38:9f4107db1bff 39 BYTE read_data[THERMOM_SCRATCHPAD_SIZE];
umairaftab 38:9f4107db1bff 40 BYTE write_data[ALARM_CONFIG_SIZE];
umairaftab 38:9f4107db1bff 41
umairaftab 38:9f4107db1bff 42 if (readAndValidateData(read_data))
umairaftab 38:9f4107db1bff 43 {
umairaftab 38:9f4107db1bff 44 // copy alarm and config data to write data
umairaftab 38:9f4107db1bff 45 for (int k = 2; k < 5; k++)
umairaftab 38:9f4107db1bff 46 {
umairaftab 38:9f4107db1bff 47 write_data[k - 2] = read_data[k];
umairaftab 38:9f4107db1bff 48 }
umairaftab 38:9f4107db1bff 49 int config = write_data[2];
umairaftab 38:9f4107db1bff 50 config &= 0x9F;
umairaftab 38:9f4107db1bff 51 config ^= (resln << 5);
umairaftab 38:9f4107db1bff 52 write_data[2] = config;
umairaftab 38:9f4107db1bff 53
umairaftab 38:9f4107db1bff 54 resetAndAddress();
umairaftab 38:9f4107db1bff 55 oneWire.writeByte(WRITESCRATCH);
umairaftab 38:9f4107db1bff 56 for (int k = 0; k < 3; k++)
umairaftab 38:9f4107db1bff 57 {
umairaftab 38:9f4107db1bff 58 oneWire.writeByte(write_data[k]);
umairaftab 38:9f4107db1bff 59 }
umairaftab 38:9f4107db1bff 60
umairaftab 38:9f4107db1bff 61 // remember it so we can use the correct delay in reading the temperature
umairaftab 38:9f4107db1bff 62 // for parasitic power
umairaftab 38:9f4107db1bff 63 resolution = resln;
umairaftab 38:9f4107db1bff 64 }
umairaftab 38:9f4107db1bff 65 }
umairaftab 38:9f4107db1bff 66
umairaftab 38:9f4107db1bff 67 float DS18B20::calculateTemperature(BYTE* data)
umairaftab 38:9f4107db1bff 68 {
umairaftab 38:9f4107db1bff 69 bool signBit = false;
umairaftab 38:9f4107db1bff 70 if (data[TEMPERATURE_MSB] & 0x80) signBit = true;
umairaftab 38:9f4107db1bff 71
umairaftab 38:9f4107db1bff 72 int read_temp = (data[TEMPERATURE_MSB] << 8) + data[TEMPERATURE_LSB];
umairaftab 38:9f4107db1bff 73 if (signBit)
umairaftab 38:9f4107db1bff 74 {
umairaftab 38:9f4107db1bff 75 read_temp = (read_temp ^ 0xFFFF) + 1; // two's complement
umairaftab 38:9f4107db1bff 76 read_temp *= -1;
umairaftab 38:9f4107db1bff 77 }
umairaftab 38:9f4107db1bff 78
umairaftab 38:9f4107db1bff 79 int resolution = (data[CONFIG_REG_BYTE] & 0x60) >> 5; // mask off bits 6,5 and move to 1,0
umairaftab 38:9f4107db1bff 80 switch (resolution)
umairaftab 38:9f4107db1bff 81 {
umairaftab 38:9f4107db1bff 82 case nineBit: // 0.5 deg C increments
umairaftab 38:9f4107db1bff 83 read_temp &= 0xFFF8; // bits 2,1,0 are undefined
umairaftab 38:9f4107db1bff 84 //pc_ds18B20.traceOut("9 bit resolution ...\r\n");
umairaftab 38:9f4107db1bff 85 break;
umairaftab 38:9f4107db1bff 86 case tenBit: // 0.25 deg C increments
umairaftab 38:9f4107db1bff 87 read_temp &= 0xFFFC; // bits 1,0 are undefined
umairaftab 38:9f4107db1bff 88 //pc_ds18B20.traceOut("10 bit resolution ...\r\n");
umairaftab 38:9f4107db1bff 89 break;
umairaftab 38:9f4107db1bff 90 case elevenBit: // 0.125 deg C increments
umairaftab 38:9f4107db1bff 91 read_temp &= 0xFFFE; // bit 0 is undefined
umairaftab 38:9f4107db1bff 92 //pc_ds18B20.traceOut("11 bit resolution ...\r\n");
umairaftab 38:9f4107db1bff 93 break;
umairaftab 38:9f4107db1bff 94 case twelveBit: // 0.0625 deg C increments
umairaftab 38:9f4107db1bff 95 //pc_ds18B20.traceOut("12 bit resolution ...\r\n");
umairaftab 38:9f4107db1bff 96 break;
umairaftab 38:9f4107db1bff 97 }
umairaftab 38:9f4107db1bff 98 float realTemp = (float)read_temp/16 ;
umairaftab 38:9f4107db1bff 99
umairaftab 38:9f4107db1bff 100 //pc_ds18B20.traceOut("TEMP_READ/REAL TEMP: %f \r\n", realTemp);
umairaftab 38:9f4107db1bff 101
umairaftab 38:9f4107db1bff 102 return realTemp;
umairaftab 38:9f4107db1bff 103 }