The BME280 is a humidity sensor features an extremely fast response time which supports performance requirements for emerging applications such as context awareness, and high accuracy over a wide temperature range. The pressure sensor is an absolute barometric pressure sensor with features exceptionally high accuracy and resolution at very low noise. The integrated temperature sensor has been optimized for very low noise and high resolution. It is primarily used for temperature compensation of the pressure and humidity sensors, and can also be used for estimating ambient temperature.
The best way to use the device is a module like the one below
Connection and Layout
You can use this module in either SPI or I2C modes, in this case we went for SPI mode, here is the wiring for our module to our Linkit one
Connect Vin to 5V.
Connect GND to ground
Connect the SCK pin to Digital #13
Connect the SDO pin to Digital #12
Connect the SDI pin to Digital #11
Connect the CS pin Digital #10
Code
The code uses the sparkfun library. There are several examples available. I removed some code from a basic example
Library – https://github.com/sparkfun/SparkFun_BME280_Arduino_Library
[codesyntax lang=”cpp”]
#include <stdint.h> #include "SparkFunBME280.h" #include "Wire.h" #include "SPI.h" //Global sensor object BME280 mySensor; void setup() { Serial.begin(57600); //SPI mySensor.settings.commInterface = SPI_MODE; mySensor.settings.chipSelectPin = 10; //Operation settings 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.print("Starting BME280... result of .begin(): 0x"); delay(10); //BME280 requires 2ms to start up. Serial.println(mySensor.begin(), HEX); } void loop() { //Each loop, take a reading. Serial.print("Temperature: "); Serial.print(mySensor.readTempC(), 2); Serial.println(" degrees C"); Serial.print("Temperature: "); Serial.print(mySensor.readTempF(), 2); Serial.println(" degrees F"); Serial.print("Pressure: "); Serial.print(mySensor.readFloatPressure(), 2); Serial.println(" Pa"); Serial.print("Altitude: "); Serial.print(mySensor.readFloatAltitudeMeters(), 2); Serial.println("m"); Serial.print("Altitude: "); Serial.print(mySensor.readFloatAltitudeFeet(), 2); Serial.println("ft"); Serial.print("%RH: "); Serial.print(mySensor.readFloatHumidity(), 2); Serial.println(" %"); Serial.println(); delay(1000); }
[/codesyntax]
Output
Open the serial monitor window and you should see something like this
Temperature: 24.46 degrees C
Temperature: 76.03 degrees F
Pressure: 99894.92 Pa
Altitude: 123.59m
Altitude: 405.47ft
%RH: 0.00 %
Temperature: 24.46 degrees C
Temperature: 76.03 degrees F
Pressure: 99891.47 Pa
Altitude: 124.12m
Altitude: 407.23ft
%RH: 0.00 %
The temperature looked accurate, I looked up the air pressure and altitude of my location on the internet. Not bad on air pressure as I looked it up a bit later than when I gathered the readings
Pressure | 1011.2 mb, Steady [Min 1010.5 Max 1012.5] |
---|
Altitude was about 40m out, according to http://elevationmap.net. I’ll need to investigate this as that’s not that good
Links
You can pick up one of these breakout/modules for under $5
1PCS BME280 digital Sensor Temperature Humidity Barometric Pressure Sensor