Skip to content

getSensorData()

Arnd edited this page Sep 27, 2020 · 5 revisions

getSensorData(temperature,humidity,pressure,gas,[waitSwitch]);


This returns the most recent readings from the BME680. The function will wait for an measurement in progress to complete before returning with the new results. In order to avoid floating point, which is both slow and memory-intensive on the Arduino, the results are returned as follows:

  • Temperature - in degrees Celsius times 100, e.g. a value of "2526" means 25.26° Celsius
  • Humidity - percentage times 100, e.g. a value of "3407" means 34.07% humidity
  • Pressure - in Pascals, thus "99979" denotes 999.79hPa
  • Gas - ambient air quality sensor

By default the function waits for any currently active conversion to complete before reading the measurements. If the caller wishes to control the execution and wait explicitly, the optional "waitSwitch" boolean can be set to "false" to disable the wait prior to the read.

The last action performed by the call is to trigger a new conversion. This is done to speed up the response time, since a measurement can take a long time depending upon the IIR, oversampling and the gas sensor settings. This means that if, for example, a minute goes by since the last call to getSensorData() then the next call to the function will return 1-minute old data.

The function has an optional return code. This is only used for gas readings, bit 0x20 is set when the gas is invalid and 0x10 is set when the heater has not stabilized; otherwise the value is 0. The other 3 readings are not affected.


Example:

BME680_Class BME680;  // Instantiate class    
...    
while (!BME680.begin()) {                          // Find on I2C bus
  Serial.println("Error, unable to find BME680."); // Show error message
  delay(5000);                                     // Wait 5 seconds 
} // of if-then we can't initialize or find the device
BME680.setOversample(TemperatureSensor,Oversample16); // 16x sampling to temperature
BME680.setOversample(HumiditySensor,SensorOff); // Don't measure humidity
BME680.setOversample(PressurSensor,Oversample8); // 8x oversampling for pressure
uint8 deviceMode = BME680.mode(NormalMode); // Set normal mode
int32_t temperature,humidity,pressure,gas;
uint8_t status = BME680.getSensorData(temperature,humidity,pressure,gas);