SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By PerryP
#193677
Hi all,
I"m working on a data logger project these days.
All components are mounted on a breadboard.
On the breadboard is ,... an Arduino Nano running at 8Mhz, a DS3231 RTC, an SD card,..and the BME280 Atmospheric sensor.
The BME280 is connected to A4 &A5 via I2c,...the rtc (DS3231) and card are connected via SPI.
All components are being powered by the nano at 3.3V.

Here is the issue,..
I do read and write to the serial monitor,...logging to the card works as well.
The temperature and humidity readings are accurate.
The altitude reading is off by roughly double ( I'm at 136 meters, and the card logs 300+ meters).
I suspect a correction factor needs to be included in the code to correct to sea level.
Code is bellow...
Cheers,
Perry

#include "SparkFunBME280.h"
#include "Wire.h"
#include "SPI.h"
#include "SD.h"
#include <DS3231.h>
BME280 mySensor;
DS3231 rtc(SDA, SCL);
float tempC; // Variable for holding temp in C
float pressure; // Variable for holding pressure reading
float humidity; // variable for humidity

int chipSelect = 4; //chipSelect pin for the SD card Reader
File mySensorData; //Data object you will write your sesnor data to

void setup()
{
mySensor.settings.commInterface = I2C_MODE;
mySensor.settings.I2CAddress = 0x77;
mySensor.settings.runMode = 3; //Normal mode
mySensor.settings.tStandby = 0;
mySensor.settings.filter = 0;
mySensor.settings.tempOverSample = 1;
mySensor.settings.pressOverSample = 1;
mySensor.settings.humidOverSample = 1;

Serial.begin(9600);
rtc.begin();
pinMode(10, OUTPUT);
SD.begin(4); //initialize the card reader
delay(10); //Make sure sensor had enough time to turn on. BME280 requires 2ms to start up.
Serial.println(mySensor.begin(), HEX);
uint8_t memCounter = 0x80;
uint8_t tempReadData;
{
{
tempReadData = mySensor.readRegister(memCounter);
memCounter++;
}
}
}

void loop()
{
tempC = mySensor.readTempC(); // Read Temperature from BME280
pressure = mySensor.readFloatAltitudeMeters(); //Read Pressure
humidity = mySensor.readFloatHumidity(); //read humidity
mySensorData = SD.open("Datalog.txt", FILE_WRITE);

Serial.print(mySensor.readTempC(),0);
Serial.print(",");
Serial.print((mySensor.readFloatAltitudeMeters()-125),0);
Serial.print(",");
Serial.print(mySensor.readFloatHumidity(),0);
Serial.print (" ");
Serial.print(rtc.getTimeStr());
Serial.println();

mySensorData.print((tempC),0); //write temperature to card
mySensorData.print(",");
mySensorData.print((pressure),1); //write pressure to the card
mySensorData.print(",");
mySensorData.print((humidity),0); //write humidity to the card
mySensorData.print(" ");
mySensorData.print(rtc.getTimeStr()); //write time to the card
mySensorData.println();
mySensorData.close(); //close the file

delay(1000);
}
By UhClem
#193701
PerryP wrote:The altitude reading is off by roughly double ( I'm at 136 meters, and the card logs 300+ meters).
I suspect a correction factor needs to be included in the code to correct to sea level.
Conversion from pressure to altitude is non-linear and subject to problems. Number one being that it assumes a standard atmosphere. It is very unlikely that you will have a standard atmosphere present. Ever. High pressure systems, low pressure, temperature variations, humidity, etc. So your results are pretty decent.
By Valen
#193709
The code looks a bit odd. In the loop it first stores recorded values of temp,pressure, humidity into a variable. Then records them again from the sensor to send it to serial. And then it writes the original variables to the SD card. Why send different data to the serial (debug?) port?
By PerryP
#193728
Good observation valen!
Because of the inconsistencies with the sensor. I"ve found that prior to logging. The software requires periodic re calibration (to correct for the inaccuracy).
So, I use the serial monitor for a quick check, recal,...then flash the controller.
This way I"m sure the time stamp, and bar/alt. are correct...
By Valen
#193733
Maybe I am misunderstanding your last response. But it's not odd that you are sending data to serial port to verify it is working correctly or accurately. I find it odd that you are not sending the initially measured values to the serial port. You retrieve values a second time, and because of noise potentially different from the first time. The values on the SD card would not match the serial log. Ok, only by split second drift or noise. But still, shouldn't both be exactly the same? Also the time recorded to the SD-card is later than when those values were actually determined. Shouldn't rtc.getTimeStr() for the SD-card be called earlier and stored in a variable, just like TempC, humidity,pressure to be consistent?
By jremington
#193734
The altitude reading is off by roughly double ( I'm at 136 meters, and the card logs 300+ meters).
I suspect a correction factor needs to be included in the code to correct to sea level.
The calculated altitude depends on the local air pressure, relative to sea level and can vary by hundreds of meters over the course of a day. The sea level reference has to be updated very frequently for barometric altitude measurements to be useful, and that correction will be found in the library you are using.

See http://www.engineeringtoolbox.com/air-a ... d_462.html

Note that all airports and most weather stations report the calculated "sea level" pressure, not the local pressure.
By wpilgri
#194091
Just to add some more more information to support the BME280 lack of precision comments I have the SparkFun Atmospheric Sensor Breakout SEN-13676 and so far am disappointed by its accuracy:

Temperature: Works fine but has an approx 2 degC offset too high. I am comparing to a thermocouple and thermistor and the BME280 consistently reads high, no matter what mode it is in.

Pressure: Very disappointing readings. I look right now and it is reading 93.2 kPa but I check the local weather and it says 101.3 kPa and my Garmin watch shows 1014 millibars=101.4 kPa so the BME280 seems like the one that is out.

I haven't read of any way to calibrate and improve accuracy...if anyone knows how please share. For now I have simply added an offset to temperature but that's a hack and pressure, well I just don't believe it. Disappointing purchase.
By jremington
#194092
Pressure: Very disappointing readings. I look right now and it is reading 93.2 kPa but I check the local weather and it says 101.3 kPa and my Garmin watch shows 1014 millibars=101.4 kPa so the BME280 seems like the one that is out.
Probably not. See the last line of the post immediately above yours.