BMP180 and BLE

Dependencies:   BLE_API mbed nRF51822

Fork of WeatherStation by Weather man

Revision:
5:fe4888cc60cc
Parent:
4:fddb2d7c7c61
Child:
6:25ed8e2df02e
--- 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);