BMP280 oversampling and precision

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ejalaa12
 
Posts: 1
Joined: Thu Nov 19, 2015 5:40 am

BMP280 oversampling and precision

Post by ejalaa12 »

Hello,

I’ve recently bought two BMP280 pressure sensor.
I’m trying to mesure very accurately the pressure in two different points and see the difference.
However I noticed two things:
  • the two sensor give different value of the pressure even if it put them at the same place (the difference between themvaries from 10 to 30 Pa)
  • The value given by one sensor is not the same after resetting my board (Arduino).
    eg: It can give around 101,000 Pa before resetting and then around 101,300 Pa after resetting.
Why is this happening ?

I’ve looked into the data sheet of the BMP280, and I found out that I can be more accurate by changing the oversampling of the sensor.
However, I can’t find how to do it with the Adafruit given Library.

Could you help me ?

Thank you very much.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: BMP280 oversampling and precision

Post by adafruit_support_rick »

You'll have to modify the library. It's pretty simple. Look at the end of the begin function in Adafruit_BMP280.cpp:

Code: Select all

  readCoefficients();
  write8(BMP280_REGISTER_CONTROL, 0x3F);
  return true;
Change the 0x3f to whatever settings you want for the Control Register (register 0xF5), and add another line for the settings to the Config Register (register 0xF4).

Code: Select all

  readCoefficients();
  write8(BMP280_REGISTER_CONTROL, <0xnn); //replace <0xnn> with your settings for the control register
  write8(BMP280_REGISTER_CONFIG, <0xnn>); //replace <0xnn> with your settings for the config register
  return true;

User avatar
spitfire007
 
Posts: 35
Joined: Wed Jun 22, 2016 4:05 am

Re: BMP280 oversampling and precision

Post by spitfire007 »

Here is my best guess at how to implement high res sampling.
This is my first attempt at adjusting sensor register values so it might be wrong.
Use at own risk.

The serial print won't work for some reason in .ccp so I don't quite know how to confirm it is in the correct mode.
If someone could tell me why serial print statements don't work in this library even though wire.h is included I would be grateful.

Anyway.

This is to set into high res mode for indoor navigation use as per the data sheet.
2x temperature oversampling. (data sheet makes a note that this is the preferred option with 16x oversampling on the pressure)
16x Pressure oversampling.

From the datasheet.
Config Register 0xF5
Bit's 7,6,5 set to 0 0 0 Controls inactive duration tstandby in normal mode, set to 0.5ms
Bit's 4.3.2 set to 1 1 1 Controls the time constant of the IIR filter, set to x16 oversampling.
Bit 1 left alone as it is a reserved bit.
Bit 0 set to 0 (4 wire SPI.. not 3)

So the config register 0xF5 needs to be set to 0001 11X0 (X = reserved bit). = 1C. the bitmask will leave X as it is.

Control register 0xF4
Bit's 7,6,5 set to 0 1 0 Controls oversampling of temperature data, set to times 2 in this case
Bit's 4.3.2 set to 1 1 1 Controls oversampling of pressure data, set to times 16 in this case
Bit 1, 0 set to 1 1 Controls the power mode of the device, set to Normal mode.

So 0101 1111 for x2 temp oversample and x16 pressure oversample = 5F

because we can't touch bit 1 (X) in the 0xF5 register we need a mask.
The mask is a value with all bits to be changed (and only them) set to 1
newvalue is a value that contains the new state of those bits - all other bits are essentially ignored.

Adafruit_BMP280.cpp

Code: Select all

 readCoefficients();
  //write8(BMP280_REGISTER_CONTROL, 0x3F);
  _mask = 0xFD;			//FD = 1111 1101
  _newvalue = 0x1C;		//1C = 0001 1100
  
  _SetRegister = (read8(BMP280_REGISTER_CONFIG) & ~_mask) | (_newvalue & _mask);
     
  write8(BMP280_REGISTER_CONFIG, _SetRegister);
  write8(BMP280_REGISTER_CONTROL, 0x5F); 
  
  Serial.println(F(_SetRegister));
  Serial.println(F("SetRegister"));
Added 3 lines to Adafruit_BMP280.h

Code: Select all

class Adafruit_BMP280
{
  public:
    Adafruit_BMP280(void);
    Adafruit_BMP280(int8_t cspin);
    Adafruit_BMP280(int8_t cspin, int8_t mosipin, int8_t misopin, int8_t sckpin);

    bool  begin(uint8_t addr = BMP280_ADDRESS);
    float readTemperature(void);
    float readPressure(void);
    float readAltitude(float seaLevelhPa = 1013.25);

  private:

    void readCoefficients(void);
    uint8_t spixfer(uint8_t x);

    void      write8(byte reg, byte value);
    uint8_t   read8(byte reg);
    uint16_t  read16(byte reg);
    uint32_t  read24(byte reg);
    int16_t   readS16(byte reg);
    uint16_t  read16_LE(byte reg); // little endian
    int16_t   readS16_LE(byte reg); // little endian

    uint8_t   _i2caddr;
    int32_t   _sensorID;
    int32_t t_fine;

    int8_t _cs, _mosi, _miso, _sck;

    bmp280_calib_data _bmp280_calib;
	
	byte _mask;
	byte _newvalue;
	byte _SetRegister;
};
I have not done much testing yet. So please be careful about my coding !

User avatar
liuk
 
Posts: 12
Joined: Mon Jan 23, 2017 1:34 pm

