BMP280 MS5611 added

This commit is contained in:
Myk
2024-04-13 01:03:37 +03:00
parent 54285dd721
commit 258fa0097d
9 changed files with 294 additions and 29 deletions

View File

@@ -0,0 +1,30 @@
// BMP280Sensor.cpp
#include "BMP280Sensor.h"
BMP280Sensor::BMP280Sensor(uint8_t address) : _address(address) {
// Constructor sets the address
}
void BMP280Sensor::init() {
// Enable BMP280
bool ok = bmp280.begin(_address);
/* weather monitoring settings from driver lib */
bmp280.setSampling(Adafruit_BME280::MODE_FORCED,
Adafruit_BME280::SAMPLING_X1, // temperature
Adafruit_BME280::SAMPLING_X1, // pressure
Adafruit_BME280::SAMPLING_X1, // humidity
Adafruit_BME280::FILTER_OFF );
}
void BMP280Sensor::read_values(float* temperature, float* humidity, float* pressure, float* altitude) {
// Only needed in forced mode! In normal mode, you can remove the next line.
bmp280.takeForcedMeasurement(); // has no effect in normal mode
if (humidity) *humidity = bmp280.readHumidity();
if (temperature) *temperature = bmp280.readTemperature();
if (pressure) *pressure = bmp280.readPressure() / 100.0F;
if (altitude) *altitude = bmp280.readAltitude(SEALEVELPRESSURE_HPA);
}

View File

@@ -0,0 +1,25 @@
// MS5611Sensor.cpp
#include "MS5611Sensor.h"
// Initialize MS5611 sensor
// Ultra high resolution: MS5611_ULTRA_HIGH_RES
// (default) High resolution: MS5611_HIGH_RES
// Standard: MS5611_STANDARD
// Low power: MS5611_LOW_POWER
// Ultra low power: MS5611_ULTRA_LOW_POWER
MS5611Sensor::MS5611Sensor() {
// Constructor - No need to do anything here
}
void MS5611Sensor::init() {
ms5611.begin(MS5611_ULTRA_HIGH_RES);
}
void MS5611Sensor::read_values(double* temperature, double* preasure, double* altitude) {
if (temperature) *temperature = ms5611.readTemperature(true);
if (preasure) *preasure = ms5611.readPressure(true);
if (altitude) *altitude = ms5611.getAltitude(*preasure); // second arg double seaLevelPressure = 101325
}