Barometer program : Data Logger function includes Barometer & temperature (BMP180), Humidity & temp. (RHT03), Sunshine (Cds), RTC(M41T62) data. : Logging data saves into EEPROM (AT24C1024) using ring buffer function.
Dependencies: AT24C1024 RHT03 TextLCD BMP180 M41T62
Fork of mbed_blinky by
Please see https://mbed.org/users/kenjiArai/notebook/mbed-lpc1114fn28-barometer-with-data-logging/#
Diff: main.cpp
- Revision:
- 10:398f62bb41f7
- Parent:
- 9:ce80da60884a
- Child:
- 11:bccfd75e84a0
--- a/main.cpp Fri Jun 13 10:41:42 2014 +0000 +++ b/main.cpp Sat Jun 14 01:37:54 2014 +0000 @@ -6,7 +6,7 @@ * http://www.page.sannet.ne.jp/kenjia/index.html * http://mbed.org/users/kenjiArai/ * Created: June 13th, 2014 - * Revised: June 13th, 2014 + * Revised: June 14th, 2014 * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE @@ -15,6 +15,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "mbed.h" +#include "RHT03.h" //Include neede to use the RHT03 lib #define DEBUG_L1 1 // 1=Debug, 0=Normal #define DEBUG_L2 1 // 1=Debug, 0=Normal @@ -33,7 +34,8 @@ AnalogIn cds(dp11); // Input / CDS data AnalogIn vref(dp9); // Input / Bandgap 2.5V AnalogIn vol(dp10); // Input / contrast volume -Serial pc(dp16,dp15); +RHT03 humtemp(dp26); // RHT03 interface +Serial pc(dp16,dp15); typedef enum {CDS = 0, VREF, VOL} ADC_Select; @@ -52,6 +54,9 @@ extern uint32_t baro_pres_data; // Barometer /normalized extern int16_t baro_temp_data; +// Humidity Sensor +float humidity_temp, humidity; + // Cds GL5528 (Dark Resistance 1 Mohm type) SENBA OPTICAL & ELECTRONIC CO.,LTD. // Table value referrence: http://homepage3.nifty.com/skomo/f35/hp35_20.htm const float lux_cds[CDS_TBL_SIZE][2] = @@ -260,24 +265,39 @@ } void adc_all_read( void){ - av_cds = av_cds *0.5 + cds.read() * 0.5; - av_vref = av_vref *0.9 + vref.read() * 0.1; - av_vol = av_vol *0.2 + vol.read() * 0.8; + if ( av_cds == 0 ){ + av_cds = cds.read(); + } else { + av_cds = av_cds *0.5 + cds.read() * 0.5; + } + if ( av_vref == 0 ){ + av_vref = vref.read(); + } else { + av_vref = av_vref *0.9 + vref.read() * 0.1; + } + if ( av_vol == 0 ){ + av_vol = vol.read(); + } else { + av_vol = av_vol *0.2 + vol.read() * 0.8; + } } -void adc_init( void){ - analog_pwr = 1; - vref_pwr = 1; - wait(0.2); - av_cds = cds.read(); - av_vref = vref.read(); - av_vol = vol.read(); - wait(0.1); - adc_all_read(); - wait(0.1); - adc_all_read(); - analog_pwr = 0; - vref_pwr = 0; +void hum_RHT03_read( void){ + while (true){ + if ( humtemp.readData() == RHT_ERROR_NONE ){ //Request data from the RHT03 + break; + } + } + if ( humidity_temp == 0 ){ + humidity_temp = humtemp.getTemperatureC(); + } else { + humidity_temp = humidity_temp * 0.9 + humtemp.getTemperatureC() * 0.1; + } + if ( humidity == 0 ){ + humidity = humtemp.getHumidity(); + } else { + humidity = humidity * 0.9 + humtemp.getHumidity() * 0.1; + } } int main() { @@ -285,8 +305,6 @@ pc.baud(9600); pc.printf( "\r\nmbed LPC1114FN28 test program by JH1PJL created on "__DATE__"\r\n" ); - // Initialize ADC - adc_init(); // Initialize LCD lcd_init(); contrast = 25; @@ -301,8 +319,16 @@ // Read BMP180 data / only once baro_rd_id(); baro_rd_coefficient(); + // Show initial screen wait(5.0); + // Initialize data + av_cds = 0; + av_vref = 0; + av_vol = 0; + humidity_temp = 0; + humidity = 0; while(1) { + // ---------- Cds Sensor, Vref, Volume --------------------------------------------------- // Power on / Analog sensor analog_pwr = 1; vref_pwr = 1; @@ -331,7 +357,8 @@ lcd_setCursor(0, 1); // 2nd line top sprintf( buf,"V: %1.3f ", cal_vcc ); lcd_printStr(buf); - wait(4.0); + wait(2.0); + // ---------- Barometer Sensor / BMP180 -------------------------------------------------- baro_st_conv_temp(); // start temprerature measurment wait(0.25); // wait for convertion baro_rd_temp(); // read it @@ -353,11 +380,23 @@ baro_pres_data / 100, ( baro_pres_data % 100 ) /10, baro_temp_data / 10, baro_temp_data% 10 ); myled1 = 0; - wait(3.0); + wait(4.0); + // ---------- Humidity Sensor / RHT03 ---------------------------------------------------- + hum_RHT03_read(); // Read Humidity data then avaraging + lcd_setCursor(0, 0); // 1st line top + dt = (uint16_t)(lux * 10); + //sprintf( buf,"l: %4.1f ", lux ); + sprintf( buf,"H: %2.1f ", humidity ); + lcd_printStr(buf); + lcd_setCursor(0, 1); // 2nd line top + sprintf( buf,"T: %\+-0.1f", humidity_temp ); + lcd_printStr(buf); + myled1 = 1; + pc.printf( "Humid: %0.1f%cRH, Temp:%\+-0.1fdegC\r\n", humidity, '%', humidity_temp ); + myled1 = 0; + wait(2.0); #if DEBUG_L2 debug_port_check(); -#endif // DEBUG_L2 - wait(1.0); +#endif // DEBUG_L2 } } -