Просмотр исходного кода

Merge pull request #998 from tahnok/bmp085-sensor

Add support for bmp085/bmp180 temperature/pressure sensor
ripplebiz 9 месяцев назад
Родитель
Сommit
920ac51c8c

+ 2 - 0
platformio.ini

@@ -129,6 +129,7 @@ build_flags =
   -D ENV_INCLUDE_MLX90614=1
   -D ENV_INCLUDE_VL53L0X=1
   -D ENV_INCLUDE_BME680=1
+  -D ENV_INCLUDE_BMP085=1
 lib_deps =
   adafruit/Adafruit INA3221 Library @ ^1.0.1
   adafruit/Adafruit INA219 @ ^1.2.3
@@ -144,3 +145,4 @@ lib_deps =
   adafruit/Adafruit_VL53L0X @ ^1.2.4
   stevemarple/MicroNMEA @ ^2.0.6
   adafruit/Adafruit BME680 Library @ ^2.0.4
+  adafruit/Adafruit BMP085 Library @ ^1.2.4

+ 26 - 0
src/helpers/sensors/EnvironmentSensorManager.cpp

@@ -15,6 +15,12 @@
 static Adafruit_BME680 BME680;
 #endif
 
+#ifdef ENV_INCLUDE_BMP085
+#define TELEM_BMP085_SEALEVELPRESSURE_HPA (1013.25)
+#include <Adafruit_BMP085.h>
+static Adafruit_BMP085 BMP085;
+#endif
+
 #if ENV_INCLUDE_AHTX0
 #define TELEM_AHTX_ADDRESS      0x38      // AHT10, AHT20 temperature and humidity sensor I2C address
 #include <Adafruit_AHTX0.h>
@@ -305,6 +311,18 @@ bool EnvironmentSensorManager::begin() {
   }
   #endif
 
+  #if ENV_INCLUDE_BMP085
+  // First argument is  MODE (aka oversampling)
+  // choose ULTRALOWPOWER
+  if (BMP085.begin(0, TELEM_WIRE)) {
+    MESH_DEBUG_PRINTLN("Found sensor BMP085");
+    BMP085_initialized = true;
+  } else {
+    BMP085_initialized = false;
+    MESH_DEBUG_PRINTLN("BMP085 was not found at I2C address %02X", 0x77);
+  }
+  #endif
+
   return true;
 }
 
@@ -447,6 +465,14 @@ bool EnvironmentSensorManager::querySensors(uint8_t requester_permissions, Cayen
     }
     #endif
 
+    #if ENV_INCLUDE_BMP085
+    if (BMP085_initialized) {
+        telemetry.addTemperature(TELEM_CHANNEL_SELF, BMP085.readTemperature());
+        telemetry.addBarometricPressure(TELEM_CHANNEL_SELF, BMP085.readPressure() / 100);
+        telemetry.addAltitude(TELEM_CHANNEL_SELF, BMP085.readAltitude(TELEM_BMP085_SEALEVELPRESSURE_HPA * 100));
+    }
+    #endif
+
   }
 
   return true;

+ 1 - 0
src/helpers/sensors/EnvironmentSensorManager.h

@@ -21,6 +21,7 @@ protected:
   bool VL53L0X_initialized = false;
   bool SHT4X_initialized = false;
   bool BME680_initialized = false;
+  bool BMP085_initialized = false;
 
   bool gps_detected = false;
   bool gps_active = false;