Condensation Monitor Measure the current environment condition at outside and inside and make caution or warnings related to condensation. 結露モニタ 屋内外の環境情報を計測し、結露に関する警告あるいは注意を出力します。

Dependencies:   BME280 HDC1000 VaporCondition mbed AQM0802

Fork of mbed_HDC1000 by yasuyuki onodera

main.cpp

Committer:
takafuminaka
Date:
2015-05-18
Revision:
3:8f886f74f9bb
Parent:
1:1cf4309871b7
Child:
4:3075954b341c

File content as of revision 3:8f886f74f9bb:

//**********************
// Hygrometer and Thermometer for mbed
//
// LPC1768 flash=512KB, ADC=12bits
// LPC11U35 flash=64KB, ADC=10bits
// Nucleo ADC=12bits
//
// (C)Copyright 2015 All rights reserved by Y.Onodera
// http://einstlab.web.fc2.com
//**********************
#include "mbed.h"
#include "HDC1000.h"
#include "BME280.h"
#include "VaporCondition.h"

#define NEED_CONSOLE_OUTPUT 1

#if NEED_CONSOLE_OUTPUT
Serial  pc(USBTX, USBRX);
#define PC(...) { pc.printf(__VA_ARGS__); }
#else
#define PC(...) /* nothing */
#endif /* #if NEED_CONSOLE_OUTPUT */


#if defined(TARGET_LPC1768)
    I2C i2c(p28, p27);
    // BME280 sensor(p28, p27, 0x76 << 1);
#else
    I2C i2c(I2C_SDA0, I2C_SCL0);
    // BME280 sensor(I2C_SDA0, I2C_SCL0, 0x76 << 1);
#endif

BME280 bme280(I2C_SDA0, I2C_SCL0, 0x76 << 1);
HDC1000 hdc1000(i2c);

DigitalOut led1(LED1);
DigitalOut led2(LED2);

int main() {
    float Tdp_o;
    float Tdp_i;
    int cautions;
    int warnings;
    int warn_wid = 20;
    
    VaporCondition Inside;
    VaporCondition Outside;

    // LED Check       
    led1 = 1;
    led2 = 1;
    wait(10);

    led1 = 0;
    led2 = 0;
    
    // i2c.frequency(100000);
      
    while(1) {

        Outside.t = bme280.getTemperature();
        Outside.h = bme280.getHumidity();

        Outside.p = bme280.getPressure();
        Inside.p = bme280.getPressure(); // Usually Pressures are same between inside and outside.

        Inside.t = float(hdc1000.temperature())/0x10000*165-40;
        Inside.h = float(hdc1000.humidity())/0x10000*100;

//        PC("%2.2f degC, %2.2f %%\r\n", t, h);
        
        PC("In: %2.2f degC, %2.2f %% Out: %2.2f degC, %2.2f %%, %04.2f hPa\r\n", Inside.t, Inside.h, Outside.t, Outside.h, Outside.p);
        PC("Humidity Ratio [g/kg] : In %2.2f Out %2.2f \r\n", Inside.Rh(), Outside.Rh());
        Tdp_o = Outside.Tdp();
        Tdp_i = Inside.Tdp();
        PC("Due Point Temperature [degC] : In %2.2f Out %2.2f \r\n", Tdp_o, Tdp_i); 
        
        // print catuions //
        cautions = 0;
        if ( Tdp_o >= Outside.t )
        {
                PC("Condensation at Outside\r\n");
                cautions ++;
        }
        
        if ( Tdp_i >= Inside.t )         
        {
                PC("Condensation at Inside\r\n");
                cautions ++;
        }
        
        if ( Tdp_i >= Outside.t )
        {
                PC("Condensation at Window Inside\r\n");
                cautions ++;
        }
        
        if ( Tdp_o >= Inside.t )
        {
                PC("Condensation at Window Outside\r\n");
                cautions ++;
        }
        
        // print warnings //
        warnings = 0;
        if ( Tdp_o >= Outside.t - warn_wid)
        {
                PC("%2.2f degC to Condensation at Outside\r\n", Outside.t - Tdp_o);
                warnings ++;
        }
        
        if ( Tdp_i >= Inside.t  - warn_wid)         
        {
                PC("%2.2f degC to Condensation at Inside\r\n", Inside.t - Tdp_i);
                warnings ++;
        }
        
        if ( Tdp_i >= Outside.t  - warn_wid)
        {
                PC("%2.2f degC to Condensation at Window Inside\r\n", Outside.t - Tdp_i);
                warnings ++;
        }
        
        if ( Tdp_o >= Inside.t  - warn_wid)
        {
                PC("%2.2f degC to Condensation at Window Outside\r\n", Inside.t - Tdp_o);
                warnings ++;
        }
        
        if ( cautions > 0 ) 
        {
            led2 = 1;
        }
        else 
        {
            led2 = 0;
        }
        
        if ( warnings > 0 )
        {
            led1 = 1;
        }
        else
        {
            led1 = 0;
        }
        
        PC("\r\n");
        wait(3);
    }

}