Giter Site home page Giter Site logo

sparkfun / sparkfun_bme280_arduino_library Goto Github PK

View Code? Open in Web Editor NEW
117.0 52.0 113.0 127 KB

An Arduino library to control the BME280 humidity and pressure sensor.

Home Page: https://www.sparkfun.com/products/14348

License: Other

C++ 100.00%
arduino-library pressure-sensor humidity-sensor altitude

sparkfun_bme280_arduino_library's Introduction

SparkFun BME280 Arduino Library

SparkFun BME280 Breakout

SparkFun CCS811/BME280 Combo (SEN-14348)

This library allows the user to:

  • Read pressure in Pa
  • Read temperature in C
  • Read humidity in %RH

It also provides the following mathematical functions based from the above.

  • Read temperature in F
  • Read altitude in meters
  • Read altitude in feet

Some examples include a circular buffer class for averaging.

Thanks to:

Repository Contents

  • /examples - Example sketches for the library (.ino). Run these from the Arduino IDE.
  • /extras - Additional documentation for the user. These files are ignored by the IDE.
  • /src - Source files for the library (.cpp, .h).
  • keywords.txt - Keywords from this library that will be highlighted in the Arduino IDE.
  • library.properties - General library properties for the Arduino package manager.

Documentation

Products that use this Library

Version History

  • V_1.0.0 - Public release.
  • V_1.1.0 - Pulled request to add decimal precision to readFloatPressure() and readFloatHumidity().
  • V_1.2.0 - Added ESP32 architecture directives to modify begin operation.
  • V_2.0.0 - Major update. Generalized wire port. Functionalized oversampling, standby time, etc. Added setMode.

License Information

This product is open source!

Please review the LICENSE.md file for license information.

If you have any questions or concerns on licensing, please contact [email protected].

Distributed as-is; no warranty is given.

  • Your friends at SparkFun.

sparkfun_bme280_arduino_library's People

Contributors

andyengland521 avatar calvin1564 avatar cdonate avatar fabyte avatar jdavid avatar jkfritcher avatar jnslr avatar lukagith avatar marshalltaylorsfe avatar nseidle avatar olicooper avatar pbolduc avatar santaimpersonator avatar sfemark avatar tedder avatar xoseperez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sparkfun_bme280_arduino_library's Issues

Example9_SoftwareI2C/Example9_SoftwareI2C.ino:38: undefined reference to `BME280::beginI2C(SoftwareWire&)'

I took the exact Example9_SoftwareI2C.ino sample without any modification, compile fails with:

C:\Users\me\AppData\Local\Temp\cc9OHCNm.ltrans0.ltrans.o: In function `setup':

