Go Down

Topic: BME280 reading not stable (Read 235 times) previous topic - next topic

Marmadoc

I use BME280 with Adafruit library. 
I read pressure directly from sensor - aP=bme.readPressure()/100 with delay between readings 1000ms.
My problem is no stable reading.
Different between readings is about +/- 0.2hPa.
I need stable reading on first decimal place.
I did try to get average from 100 readings (every 50ms), but didn't help.
I know it is kind of noise, and try to find solution for it on internet. I found a couple places about sampling, but to be honest I do not understand it (I'm not good with coding);
Can you point me how to fix it.
Thx in advance.

jremington

Quote
I did try to get average from 100 readings (every 50ms), but didn't help.
Then you must have done something wrong.

Post the code, using code tags.

Marmadoc

Here it is
Code: [Select]
 #include "LiquidCrystal_I2C.h"
  LiquidCrystal_I2C lcd1(0x27,20,4);

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme;
float aPpomiar=0;
float aPsuma=0;
float aP=0;


void setup()
{
  Wire.begin();
  Serial.begin(9600);
  
  
   if (!bme.begin(0x76)) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
// LCD Display
  lcd1.init();  
  lcd1.backlight();  
  
  
}

void loop()
{
;
  
  
  aPaverage();
  Serial.print(aP,1);
Serial.println("hPa");
  
  Serial.println();
  
  lcd1.setCursor(0,0);  //col , row
  lcd1.print("Cis: ");
  lcd1.print(aP);
  lcd1.print("hPa");

  

  }
  
void aPaverage()
{
    for (int i = 0; i <= 99; i++)
  {
    aPpomiar=bme.readPressure();
    aPsuma=aPsuma+aPpomiar;
    delay(5);
  }
  aP=aPsuma/100;
  aP=aP/100;
  
}  

jremington

#3
Jan 22, 2021, 12:18 am Last Edit: Jan 22, 2021, 12:22 am by jremington
There are several problems with that code. You forgot to initialize the sum to zero, and you divide by the number of samples twice.

Try replacing the function "aPaverage" with this version:

Code: [Select]
void aPaverage()
{
    aPsuma = 0.0; //initialize sum
 for (int i = 0; i <= 99; i++)
  {
    aPsuma += bme.readPressure(); //accumulate readings
    delay(5);
  }
  aP=aPsuma/100.0;  //calculate average
}

Koepel

#4
Jan 22, 2021, 01:00 am Last Edit: Jan 22, 2021, 01:01 am by Koepel
Do you also have the BME280 module from Adafruit ? Can you give a link to where you bought your BME280 module ? Is that a real BME280 or a counterfeit ?
Which Arduino board do you use ?
A 5V Arduino board has a 5V I2C bus. A 3.3V Sensor has a 3.3V I2C bus. You should know what you are doing before connecting those together.

If you have a Arduino Mega 2560 with a bare BME280 sensor (without I2C level shifters), then your BME280 is probably already damaged and you should buy a new one.

johnerrington

I have a NodeMCU (ESP8266) reading data from a BMP280 module

its fully documented here

http://www.skillbank.co.uk/arduino/NodeI2CSPI.htm

I'm getting results like this:  ESP8266 Weather Station:  Pressure: 982.80 hPa

If you expect the last two digits to be stable - from a sensor module costing $1 - in free air

(ie with drafts & movement around it)

your expectations are unrealistic.

You can read about averaging readings here

http://www.skillbank.co.uk/arduino/adc1.htm



I'm trying to help. If I find your question interesting I'll give you karma. If you find my input useful please give me karma (I need it)

Marmadoc

Thank you all for your input. Now I need some time to read all what you suggested.
Thx again

Go Up