This is mandatory
Dependencies: BLE_API mbed nRF51822 SHT21_ncleee
Revision 5:fe4888cc60cc, committed 2015-12-21
- Comitter:
- PostaL
- Date:
- Mon Dec 21 00:25:08 2015 +0000
- Parent:
- 4:fddb2d7c7c61
- Commit message:
- Added humidity reading + temp. avg. via SHT21
Changed in this revision
--- a/DHT.lib Sat Nov 14 21:09:57 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://developer.mbed.org/teams/components/code/DHT/#df22ddf10d75
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SHT21_ncleee.lib Mon Dec 21 00:25:08 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/graeme88/code/SHT21_ncleee/#03bbabb7b0b0
--- a/main.cpp Sat Nov 14 21:09:57 2015 +0000 +++ b/main.cpp Mon Dec 21 00:25:08 2015 +0000 @@ -7,10 +7,11 @@ #include "WeatherService.h" #include "BatteryService.h" #include "BMP180.h" -#include "DHT.h" +#include "SHT21_ncleee.h" -float temperature; +float temperature1; +float temperature2; float pressure; float humidity; @@ -21,7 +22,8 @@ DigitalOut instrumentsPower(p30); BMP180 bmp180; -DHT dht(p5,DHT11); +SHT21 sht21(&i2c); + const static char DEVICE_NAME[] = "Weather Station"; @@ -30,7 +32,7 @@ GattService::UUID_BATTERY_SERVICE }; -static volatile bool triggerSensorPolling = false; +static volatile bool triggerSensorPolling = false; void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) { @@ -63,21 +65,13 @@ return; } - temperature = (float)bmp180.BMP180GetTemperature()/10.0f; + temperature1 = (float)bmp180.BMP180GetTemperature()/10.0f; pressure = (float)bmp180.BMP180GetPressure(); } -void updateFromDHT() { - wait(3); - int err = dht.readData(); - if (err == 0) { - humidity = dht.ReadHumidity(); - printf("Dew point is %4.2f \n",dht.CalcdewPoint(dht.ReadTemperature(CELCIUS), humidity)); - printf("Dew point (fast) is %4.2f \n",dht.CalcdewPointFast(dht.ReadTemperature(CELCIUS), humidity)); - } - else { - printf("Error reading DHT: %d \n", err); - } +void updateFromSHT21() { + temperature2 = sht21.readTemp(); + humidity = sht21.readHumidity(); } int main(void) @@ -115,14 +109,19 @@ instrumentsPower = 1; wait(1); updateFromBMP180(); - updateFromDHT(); + updateFromSHT21(); instrumentsPower = 0; - printf("Temp: %.1f C \n", temperature); + float temperature = (temperature1 + temperature2) / 2; + + printf("Temp1: %.1f ºC \n", temperature1); + printf("Temp2: %.1f ºC \n", temperature2); + printf("Temp Avg.: %.1f ºC \n", temperature); printf("Pressure: %.3f Pa \n", pressure); - printf("Humidity: %.1f % \n", humidity); + printf("Humidity: %.1f%% \n", humidity); printf("---\n"); + weatherService.updateTemperature(temperature); weatherService.updatePressure(pressure); weatherService.updateHumidity(humidity);