52 lines
1.7 KiB
Arduino
52 lines
1.7 KiB
Arduino
|
#include <Adafruit_BMP280.h> // Install from library manager - sensor board info: https://www.bastelgarage.ch/bmp280-temperatur-luftdruck-sensor
|
||
|
|
||
|
Adafruit_BMP280 _sensor_bmp280;
|
||
|
Adafruit_Sensor *_sensor_bmp280_temp = _sensor_bmp280.getTemperatureSensor();
|
||
|
Adafruit_Sensor *_sensor_bmp280_pressure = _sensor_bmp280.getPressureSensor();
|
||
|
|
||
|
bool sensor_bmp280_begin(uint8_t addr)
|
||
|
{
|
||
|
bool status = _sensor_bmp280.begin(addr);
|
||
|
|
||
|
if (status)
|
||
|
{
|
||
|
debug("BMP280 Connected");
|
||
|
|
||
|
_sensor_bmp280.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
|
||
|
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
|
||
|
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
|
||
|
Adafruit_BMP280::FILTER_X16, /* Filtering. */
|
||
|
Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
|
||
|
|
||
|
} else {
|
||
|
debug("Could not find a valid BMP280 sensor, check wiring or try a different address!");
|
||
|
debug("SensorID was: " + String(_sensor_bmp280.sensorID()));
|
||
|
debug(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
|
||
|
debug(" ID of 0x56-0x58 represents a BMP 280,\n");
|
||
|
debug(" ID of 0x60 represents a BME 280.\n");
|
||
|
debug(" ID of 0x61 represents a BME 680.\n");
|
||
|
|
||
|
}
|
||
|
|
||
|
return status;
|
||
|
}
|
||
|
|
||
|
float bmp280_temperature()
|
||
|
{
|
||
|
sensors_event_t temp_event, pressure_event;
|
||
|
_sensor_bmp280_temp->getEvent(&temp_event);
|
||
|
return temp_event.temperature * TEMP_FACTOR;
|
||
|
}
|
||
|
|
||
|
float bmp280_pressure()
|
||
|
{
|
||
|
sensors_event_t pressure_event;
|
||
|
_sensor_bmp280_pressure->getEvent(&pressure_event);
|
||
|
return pressure_event.pressure;
|
||
|
}
|
||
|
|
||
|
float bmp280_humidity()
|
||
|
{
|
||
|
return 0 * HUMIDITY_FACTOR;
|
||
|
}
|