From 0e7486552dec3868ca2093917d65039bf43f8f72 Mon Sep 17 00:00:00 2001 From: liquidraver <504870+liquidraver@users.noreply.github.com> Date: Thu, 16 Oct 2025 10:17:23 +0200 Subject: [PATCH 1/2] Add simple BME680 support to RAK with adafruit library --- platformio.ini | 2 ++ .../sensors/EnvironmentSensorManager.cpp | 33 ++++++++++++++++++- .../sensors/EnvironmentSensorManager.h | 1 + 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 4fe17af93..7af337475 100644 --- a/platformio.ini +++ b/platformio.ini @@ -124,6 +124,7 @@ build_flags = -D ENV_INCLUDE_INA260=1 -D ENV_INCLUDE_MLX90614=1 -D ENV_INCLUDE_VL53L0X=1 + -D ENV_INCLUDE_BME680=1 lib_deps = adafruit/Adafruit INA3221 Library @ ^1.0.1 adafruit/Adafruit INA219 @ ^1.2.3 @@ -138,3 +139,4 @@ lib_deps = adafruit/Adafruit MLX90614 Library @ ^2.1.5 adafruit/Adafruit_VL53L0X @ ^1.2.4 stevemarple/MicroNMEA @ ^2.0.6 + adafruit/Adafruit BME680 Library @ ^2.0.4 diff --git a/src/helpers/sensors/EnvironmentSensorManager.cpp b/src/helpers/sensors/EnvironmentSensorManager.cpp index 295458941..e244ef209 100644 --- a/src/helpers/sensors/EnvironmentSensorManager.cpp +++ b/src/helpers/sensors/EnvironmentSensorManager.cpp @@ -6,6 +6,14 @@ #define TELEM_WIRE &Wire // Use default I2C bus for Environment Sensors #endif +#ifdef ENV_INCLUDE_BME680 +#ifndef TELEM_BME680_ADDRESS +#define TELEM_BME680_ADDRESS 0x76 // BME680 environmental sensor I2C address +#endif +#include +static Adafruit_BME680 BME680; +#endif + #if ENV_INCLUDE_AHTX0 #define TELEM_AHTX_ADDRESS 0x38 // AHT10, AHT20 temperature and humidity sensor I2C address #include @@ -286,6 +294,16 @@ bool EnvironmentSensorManager::begin() { } #endif + #if ENV_INCLUDE_BME680 + if (BME680.begin(TELEM_BME680_ADDRESS, TELEM_WIRE)) { + MESH_DEBUG_PRINTLN("Found BME680 at address: %02X", TELEM_BME680_ADDRESS); + BME680_initialized = true; + } else { + BME680_initialized = false; + MESH_DEBUG_PRINTLN("BME680 was not found at I2C address %02X", TELEM_BME680_ADDRESS); + } + #endif + return true; } @@ -415,6 +433,18 @@ bool EnvironmentSensorManager::querySensors(uint8_t requester_permissions, Cayen } #endif + #if ENV_INCLUDE_BME680 + if (BME680_initialized) { + if (BME680.performReading()) { + telemetry.addTemperature(TELEM_CHANNEL_SELF, BME680.temperature); + telemetry.addRelativeHumidity(TELEM_CHANNEL_SELF, BME680.humidity); + telemetry.addBarometricPressure(TELEM_CHANNEL_SELF, BME680.pressure / 100); + telemetry.addAnalogInput(next_available_channel, BME680.gas_resistance); + next_available_channel++; + } + } + #endif + } return true; @@ -623,6 +653,7 @@ void EnvironmentSensorManager::stop_gps() { void EnvironmentSensorManager::loop() { static long next_gps_update = 0; + #if ENV_INCLUDE_GPS _location->loop(); if (millis() > next_gps_update) { @@ -647,5 +678,5 @@ void EnvironmentSensorManager::loop() { } next_gps_update = millis() + 1000; } + #endif } -#endif diff --git a/src/helpers/sensors/EnvironmentSensorManager.h b/src/helpers/sensors/EnvironmentSensorManager.h index 09c6cae41..133d26504 100644 --- a/src/helpers/sensors/EnvironmentSensorManager.h +++ b/src/helpers/sensors/EnvironmentSensorManager.h @@ -20,6 +20,7 @@ class EnvironmentSensorManager : public SensorManager { bool MLX90614_initialized = false; bool VL53L0X_initialized = false; bool SHT4X_initialized = false; + bool BME680_initialized = false; bool gps_detected = false; bool gps_active = false; From 3c48f016019d611d763493e0de246397d2a7ea98 Mon Sep 17 00:00:00 2001 From: liquidraver <504870+liquidraver@users.noreply.github.com> Date: Thu, 16 Oct 2025 11:29:22 +0200 Subject: [PATCH 2/2] BME680 library doesn't have altitude calculation, we can add it here to match other sensors' --- src/helpers/sensors/EnvironmentSensorManager.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/helpers/sensors/EnvironmentSensorManager.cpp b/src/helpers/sensors/EnvironmentSensorManager.cpp index e244ef209..bb70c0b5c 100644 --- a/src/helpers/sensors/EnvironmentSensorManager.cpp +++ b/src/helpers/sensors/EnvironmentSensorManager.cpp @@ -8,8 +8,9 @@ #ifdef ENV_INCLUDE_BME680 #ifndef TELEM_BME680_ADDRESS -#define TELEM_BME680_ADDRESS 0x76 // BME680 environmental sensor I2C address +#define TELEM_BME680_ADDRESS 0x76 #endif +#define TELEM_BME680_SEALEVELPRESSURE_HPA (1013.25) #include static Adafruit_BME680 BME680; #endif @@ -439,6 +440,7 @@ bool EnvironmentSensorManager::querySensors(uint8_t requester_permissions, Cayen telemetry.addTemperature(TELEM_CHANNEL_SELF, BME680.temperature); telemetry.addRelativeHumidity(TELEM_CHANNEL_SELF, BME680.humidity); telemetry.addBarometricPressure(TELEM_CHANNEL_SELF, BME680.pressure / 100); + telemetry.addAltitude(TELEM_CHANNEL_SELF, 44330.0 * (1.0 - pow((BME680.pressure / 100) / TELEM_BME680_SEALEVELPRESSURE_HPA, 0.1903))); telemetry.addAnalogInput(next_available_channel, BME680.gas_resistance); next_available_channel++; } @@ -680,3 +682,4 @@ void EnvironmentSensorManager::loop() { } #endif } +#endif