C:\Users\me\Documents\arduino-1.8.8\libraries\SparkFun_BME280_Arduino_Library-master\examples\Example9_SoftwareI2C/Example9_SoftwareI2C.ino:38: undefined reference to `BME280::beginI2C(SoftwareWire&)'

collect2.exe: error: ld returned 1 exit status

Connecting to A4 & A5 doesn't work.

Worth noting that examples, tutorials and documentation made note to connect SDA and SCL to A4 and A5, however this did not work on my Arduino Uno or MKR Wifi 1010 - I had to connect them to the boards corresponding SDA and SCL inputs.

This initially caused me a little confusion and might be worth noting in examples.

Changes to stand by time and filter could be ignored

The the Bosch BME280 data sheet state,

5.4.6 Register 0xF5 "config"
The "config" register sets the rate, filter and interface options of the device. Writes to the "config" register in normal mode may be ignored. In sleep mode writes are not ignored.

Since at the end of the begin call, the mode is set to normal. Calls to setStandbyTime or setFilter may be ignored. It should also be noted about the sensor mode transitions,

3.3.1 Sensor mode transitions
If the device is currently performing a measurement, the execution of mode switching commands is delayed until the end of the currently running measurement period.

These two functions should check the current mode, if it is not in sleep mode, change to sleep mode, make the change and return to the original mode. If the device is currently measuring, it should wait until the measurement is complete before setting the values.

It is unclear in the data sheet, if in forced mode if the writes would be ignored or not. In forced mode, once the measurement is complete, the mode transitions back to sleep automatically.

The error is easy for someone to come across, for example Issue 27, the person calls begin and subsequently calls setStandbyTime andsetFilter.

I can also see setTempOverSample, setPressureOverSample and setHumidityOverSample use this get mode, set mode to sleep, change setting and set mode to original pattern. I was not able to find anything in the data sheet about requiring sleep mode for the over sample settings to take effect. The temperature and pressure settings use the same ctrl_meas register which is shared with the mode. The humidity oversampling does not take effect util a write to ctrl_meas, but it does not state the device needs to be in sleep mode.

reading pressure or humidity without temperature can result incorrect results

The readings for the humidity and pressure can be off because they depend on the temperature reading. There is a instance variable t_fine that both humidity and pressure reference. It is only initialized in when reading the temperature. This fact should be documented.

I propose adding a single method that reads all three measurements in a single call to the sensor. In my measurements on a Moteino M0, the time required to read temperature, humidity and pressure can be reduced by about 35% (1139 us vs 1729 us). Reading all values in a single call ensures the sensor values are all from the same measurement.

My first prototype looks like this. However, I am thinking on changing this a bit to align it better with the style of BME280 class with various methods (ie temperature in C / F, altitude in meters / feet). Thoughts?

struct BME280_SensorMeasurements
{
  public:
	float temperature;
	float pressure;
	float humidity;
};

class BME280
{
  public:
    void read(BME280_SensorMeasurements *measurements);
}

edit: fixed units from ns to us.

.begin() get hanging if BME280 failure

I simulate BME280 failure by remove Vcc out of the sensor. The code get hanging when I call .begin(). There should be a way to improve the code by testing the BME280 and return result to the . begin().
/tee

SparkFunBME280.cpp:410:37: error: ‘pow’ was not declared in this scope

There are several calls to math functions (pow, log, log10) but math.h is not included.

This is not an issue with Arduino probably because math.h is included somewhere else. But I'm trying to use this library with RIOT-OS, which has an Arduino compatibility module and I get a number of errors like:

error: ‘pow’ was not declared in this scope

For now I'll have to apply a patch, but it would be cool to be able to use this library without modifications. This is the patch I'm going to use:

--- SparkFunBME280.cpp	2020-10-23 18:52:48.971574912 +0200
+++ SparkFunBME280_math.cpp	2020-10-23 19:08:15.968040892 +0200
@@ -20,6 +20,7 @@
 ******************************************************************************/
 //See SparkFunBME280.h for additional topology notes.
 
+#include <math.h>
 #include "SparkFunBME280.h"
 
 //****************************************************************************//

Calibration's problem

Hello,

I found an problem reading data from BME280. Where should I look and search, according to an fact that on some other library's data are readable on Arduino monitor.
I2C_ReadAllData.ino respond as below:

Program Started
Starting BME280... result of .begin(): 0x1
Displaying ID, reset and ctrl regs
ID(0xD0): 0x1
Reset register(0xE0): 0x1
ctrl_meas(0xF4): 0x1
ctrl_hum(0xF2): 0x1

Displaying all regs
0x80:80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F
0x90:90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F
0xA0:A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF
0xB0:B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF
0xC0:C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF
0xD0:D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF
0xE0:E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF
0xF0:F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF

Displaying concatenated calibration words
dig_T1, uint16: 257
dig_T2, int16: 257
dig_T3, int16: 257
dig_P1, uint16: 257
dig_P2, int16: 257
dig_P3, int16: 257
dig_P4, int16: 257
dig_P5, int16: 257
dig_P6, int16: 257
dig_P7, int16: 257
dig_P8, int16: 257
dig_P9, int16: 257
dig_H1, uint8: 1
dig_H2, int16: 257
dig_H3, uint8: 1
dig_H4, int16: 17
dig_H5, int16: 16
dig_H6, uint8: 1

Temperature: 0.00 degrees C
Temperature: 32.00 degrees F
Pressure: 21742956.00 Pa
Altitude: -81480.92m
Altitude: -267325.84ft
%RH: 0.00 %

Temperature: 0.00 degrees C
Temperature: 32.00 degrees F
Pressure: 21742956.00 Pa
Altitude: -81480.92m
Altitude: -267325.84ft
%RH: 0.00 %

I'll be glad for some help.
Best regards,
QwiateQ

Incorrect Coefficient in Altitude Calculation

I believe there is an error in the altitude calculation formula (SparkFunBME280.cpp, line #421). The coefficient value of 45846.2 does not match international (ISA) or US standard altitude models.

To match accepted standards this should have a value of 44330.77 (44330.76923 to be exact).

I know it seems a small issue, but since this is a multiplier, it results in values that are 3.4% too high. Here are some references supporting this coefficient:

https://www.iso.org/standard/7472.html
ISO Standard Atmosphere. The primary source document for the international standard. (Unfortunately there is a charge to download this document.)

https://www.fai.org/sites/default/files/documents/sc4_vol_edic_16_rev_1.pdf
FAI World Aeromodeling document. A more accessable document describing altimeter requirements for model aircraft competition. (See page 10)

https://en.wikipedia.org/wiki/International_Standard_Atmosphere
Wikipedia info on altitude standards with more references at the end of the document.

https://github.com/adafruit/Adafruit_BME280_Library
The Adafruit BME280 library uses a value of 44330.0 (line 591).

Thank you for your efforts!

Usage of Wire library (not a bug, only source code aesthetics)

The way that the function Wire.requestFrom() is used can be improved.
Others are copying this code and the comment that the slave (Target) may send less than requested is confusing, because that is not correct.

The Wire.requestFrom() is used in 4 places.
One way to improve it could be this:

// request bytes from slave device
uint8_t n = (uint8_t) _hardPort->requestFrom(settings.I2CAddress, length);
if (n == length)
{
  while (_hardPort->available() > 0)
  {
    c = _hardPort->read(); // receive a byte as character
    *outputPointer = c;
    outputPointer++;
  }
}

The while can be a for (uint8_t i=0; i<n; i++), because once the received number of bytes is the same as the requested number of bytes, it is 100% sure that those bytes can be read with Wire.read().

A while is confusing if only one byte is read. It can be this:

uint8_t n = (uint8_t) _hardPort->requestFrom(settings.I2CAddress, numBytes);
if (n == numBytes)
{
  result = _hardPort->read(); // receive a byte as a proper uint8_t
}

This new code will do exactly the same thing as the old code in every situation. It is only source code aesthetics.

some minor suggerstions

  • samples should include setting the i2c adress, my bme280-modul needed bme280.settings.I2CAddress = 0x76;
  • Wire.begin() should be removed (different plattforms need other begin()-calls)
  • result of BME280::begin() should be defined or shown in example (perhaps having it as a true/false if not 0x60 would be a better option but break compatibility)

BME280 GYBMEP incorrect sensor readings

Hi,

I am trying to read sensor data from BME280 GYBMEP connected to ESP8266 (MOD-WIFI-ESP8266-DEV by Olimex) via I2C. There is also APDS-9960 light sensor connected in parallel.

Readings from BME280 make no sense at all (see below). Is it some kind of calibration issue or a faulty sensor?

SDK:2.2.1(cfd48f3)/Core:2.4.1/lwIP:2.0.3(STABLE-2_0_3_RELEASE/glue:arduino-2.4.1)
APDS-9960 initialization complete
Light sensor is now running
Starting BME280... result of .begin(): 0xD0
Displaying ID, reset and ctrl regs
ID(0xD0): 0xD0
Reset register(0xE0): 0xD0
ctrl_meas(0xF4): 0xD0
ctrl_hum(0xF2): 0xD0


Displaying all regs
0x80:08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 
0x90:09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 
0xA0:0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 
0xB0:0B 0B 0B 0B 0B 0B 0B 0B 0B 0B 0B 0B 0B 0B 0B 0B 
0xC0:0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 
0xD0:0D 0D 0D 0D 0D 0D 0D 0D 0D 0D 0D 0D 0D 0D 0D 0D 
0xE0:0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 
0xF0:0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 


Displaying concatenated calibration words
dig_T1, uint16: 43728
dig_T2, int16: -21808
dig_T3, int16: -21808
dig_P1, uint16: 43728
dig_P2, int16: -21808
dig_P3, int16: -21808
dig_P4, int16: -21808
dig_P5, int16: -21808
dig_P6, int16: -21808
dig_P7, int16: -21808
dig_P8, int16: -21808
dig_P9, int16: -21808
dig_H1, uint8: 208
dig_H2, int16: -21808
dig_H3, uint8: 208
dig_H4, int16: -21248
dig_H5, int16: -21075
dig_H6, uint8: 208

Init completed!
Tick...
Light: Ambient: 0 R: 0 G: 0 B: 0
Temperature: 50.30 degrees C
Pressure: 5522.10 Pa
Altitude: 19489.89m
%RH: 0.00 %

Tick...
Light: Ambient: 166 R: 55 G: 63 B: 64
Temperature: 50.30 degrees C
Pressure: 5522.10 Pa
Altitude: 19489.89m
%RH: 0.00 %

Tick...
Light: Ambient: 166 R: 55 G: 63 B: 64
Temperature: 50.30 degrees C
Pressure: 5522.10 Pa
Altitude: 19489.89m
%RH: 0.00 %

Tick...
Light: Ambient: 166 R: 55 G: 63 B: 64
Temperature: 50.30 degrees C
Pressure: 5522.10 Pa
Altitude: 19489.89m
%RH: 0.00 %

Tick...
Light: Ambient: 165 R: 55 G: 63 B: 64
Temperature: 50.30 degrees C
Pressure: 5522.10 Pa
Altitude: 19489.89m
%RH: 0.00 %

Tick...
Light: Ambient: 165 R: 54 G: 63 B: 64
Temperature: 50.30 degrees C
Pressure: 5522.10 Pa
Altitude: 19489.89m
%RH: 0.00 %

Tick...
Light: Ambient: 165 R: 54 G: 63 B: 64
Temperature: 50.30 degrees C
Pressure: 5522.10 Pa
Altitude: 19489.89m
%RH: 0.00 %

Tick...
Light: Ambient: 165 R: 54 G: 63 B: 64
Temperature: 50.30 degrees C
Pressure: 5522.10 Pa
Altitude: 19489.89m
%RH: 0.00 %

Tick...
Light: Ambient: 165 R: 55 G: 63 B: 64
Temperature: 50.30 degrees C
Pressure: 5522.10 Pa
Altitude: 19489.89m
%RH: 0.00 %

Tick...
Light: Ambient: 165 R: 55 G: 63 B: 64
Temperature: 50.30 degrees C
Pressure: 5522.10 Pa
Altitude: 19489.89m
%RH: 0.00 %

beginSPI and beginI2C call begin twice

In functions beginSPI and beginI2C there are two calls to the begin function. The begin function has a 2 ms delay at the start to accommodate BME280 startup. When using a BME280, this introduces more delay that is required. Capturing the return value of begin and using it in the comparisons will eliminate the extra startup delay. PR will be submitted shortly.

Change

	if(begin() == 0x58) return(true); //Begin normal init with these settings. Should return chip ID of 0x58 for BMP
	if(begin() == 0x60) return(true); //Begin normal init with these settings. Should return chip ID of 0x60 for BME

to

	uint8_t chipID = begin();

	if(chipID == 0x58) return(true); //Begin normal init with these settings. Should return chip ID of 0x58 for BMP
	if(chipID == 0x60) return(true); //Begin normal init with these settings. Should return chip ID of 0x60 for BME

Error compiling for board SparkFun SAMD51 Thing Plus

I wanted to hook up my lovely SparkFun BME280 / CCS811 Qwiic board to my SAMD51 Thing Plus (for a solar-powered LoRaWAN environmental sensor :D), but ran into some issues compiling a sketch with this library.

I pared it down to this sketch, which I believe is the bare minimum needed to get the BME280 working:

#include <SparkFunBME280.h>

BME280  bme280;

void setup() {
  Serial.begin(9600);
  while (!Serial) ;
  bme280.settings.commInterface = I2C_MODE;
  bme280.settings.I2CAddress = 0x77;
  bme280.settings.runMode = 3; //  3, Normal mode
  bme280.settings.tStandby = 0; //  0, 0.5ms
  bme280.settings.filter = 0; //  0, filter off

  //tempOverSample can be:
  //  0, skipped
  //  1 through 5, oversampling *1, *2, *4, *8, *16 respectively
  bme280.settings.tempOverSample = 1;

  //pressOverSample can be:
  //  0, skipped
  //  1 through 5, oversampling *1, *2, *4, *8, *16 respectively
  bme280.settings.pressOverSample = 1;

  //humidOverSample can be:
  //  0, skipped
  //  1 through 5, oversampling *1, *2, *4, *8, *16 respectively
  bme280.settings.humidOverSample = 1;

  if (bme280.begin() != 0x60) {
    Serial.println("BME280 failed");
    while (1);
  }

  Serial.println("OK");
}

void loop() {
  // put your main code here, to run repeatedly:

}

But it doesn't compile:

Arduino: 1.8.9 (Linux), TD: 1.47, Board: "SparkFun SAMD51 Thing Plus"

Build options changed, rebuilding all
/home/kyle/Arduino/libraries/SparkFun_BME280/src/SparkFunBME280.cpp: In member function 'uint8_t BME280::begin()':
/home/kyle/Arduino/libraries/SparkFun_BME280/src/SparkFunBME280.cpp:98:23: error: 'SPI_CLOCK_DIV32' was not declared in this scope
   SPI.setClockDivider(SPI_CLOCK_DIV32);
                       ^
exit status 1
Error compiling for board SparkFun SAMD51 Thing Plus.

I've verified that this works with the RedBoard Turbo.

My investigation shows that the SparkFun SAMD core only defines the clock dividers for 48MHz CPUs; I'll try to follow on with a PR for that in that repo. In the meantime, I've added the following after the 48MHz definitions (in ~/.arduino15/packages/SparkFun/hardware/samd/1.7.0/libraries/SPI):

#if F_CPU == 120000000
  #define SPI_CLOCK_DIV2   15
  #define SPI_CLOCK_DIV4   30
  #define SPI_CLOCK_DIV8   60
  #define SPI_CLOCK_DIV16  120
  #define SPI_CLOCK_DIV32  240
  #define SPI_CLOCK_DIV64  480
  #define SPI_CLOCK_DIV128 960
#endif

where each value is (120 MHz / 16 MHz * divider), as with the block above it.

Cheers!

relative humidity issues with BME280

I and others have noted problems with the BME280 relative humidity readings. These same kinds of problems appear to be common with "capacitive" temperature-compensated humidity sensors. BME280 RH values are almost universally too high. Under warm and humid conditions I have observed them "saturating" at 100% RH when this is clearly not possible. These problems appear to be related to how the temperature compensation algorithms work. It might be helpful if their software libraries (Adafruit, SparkFun) included access to the calibration coefficients that I assume are used to convert some sensor output to a relative humidity value. Then it might be possible to develop algorithms that would give more reasonable values -- compared to, for example, RH values from a nearby "official" weather station. Without better performance, these sensors simply aren't suited for outdoor use in weather stations, despite what is said about them by vendors such as Adafruit and SparkFun.
Thoughts? Suggestions?

Reference pressure can't be set

Dear Sir, my name is Emanuele and I'am an amateur softwarist. I was trying your library and I found many interesting features including the possibility to use oversampling.
The only problem I've found is that reference pressure cannot be set for proper altitude calculations. I've seen in the code, under Pressure Section that the reference pressure is set at 101325Pa; this value should be changed accordingly to the real pressure at sea level in order to calculate the right altitude.
Hope this can be useful.
Best regards,
Emanuele

readFloatHumidity doesn't return decimals

Hi! First of all thanks for the library!

I used the code from one of your examples to read the humidity into an array I initialized as follows:
float humidityBuffer[buffersize+1] = {0.0};
and later I read from the sensor with:
humidityBuffer[bufferposition] = mySensor.readFloatHumidity();
and I get values like "38" but with no decimal places. It works for temperature and with a division by 100 for pressure in hectopascals as well.

What am I doing wrong or is this an error in the library? I'm using the version from the library manager in Arduino IDE with an ESP8266.

Relative Humidity always an integer %

In SparkFunBME280.cpp, function readFloatHumidity():

return (float)((var1>>12) >> 10);

is truncating result to integer. Comment above says there are 10 fractional bits. I changed this in my copy to:

return ((float)(var1>>12)) / 1024;

and confirmed this now yeilds 3 decimal places.

I am a newbie at github and have never performed a "pull request", which is what I assume I should be doing. First of all can someone please confirm my change is appropriate?

Initial reading inaccurate when using MODE_SLEEP

I Serial.print() the following to the console. Notice the intial h_pc, p_hpa and alt_m readings are off and how it takes 16ms to read...

Measure time 16ms => {"h_pc":51.34,"p_hpa":95007.30,"alt_m":558.15,"temp_c":21.32}
Measure time 8ms => {"h_pc":58.79,"p_hpa":98630.13,"alt_m":234.53,"temp_c":21.30}
Measure time 8ms => {"h_pc":51.03,"p_hpa":98629.98,"alt_m":234.55,"temp_c":21.26}
Measure time 8ms => {"h_pc":56.95,"p_hpa":98627.13,"alt_m":234.80,"temp_c":21.25}
Measure time 8ms => {"h_pc":53.36,"p_hpa":98624.58,"alt_m":235.02,"temp_c":21.25}

If it helps I am using PlatformIO with the latest ESP32 Arduino (1.3.0) on the Lolin Wemos D1 mini Pro

My main.cpp looks as follows:

#include <Arduino.h>
#include <Wire.h>
#include "SparkFunBME280.h"

BME280 bme; // I2C

void printValues();

void setup() {
    Serial.begin(9600);
    Serial.println(F("BME280 test"));

    Wire.begin(SDA,SCL);
    Wire.setClock(400000);
    bme.setI2CAddress(0x76);

    if (bme.beginI2C() == false) {
        Serial.println(F("No sensor response. Please check wiring."));
        ESP.deepSleep(0);
    }
    bme.setFilter(2); //0 to 4 is valid. Filter coefficient. See 3.4.4
    bme.setStandbyTime(5); //0 to 7 valid. Time between readings. See table 27.
    bme.setTempOverSample(1); //0 to 16 are valid. 0 disables temp sensing. See table 24.
    bme.setPressureOverSample(1); //0 to 16 are valid. 0 disables pressure sensing. See table 23.
    bme.setHumidityOverSample(1); //0 to 16 are valid. 0 disables humidity sensing. See table 19.
    bme.setMode(MODE_SLEEP); //MODE_SLEEP, MODE_FORCED, MODE_NORMAL is valid. See 3.3
}

void loop() {
    bme.setMode(MODE_FORCED); //Wake up sensor and take reading

    long startTime = millis();
    while(bme.isMeasuring() == false); //Wait for sensor to start measurment
    while(bme.isMeasuring() == true); //Hang out while sensor completes the reading    
    long endTime = millis();
    // bme.setMode(MODE_SLEEP); //Needed?

    //Sensor is now back asleep but we get get the data
    Serial.print(F("Measure time "));
    Serial.print(endTime - startTime);
    Serial.print("ms => ");

    printValues();
    delay(30e3); // 30 second sleep (30,000 ms)
}

void printValues() {
    Serial.print("{\"h_pc\":"); Serial.print(bme.readFloatHumidity(), 2);
    Serial.print(",");

    Serial.print("\"p_hpa\":"); Serial.print(bme.readFloatPressure(), 2);
    Serial.print(",");

    Serial.print("\"alt_m\":"); Serial.print(bme.readFloatAltitudeMeters(), 2);
    Serial.print(",");

    Serial.print("\"temp_c\":"); Serial.print(bme.readTempC(), 2);
    Serial.print("}\n");
}

Dual Sensors have different readings

I have two sensors set up on the i2c interface and they are both sitting right next to each other but the readings I am getting from them are considerably different even thought the settings for them both are the same.

gTemp: 17.69 <--- This is a Dallas 1 wire sensor I am using as a reference
iTemp: 17.66 oTemp: 19.26
iPress: 70562.03 oPress: 101665.53
iHum: 59.30 oHum: 73.39

the sensors are set up as i and o (one will eventually be outside a box and the other inside)

The settings I used to set these up are as follows.

[code]
SensorI.beginI2C();
SensorI.settings.commInterface = I2C_MODE;
SensorI.settings.I2CAddress = 0x76;
SensorI.setFilter(0); //0 to 4 is valid. Filter coefficient. See 3.4.4
SensorI.setStandbyTime(0); //0 to 7 valid. Time between readings. See table 27.
SensorI.setTempOverSample(1); //0 to 16 are valid. 0 disables temp sensing. See table 24.
SensorI.setPressureOverSample(1); //0 to 16 are valid. 0 disables pressure sensing. See table 23.
SensorI.setHumidityOverSample(1); //0 to 16 are valid. 0 disables humidity sensing. See table 19.
SensorI.setMode(MODE_FORCED); //MODE_SLEEP, MODE_FORCED, MODE_NORMAL is valid. See 3.3

SensorO.beginI2C();
SensorO.settings.commInterface = I2C_MODE;
SensorO.settings.I2CAddress = 0x77;
SensorO.setFilter(0); //0 to 4 is valid. Filter coefficient. See 3.4.4
SensorO.setStandbyTime(0); //0 to 7 valid. Time between readings. See table 27.
SensorO.setTempOverSample(1); //0 to 16 are valid. 0 disables temp sensing. See table 24.
SensorO.setPressureOverSample(1); //0 to 16 are valid. 0 disables pressure sensing. See table 23.
SensorO.setHumidityOverSample(1); //0 to 16 are valid. 0 disables humidity sensing. See table 19.
SensorO.setMode(MODE_FORCED); //MODE_SLEEP, MODE_FORCED, MODE_NORMAL is valid. See 3.3
[/code]

Am i missing something?

Wire.begin Called Within .begin Method

Mostly a style issue - SparkFun libraries now usually leave the I2C / SPI begin methods to be called at the sketch level so that configuration parameters can be respected.

Oversampling bits?

Dear Friends,

A question emerged in me during browsing your code. The function checkSampleValue() in SparkFunBME280.cpp seems returning incorrect values for configuration register bitfields in some cases. Table 20, 23 and 24 in the BME280 datasheet show that 4-, 8- and 16-times oversampling should be represented by 0b011 (3), 0b100 (4) and 0b101 (5) bitfield values. As I see, the function now simply returns with values 4, 8 and 16, which are incorrect. Moreover, this return value is used in setXXXOverSample() functions, and values 8 and 16 contain bits that may unintentionally overwrite other fields in registers.
How do you think, maybe am I right, or I had not noticed something?

Best regards,
Zoltan

High current consumption

Reading the temp/pressure/humidity using this library seems to leave the bme280 in a state where it consumes over 400uA, and stays like that indefinitely. It would be better if the readTempC(), readFloatHumidity() and readFloatPressure() functions put the chip into sleep or standby mode after the reading has been taken. These modes use < 1uA. See page 7 of the data sheet: http://www.mouser.com/ds/2/783/BST-BME280_DS001-11-844833.pdf

Workaround: user can call reset() after taking readings. This means that begin() must be called every time before readings are taken, e.g.:
combinedSensor.begin(); temperatureNow = combinedSensor.readTempC(); double humidityNow = combinedSensor.readFloatHumidity(); double pressureNow = combinedSensor.readFloatPressure() / 100; combinedSensor.reset();
This reduces current consumption to around 8uA vs. 400uA after readings are taken, according to my multimeter. However, as begin() calls Wire.begin(), there could be side-effects of this workaround. But workaround works OK for me.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.