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.
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.
Here it is
#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;
}
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:
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
}
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.
I have a NodeMCU (ESP8266) reading data from a BMP280 module
its fully documented here
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
Thank you all for your input. Now I need some time to read all what you suggested.
Thx again
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.