Wrong/non changing values with the SparkFunBME280 library

Hey guys, so I’m using the SparkFunBME280 library on my electron and I’m getting values that are both wrong and not changing on both Ubidots and over serial. Besides a function to convert from pascals to inHg, I’m just using the functions included in the library. I’m also using FuelGauge and a MAX30105 breakout but I shouldn’t be having any address collision. Any help you guys could give would be greatly appreciated! Here’s my sketch:

     #include <SparkFunBME280.h>
     #include <Ubidots.h>
     #define TOKEN "xxxxxxxxxxxxxxxxxxx"  // Put ubidots token here

     BME280 BME;
     Ubidots ubidots(TOKEN);
     FuelGauge fuel;

     float convertPascalToInchMercury(float x){
     float inchMercury = x * 0.000295;  //conversion factor for going from pascal to inches of mercury
     return inchMercury;
     }
     void setup() {
         BME.settings.commInterface = I2C_MODE; //select either i2c or spi mode
         BME.settings.I2CAddress = 0x77; //address of chip
         BME.settings.chipSelectPin = 10;
     	BME.settings.runMode = 0;
     	BME.settings.tempOverSample = 0;
     	BME.settings.pressOverSample = 0;
         BME.settings.humidOverSample = 0;
         BME.begin(); //essentially wire.begin()

     }

     void loop() {
         float pascals = BME.readFloatPressure();
         float pressure = convertPascalToInchMercury(pascals);
         float altitude = BME.readFloatAltitudeMeters();
         float humidity = BME.readFloatHumidity();
         float temp = BME.readTempC();
         
         ubidots.add("Temperature", temp);
         ubidots.add("Pressure", pressure);
         ubidots.add("Altitude", altitude);
         ubidots.add("Humidity", humidity);
         
         double cellVoltage = fuel.getVCell();
         double stateOfCharge = fuel.getSoC();
         
         ubidots.add("Voltage", cellVoltage);
         ubidots.add("Battery Percentage", stateOfCharge);
         ubidots.sendAll();
         
         Serial.println(temp);
         Serial.println(pressure);
         Serial.println(altitude);
         Serial.println(humidity);
         
         
         delay(20000);
     }

@espace, can you repost our code but specify you code block using the </> editor function.

What values are you getting? Are all the BME values (temp, pressure, altitude, and humidity) wrong and unvarying?

Not exactly sure what you mean.

All are wrong and unvarying, by double digits, for temp, pressure, and humidity and roughly 3x higher for altitude (my town sits at roughly 3690ft and I’m getting values around 3331m).

What is the actual value you’re getting for the temperature? Does it go up if you put your finger on the BME280?

I see the same unvarying values if I use the same settings that you are. If I use the ones in the example .ino file (I2C_ReadAllData.ino), I get results that seem about right and are varying.

BME.settings.filter = 4;
BME.settings.runMode = 3;
BME.settings.tempOverSample = 5;
BME.settings.pressOverSample = 5;
BME.settings.humidOverSample = 5;
1 Like

Hmmm, that’s interesting. Where are you seeing that .ino file? My code is what I pieced together from the .cpp file while browsing the library from the web IDE but I definitely could have missed something as I’m just picking up bit shifting and such. I’ll try those setting here in a few and see how things pan out.

It's one of the example files that's part of the library. You should see it when you choose a library in the web IDE.

e.g. this sampe features some enlightening comments
https://build.particle.io/libs/SparkFunBME280/1.1.2/tab/example/I2C_and_SPI_Multisensor.ino

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

Mark the 0 meaning “can be skipped” part.

Ahhhhhhh I never noticed that there was an example selection below the cpp and header files. Good to know. Thanks!

Never noticed the examples below the cpp and header files. Thanks!

1 Like

Care to explain the 1-5 parts or what they represent? Having a hard time seeing exactly what 1, 2, 3, 8, and 16 are pointing to.

The datasheet for any sensor is the place to get comprehensive info about such things


See chapter 3.4 (page 14) and following