Telemetry: Create BME280 sensor that can bu used across variants. Add to promicro.
This commit is contained in:
55
src/helpers/sensors/BME280Sensor.h
Normal file
55
src/helpers/sensors/BME280Sensor.h
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <Mesh.h>
|
||||||
|
#include <Adafruit_BME280.h>
|
||||||
|
|
||||||
|
#define TELEM_BME280_ADDRESS 0x76 // BME280 environmental sensor I2C address
|
||||||
|
#define SEALEVELPRESSURE_HPA (1013.25) // Athmospheric pressure at sea level
|
||||||
|
|
||||||
|
static Adafruit_BME280 BME280;
|
||||||
|
|
||||||
|
class BME280Sensor {
|
||||||
|
bool initialized = false;
|
||||||
|
public:
|
||||||
|
void begin() {
|
||||||
|
if (BME280.begin(TELEM_BME280_ADDRESS, &Wire)) {
|
||||||
|
MESH_DEBUG_PRINTLN("Found BME280 at address: %02X", TELEM_BME280_ADDRESS);
|
||||||
|
MESH_DEBUG_PRINTLN("BME sensor ID: %02X", BME280.sensorID);
|
||||||
|
initialized = true;
|
||||||
|
} else {
|
||||||
|
initialized = false;
|
||||||
|
MESH_DEBUG_PRINTLN("BME280 was not found at I2C address %02X", TELEM_BME280_ADDRESS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isInitialized() const { return initialized; };
|
||||||
|
|
||||||
|
float getRelativeHumidity() const {
|
||||||
|
if (initialized) {
|
||||||
|
return BME280.readHumidity();;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float getTemperature() const {
|
||||||
|
if (initialized) {
|
||||||
|
return BME280.readTemperature();;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float getBarometricPressure() const {
|
||||||
|
if (initialized) {
|
||||||
|
return BME280.readPressure();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float getAltitude() const {
|
||||||
|
if (initialized) {
|
||||||
|
return BME280.readAltitude(SEALEVELPRESSURE_HPA);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setTemperatureCompensation(float delta) {
|
||||||
|
if (initialized) {
|
||||||
|
BME280.setTemperatureCompensation(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -4,6 +4,7 @@ bool EnvironmentSensorManager::begin() {
|
|||||||
INA3221_sensor.begin();
|
INA3221_sensor.begin();
|
||||||
INA219_sensor.begin();
|
INA219_sensor.begin();
|
||||||
AHTX0_sensor.begin();
|
AHTX0_sensor.begin();
|
||||||
|
BME280_sensor.begin();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -32,6 +33,12 @@ bool EnvironmentSensorManager::querySensors(uint8_t requester_permissions, Cayen
|
|||||||
telemetry.addTemperature(TELEM_CHANNEL_SELF, AHTX0_sensor.getTemperature());
|
telemetry.addTemperature(TELEM_CHANNEL_SELF, AHTX0_sensor.getTemperature());
|
||||||
telemetry.addRelativeHumidity(TELEM_CHANNEL_SELF, AHTX0_sensor.getRelativeHumidity());
|
telemetry.addRelativeHumidity(TELEM_CHANNEL_SELF, AHTX0_sensor.getRelativeHumidity());
|
||||||
}
|
}
|
||||||
|
if (BME280_sensor.isInitialized()) {
|
||||||
|
telemetry.addTemperature(TELEM_CHANNEL_SELF, BME280_sensor.getTemperature());
|
||||||
|
telemetry.addRelativeHumidity(TELEM_CHANNEL_SELF, BME280_sensor.getRelativeHumidity());
|
||||||
|
telemetry.addBarometricPressure(TELEM_CHANNEL_SELF, BME280_sensor.getBarometricPressure());
|
||||||
|
telemetry.addAltitude(TELEM_CHANNEL_SELF, BME280_sensor.getAltitude());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "INA3221Sensor.h"
|
#include "INA3221Sensor.h"
|
||||||
#include "INA219Sensor.h"
|
#include "INA219Sensor.h"
|
||||||
#include "AHTX0Sensor.h"
|
#include "AHTX0Sensor.h"
|
||||||
|
#include "BME280Sensor.h"
|
||||||
|
|
||||||
#define NUM_SENSOR_SETTINGS 3
|
#define NUM_SENSOR_SETTINGS 3
|
||||||
#define TELEM_INA3221_SETTING_CH1 "INA3221-1"
|
#define TELEM_INA3221_SETTING_CH1 "INA3221-1"
|
||||||
@@ -19,6 +20,7 @@ protected:
|
|||||||
INA3221Sensor INA3221_sensor;
|
INA3221Sensor INA3221_sensor;
|
||||||
AHTX0Sensor AHTX0_sensor;
|
AHTX0Sensor AHTX0_sensor;
|
||||||
INA219Sensor INA219_sensor;
|
INA219Sensor INA219_sensor;
|
||||||
|
BME280Sensor BME280_sensor;
|
||||||
public:
|
public:
|
||||||
EnvironmentSensorManager(){};
|
EnvironmentSensorManager(){};
|
||||||
bool begin() override;
|
bool begin() override;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ lib_deps= ${nrf52840_base.lib_deps}
|
|||||||
robtillaart/INA3221 @ ^0.4.1
|
robtillaart/INA3221 @ ^0.4.1
|
||||||
robtillaart/INA219 @ ^0.4.1
|
robtillaart/INA219 @ ^0.4.1
|
||||||
adafruit/Adafruit AHTX0@^2.0.5
|
adafruit/Adafruit AHTX0@^2.0.5
|
||||||
|
adafruit/Adafruit BME280 Library@^2.3.0
|
||||||
|
|
||||||
[env:Faketec_Repeater]
|
[env:Faketec_Repeater]
|
||||||
extends = Faketec
|
extends = Faketec
|
||||||
|
|||||||
Reference in New Issue
Block a user