Class BME280

java.lang.Object
com.diozero.devices.BME280
All Implemented Interfaces:
BarometerInterface, HygrometerInterface, SensorInterface, ThermometerInterface, Closeable, AutoCloseable

public class BME280
extends Object
implements BarometerInterface, ThermometerInterface, HygrometerInterface
Provides access to the Bosch BMx280 pressure and temperature sensor. The BME280 includes an additional humidity sensor. Different constructors support access via I2C or SPI. All constructors configure the device as follows:
  • Temperature oversampling: x1
  • Pressure oversampling: x1
  • Temperature oversampling: x1
  • Operating mode: Normal
  • Standby inactive duration: 1 second
  • IIR filter coefficient: Off
Author:
gregflurry, mattjlewis
  • Field Details

  • Constructor Details

    • BME280

      public BME280() throws RuntimeIOException
      Creates an instance that uses I2C. Assumes I2C bus 1 and the default I2C address (0x76); all other I2C instantiation parameters are set to the default.
      Throws:
      RuntimeIOException - if instance cannot be created
    • BME280

      public BME280​(int bus, int address) throws RuntimeIOException
      Creates an instance that uses I2C. The caller must provide the I2C bus number and the I2C address; all other I2C instantiation parameters are set to the default.
      Parameters:
      bus - I2C bus number
      address - device address
      Throws:
      RuntimeIOException - if instance cannot be created
    • BME280

      public BME280​(int chipSelect) throws RuntimeIOException
      Creates an instance that uses SPI. The caller must provide the chip select line; all other SPI instantiation parameters are set to the default.
      Parameters:
      chipSelect - the chip select line used
      Throws:
      RuntimeIOException - if instance cannot be created
    • BME280

      public BME280​(int controller, int chipSelect, int frequency, SpiClockMode mode) throws RuntimeIOException
      Creates an instance that uses SPI. The caller must provide all SPI instantiation parameters.
      Parameters:
      controller - the SPI controller used
      chipSelect - the chip select line used
      frequency - the frequency used
      mode - the clock mode used
      Throws:
      RuntimeIOException
  • Method Details

    • setOperatingModes

      public void setOperatingModes​(BME280.TemperatureOversampling tempOversampling, BME280.PressureOversampling pressOversampling, BME280.HumidityOversampling humOversampling, BME280.OperatingMode operatingMode)
      Sets the oversampling multipliers and operating mode.
      Parameters:
      tempOversampling - oversampling multiplier for temperature
      pressOversampling - oversampling multiplier for pressure
      humOversampling - oversampling multiplier for humidity
      operatingMode - operating mode
    • setStandbyAndFilterModes

      public void setStandbyAndFilterModes​(BME280.StandbyDuration standbyDuration, BME280.FilterCoefficient filterCoefficient)
      Sets the standby duration for normal mode and the IIR filter coefficient.
      Parameters:
      standbyDuration - standby duration
      filterCoefficient - IIR filter coefficient
    • waitDataAvailable

      public boolean waitDataAvailable​(int interval, int maxIntervals)
      Waits for data to become available.
      Parameters:
      interval - sleep interval
      maxIntervals - maximum number of intervals to wait
      Returns:
      true if data available, false if not
    • isDataAvailable

      public boolean isDataAvailable()
      Indicates if data is available.
      Returns:
      rue if data available, false if not
    • getValues

      public float[] getValues()
      Reads the temperature, pressure, and humidity registers; compensates the raw values to provide meaningful results.
      Returns:
      array in order of: temperature, pressure, humidity
    • getTemperature

      public float getTemperature()
      Reads the temperature, pressure, and humidity registers; compensates the raw values to provide meaningful results.
      Specified by:
      getTemperature in interface ThermometerInterface
      Returns:
      temperature
    • getPressure

      public float getPressure()
      Reads the temperature, pressure, and humidity registers; compensates the raw values to provide meaningful results.
      Specified by:
      getPressure in interface BarometerInterface
      Returns:
      pressure in hectoPascals (hPa)
    • getRelativeHumidity

      public float getRelativeHumidity()
      Reads the temperature, pressure, and humidity registers; compensates the raw values to provide meaningful results.
      Specified by:
      getRelativeHumidity in interface HygrometerInterface
      Returns:
      humidity
    • close

      public void close() throws RuntimeIOException
      Closes the device
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface HygrometerInterface
      Specified by:
      close in interface SensorInterface
      Throws:
      RuntimeIOException - if close fails
    • reset

      public void reset()
      Resets the device.