Skip to content

enable IIR filtering for BME280 #1048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: beta
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion airrohr-firmware/airrohr-firmware.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5408,7 +5408,8 @@ static bool initBMX280(char addr)
BMX280::MODE_FORCED,
BMX280::SAMPLING_X1,
BMX280::SAMPLING_X1,
BMX280::SAMPLING_X1);
BMX280::SAMPLING_X1,
BMX280::IIR_16);
return true;
}
else
Expand Down
2 changes: 2 additions & 0 deletions airrohr-firmware/bmx280_i2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ void BMX280::setSampling(sensor_mode mode,
sensor_sampling tempSampling,
sensor_sampling pressSampling,
sensor_sampling humSampling,
iir_filter iirFilter,
standby_duration duration) {

_measReg.mode = mode;
Expand All @@ -140,6 +141,7 @@ void BMX280::setSampling(sensor_mode mode,

config _configReg;
_configReg.t_sb = duration;
_configReg.filter = iirFilter;

// making sure sensor is in sleep mode before setting configuration
// as it otherwise may be ignored
Expand Down
30 changes: 24 additions & 6 deletions airrohr-firmware/bmx280_i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ class BMX280 {
SAMPLING_X16 = 0b101
};

/**************************************************************************/
/*!
@brief IIR filter
*/
/**************************************************************************/
enum iir_filter {
IIR_NONE = 0b000,
IIR_2 = 0b001,
IIR_4 = 0b010,
IIR_8 = 0b011,
IIR_16 = 0b100
};

/**************************************************************************/
/*!
@brief power modes
Expand Down Expand Up @@ -82,6 +95,7 @@ class BMX280 {
sensor_sampling tempSampling = SAMPLING_X16,
sensor_sampling pressSampling = SAMPLING_X16,
sensor_sampling humSampling = SAMPLING_X16,
iir_filter iirFilter = IIR_NONE,
standby_duration duration = STANDBY_MS_0_5);

void takeForcedMeasurement();
Expand Down Expand Up @@ -146,14 +160,18 @@ class BMX280 {
// 111 = 20 ms
uint8_t t_sb : 3; ///< inactive duration (standby time) in normal mode

// unused - don't set
uint8_t none : 1; ///< unused - don't set
// Controls the time constant of the IIR filter
// 000 = off
// 001 = 2
// 010 = 4
// 011 = 8
// 100, others = 16
uint8_t filter : 3; ///< Controls the time constant of the IIR filter
uint8_t none : 1; ///< unused - don't set
uint8_t spi3w_en : 1; ///< unused - don't set

uint8_t _unused : 3;


/// @return combined config register
uint8_t get() { return (t_sb << 5); }
uint8_t get() { return (t_sb << 5) | (filter << 2); }
};

/**************************************************************************/
Expand Down