Re: BMP280 oversampling and precision

Post by liuk »

Hi, I'm having the very same issue. Tried both suggestions with no good results. Any update on this? Thanks
EDIT: I'm adding more info on how Adafruit Admin suggestion does not work: changing the code as he suggests:

Code: Select all

readCoefficients();
  write8(BMP280_REGISTER_CONTROL, 0xF5); //replace <0xnn> with your settings for the control register
  write8(BMP280_REGISTER_CONFIG, 0xF4); //replace <0xnn> with your settings for the config register
  return true;
not only does not add any precision to the sampling, but it actually freezes all the values.
Here's a screenshot from my monitor: while moving the device values do not change in any way: they are like frozen
Attachments
Screen Shot 2017-02-05 at 13.54.23.png
Screen Shot 2017-02-05 at 13.54.23.png (314.06 KiB) Viewed 4303 times

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: BMP280 oversampling and precision

Post by adafruit_support_rick »

0xF5 and 0xF4 are the register addresses, not the suggested settings. You want to substitute the register settings into those instructions.
See the datasheet for the register definitions
http://www.adafruit.com/datasheets/BST- ... 001-11.pdf

@spitfire007 discusses the register settings in his post above.

User avatar
liuk
 
Posts: 12
Joined: Mon Jan 23, 2017 1:34 pm

Re: BMP280 oversampling and precision

Post by liuk »

Thank you so much Rick, and sorry if i got it wrong.

Since I'm totally new to sensor configuration (and a little lost, honestly), I thought those lines were the ones doing the oversampling, but looks like there are some extra steps I have no idea of (even after looking at the provided link).

Can you please help me set the sensor to ultra high resolution / minimum noise?
That would be much appreciated (and i can learn something for the future)

Thanks a lot!

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: BMP280 oversampling and precision

Post by adafruit_support_rick »

Try this. At the end of begin() in Adafruit_BMP260.cpp, paste these lines

Code: Select all

  readCoefficients();
  write8(BMP280_REGISTER_CONTROL, 0xEB);
  uint8_t config = read8(BMP280_REGISTER_CONFIG) & 0x03;
  write8(BMP280_REGISTER_CONFIG, 0x1C | config);
  return true;
in place of these lines

Code: Select all

  readCoefficients();
  write8(BMP280_REGISTER_CONTROL, 0x3F);
  return true;

User avatar
liuk
 
Posts: 12
Joined: Mon Jan 23, 2017 1:34 pm

Re: BMP280 oversampling and precision

Post by liuk »

Thanks a lot, it worked! ;-)

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: BMP280 oversampling and precision

Post by adafruit_support_rick »

Really? Wow - I didn't test that at all. I guess sometimes you just get it right the first time ;-)

User avatar
ashrantaryal
 
Posts: 1
Joined: Thu Mar 17, 2016 2:00 pm

Re: BMP280 oversampling and precision

Post by ashrantaryal »

I am new to sensor configuration and would love your help. I want to detect small changes in pressure eg. caused by blowing into the sensor. When I use the default settings, it detects the changes initially (5-10 seconds after start) but not after 2-3 minutes. I am guessing this is due to the IIR filter settings, so I would like to change it. From the datasheet, the closest use case seems to be Elevator/floor change detection so I would like to set the sensor to Elevator/floor change detection. I have a snapshot from the datasheet below:
Capture.JPG
Capture.JPG (85.02 KiB) Viewed 3923 times
For register 0xF4, bits 7,6,5 refer to BANNED_t and need to be set to 001. bits 4,3,2 refer to BANNED_p and need to be set to 011 bits 1,0 refer to the power mode and need to be set to 01 or 10 for forced mode.

The datasheet also mentions this for forced mode operation: "When the measurement is finished, the sensor returns to sleep mode and the measurement results can be obtained from the data registers. For a next measurement, forced mode needs to be selected again." How can this be done for every measurement?

Also from the datasheet: "Writes to the 0xF5 “config” register in normal mode may be ignored. In sleep mode writes are not ignored." Does this mean that we cannot change IIR filter options in normal mode?

For register 0xF5 bits 7,6,5 refer to t_sb in normal mode, it should be set to 010. bits 4,3,2 refer to filter options. I am not sure how this should be set. Please see below. bits 1 and 0 do not need to be changed.


From the datasheet: "The IIR filter can be configured using the filter[2:0] bits in control register 0xF5 with the following options:
IIR.JPG
IIR.JPG (23.13 KiB) Viewed 3923 times
"

I am not sure what the values should be to set the IIR filter coefficient to 4 for floor change detection. I would also like to turn the IIR filter off to check if that works better.

How should I update the Adafruit_BMP260.cpp script? Thank you so much for your help :)

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: BMP280 oversampling and precision

Post by adafruit_support_rick »

Well, I really don't know all that much about the sensor. I'd have to study the datasheet for a while.
Maybe somebody else here knows. I'll ask around.

User avatar
adafruit2
 
Posts: 22200
Joined: Fri Mar 11, 2005 7:36 pm

Re: BMP280 oversampling and precision

Post by adafruit2 »

you can put your changes here
https://github.com/adafruit/Adafruit_BM ... 80.cpp#L65
it sounds like you'll need to put the sensor to sleep - set the bit in the register required (check the DS) to take it out of active/normal mode, then make your changes

the BME280 library is similar, and has some settings that are documented
https://github.com/adafruit/Adafruit_BM ... 0.cpp#L125

that might help!

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”