Software to create an Environmental Comfort Measurement station using an mbed LPC1768.

Dependencies:   4DGL-uLCD-SE SCP1000 SHTx mbed

Fork of SHT15_Example by Roy van Dam

Files at this revision

API Documentation at this revision

Comitter:
kylepost3
Date:
Sun Mar 23 22:03:11 2014 +0000
Parent:
0:f850dfb07e93
Commit message:
Published Version 1.0 of the Environmental Comfort Measurement project

Changed in this revision

4DGL-uLCD-SE.lib Show annotated file Show diff for this revision Revisions of this file
SCP1000.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/4DGL-uLCD-SE.lib	Sun Mar 23 22:03:11 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/4180_1/code/4DGL-uLCD-SE/#e39a44de229a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SCP1000.lib	Sun Mar 23 22:03:11 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/kadams6/code/SCP1000/#47d6f205890b
--- a/main.cpp	Fri Nov 19 16:51:29 2010 +0000
+++ b/main.cpp	Sun Mar 23 22:03:11 2014 +0000
@@ -1,61 +1,163 @@
-/**
- * Copyright (c) 2010 Roy van Dam <roy@negative-black.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
 #include "mbed.h"
 #include "SHTx/sht15.hpp"
+#include "SCP1000.h"
+#include "uLCD_4DGL.h"
+ 
+uLCD_4DGL uLCD(p28,p27,p29); // serial tx, serial rx, reset pin;
+SCP1000 scp1000(p5,p6,p7,p8);
+SHTx::SHT15 sensor(p9, p10);
+DigitalOut busy(LED1);
+DigitalIn mode(p14);
 
-Serial pc(USBTX, USBRX);
-DigitalOut busy(LED1);
+
+// Declare pins for color sensor
+AnalogIn red_in(p15);
+AnalogIn green_in(p16);
+AnalogIn blue_in(p17);
+ 
+BusOut red_gain(p26, p25);
+BusOut green_gain(p24, p23);  
+BusOut blue_gain(p22, p21);  
+
+
 
-// I used p9 and p10 here  but you
-// can use any other GPIO as well.
-SHTx::SHT15 sensor(p9, p10);
+float comfort_calc(float val, int min, int max){
+    float delta;
+    
+    if (val < min)
+        delta = val-min;
+    else if (val > max)
+        delta = val - max;
+    else
+        delta = 0;
+    
+    delta = delta * 10 / (max-min);
+        
+    return delta;
+}
 
-int
-main() {
+void delta_print(float delta, char* type){
+    if (delta == 0)
+        uLCD.printf("%s: GOOD   \r\n", type);
+    else if (delta < 0)
+        uLCD.printf("%s: LOW   \r\n", type);
+    else
+        uLCD.printf("%s: HIGH   \r\n", type);
+}
+
+int main() {
     // Speed things up a bit.
     sensor.setOTPReload(false);
     sensor.setResolution(true);
     
+    //Declare internal variables
+    float temp, humid, inHg, tempF;
+    int press;
+    
+    int red = 0;
+    int green = 0;
+    int blue = 0;
+       
+    int prev_mode = 0;
+    
+    //declare comfort values 
+    float temp_delta = 0;
+    float humid_delta = 0;
+    float press_delta = 0;
+    float color_delta = 0;
+    
+    float comfort = 0;
+    
+    // Sets the gain of the color sensor
+    red_gain = 3;
+    green_gain = 3;
+    blue_gain = 3;
+    
+    sensor.setScale(false); // Sets the sensor temp. setting to Celsius
+    
+    uLCD.baudrate(600000);
+    uLCD.cls();
     while(1) {
-        busy = true;
+        //busy = true;
         sensor.update();
-        busy = false;
+        
+        temp = (sensor.getTemperature() + scp1000.readTemperature() )/ 2;   // Averages the 2 available temperature readings
+        humid = sensor.getHumidity();
+        press = scp1000.readPressure();
+        busy = false;        
+        
+        tempF = temp * 9.0 / 5.0 + 32.0; // Converts temp from C to F
         
-        // Temperature in celcius
-        sensor.setScale(false);
-        pc.printf("Temperature [ %3.2f C ]\r\n", sensor.getTemperature());
+        // Scale the RGB sensor values to usuable values
+        red = red_in * 1000;
+        green = green_in * 1000;
+        blue = blue_in * 1700;
+        
+        // Convert pressure to mmhg
+        inHg = press / 3376.85;
+        
+
+        temp_delta = comfort_calc(tempF, 65, 75);
+        humid_delta = comfort_calc(humid, 30, 70);
+        press_delta = comfort_calc(inHg, 28, 31);
+        color_delta = comfort_calc(red+green+blue, 30, 450);
+        
+        
         
-        // Temperature in fahrenheit
-        sensor.setScale(true);
-        pc.printf("            [ %3.2f F ]\r\n", sensor.getTemperature());
+        comfort = abs(temp_delta) + abs(humid_delta) + abs(press_delta)+ abs(color_delta);
+        comfort = 100 - comfort;
+
+        // Beggining of printing modes
+        uLCD.locate(0,0);
         
-        // Relative Humidity
-        pc.printf("Humdity     [ %3.2f %% ]\r\n\n", sensor.getHumidity());
+                
+        if (mode==0){     // Sensor detail mode   
+            if (prev_mode != mode)
+                uLCD.cls();
+                
+            // Prints the temperature in celcius            
+            uLCD.printf("Temp: %3.2f F\r\n", tempF);
+            
+            // Prints the relative Humidity
+            uLCD.printf("Humdity: %3.2f %%\r\n", humid);
+            
+            // Prints barometric pressure
+            uLCD.printf("Press: %3.2f inHg\r\n\n", inHg);
+            if (inHg >=28.9)
+                uLCD.printf("High Pressure");
+            else 
+                uLCD.printf("Low Pressure");
+            
+            //Print color sensor values
+            uLCD.printf("\n\n");
+            uLCD.printf("Red: %i\r\n", red);
+            uLCD.printf("Green: %i\r\n", green);
+            uLCD.printf("Blue: %i\r\n", blue);  
+            
+            uLCD.printf("\nt:%3.2f h:%3.2f \np:%3.2f l:%3.2f \r\n", temp_delta, humid_delta, press_delta, color_delta);
+            
+            prev_mode = 0;
+        }
+        else { // Normal mode
+            if (prev_mode != mode)
+                uLCD.cls();
+
         
-        wait(5);
+            delta_print(temp_delta, "Temp");
+            delta_print(humid_delta, "Humid");
+            delta_print(press_delta, "Press");
+            delta_print(color_delta, "Light");
+            
+            if (comfort >90)
+                uLCD.printf("\n\nComfortable   \r\n");
+            else
+                uLCD.printf("\n\nUncomfortable\r\n");
+            
+            uLCD.printf("Rating %3.0f/100\r\n", comfort);  
+            prev_mode = 1;
+        }
+        wait(.5);
     }
 }
+
+