finitespace / BME280

Provides an Arduino library for reading and interpreting Bosch BME280 data over I2C, SPI or Sw SPI.
GNU General Public License v3.0
212 stars 105 forks source link

BME280

Provides an Arduino library for reading and interpreting Bosch BME280 data over I2C, SPI or Sw SPI. Additional environment calculation functions are provided. ESP and BRZO are now supported.

Table of Contents

  1. BME280

  2. Table of Contents

  3. Summary

  4. Installation

  5. Usage

  6. Enumerations

  7. Settings

  8. Methods

  9. Environment Calculations

  10. Contributing

  11. History

  12. Credits

  13. License

Summary

Reads temperature, humidity, and pressure. Calculates altitude, equivalent sea level pressure and dew point. Provides functions for english and metric. Also reads pressure in Pa, hPa, inHg, atm, bar, torr, N/m^2 and psi.

Installation

To use this library download the zip file, decompress it to a folder named BME280. Move the folder to {Arduino Path}/libraries.

Usage

Include the library at the top of your Arduino script. #include <BME280> Create a global or local variable. BME280 bme In your start up call bme.begin(). Read the temperature, humidity, pressure, altitude and/or dew point.

float pres, temp, hum bme.read(pres, temp, hum)

or

temp = bme.temp() hum = bme.hum() pres = bme.pres()

Enumerations

TempUnit Enum

PresUnit Enum

OSR Enum

Mode Enum

StandbyTime Enum

Filter Enum

ChipModel Enum

Settings

BME280::Settings Struct

    * Temperature Oversampling Rate (tempOSR): OSR Enum, default = OSR_X1

    * Humidity Oversampling Rate (humOSR): OSR Enum, default = OSR_X1

    * Pressure Oversampling Rate (presOSR): OSR Enum, default = OSR_X1

    * Mode (mode): Mode Enum, default = Mode_Forced

    * Standby Time (standbyTime): StandbyTime Enum, default = StandbyTime_1000ms

    * Filter (filter): Filter Enum, default = Filter_16

    * SPI Enable: SpiEnable Enum, default = false
      values: true = enable, false = disable

BME280I2C::Settings Struct

BME280Spi::Settings Struct

BME280I2C(const BME280I2C::Settings& settings)

Constructor used to create the I2C Bme class. All parameters have default values.

BME280Spi(const BME280Spi::Settings& settings)

Constructor used to create the Spi Bme class. All parameters have default values except chip select.

BME280SpiSw(const BME280SpiSw::Settings& settings)

Constructor used to create the software Spi Bme class. All parameters have default values except chip select, mosi, miso and sck.

bool begin()

Method used at start up to initialize the class. Starts the I2C or SPI interface. Can be called again to re-initialize the mode settings.

Note: To allow the user to provide their own wire implementation, Wire.begin() (or the equalivant) must be called before bme.begin()

   * return: bool, true = success, false = failure (no device found)

void setSettings(const Settings& settings)

Method to set the sensor settings.

const Settings& getSettings() const

Method to get the sensor settings.

float temp(TempUnit unit)

Read the temperature from the BME280 and return a float.

    return: float = temperature

    * unit: tempUnit, default = TempUnit_Celsius

float pres(PresUnit unit)

Read the pressure from the BME280 and return a float with the specified unit.

    return: float = pressure

    * presUnit: uint8_t, default = PresUnit_hPa

float hum()

Read the humidity from the BME280 and return a percentage as a float.

    * return: float = percent relative humidity

void read(float& pressure, float& temp, float& humidity, TempUnit tempUnit, PresUnit presUnit)

Read the data from the BME280 with the specified units.

    return: None, however, pressure, temp and humidity are changed.

    * Pressure: float, reference
      values: reference to storage float for pressure

    * Temperature: float, reference
      values: reference to storage float for temperature

    * Humidity: float, reference
      values: reference to storage float for humidity

    * tempUnit: tempUnit, default = TempUnit_Celsius

    * presUnit: uint8_t, default = PresUnit_hPa

ChipModel chipModel()

    * return: [ChipModel](#chipmodel-enum) enum

Environment Calculations

float Altitude(float pressure, AltitudeUnit = AltitudeUnit_Meters, float seaLevelPressure = 1013.25, outsideTemp = 15.0, TempUnit = TempUnit_Celsius)

Calculate the altitude based on the pressure with the specified units.

    Return: float altitude

    * Pressure: float
      values: unit independent

    * AltitudeUnit: default = AltitudeUnit_Meters
      values:  AltitudeUnit_Meters, AltitudeUnit_Feet

    * Sea Level Pressure: float, default = 1013.25
      values:  unit independent

    * outsideTemp: float, default = 15.0
      values:  any float related to TempUnit

    * TempUnit: default = TempUnit_Celsius
      values: TempUnit_Celsius, TempUnit_Fahrenheit

      Note: The formula evaluates the height difference based on difference of pressure.
     - May be used to evaluate altitude over MSL. (default set)
                (default referencePressure, default outsideTemp parameters ~ ISA standard)
                The altitude is derived from QNH, used in aviation.
     - May be used to evaluate height over MSL
                (referencePressure should be equal to QFF read in meteorologic synoptic maps,
                outsideTemp should be equal to local temperature)
     - May be used to evaluate the height difference between two points
                (referencePressure should be set to the pressure on the lower point.)

float EquivalentSeaLevelPressure(float altitude, float temp, float pres, AltitudeUnit altUnit, TempUnit tempUnit )

Convert current pressure to equivalent sea-level pressure.

    Return: float equivalent pressure at sea level.

    * altitude: float
      values: meters

    * temp: float
      values: celsius

    * pres: float
      values: unit independent

    * AltitudeUnit: default = AltitudeUnit_Meters
      values:  AltitudeUnit_Meters, AltitudeUnit_Feet

    * TempUnit: default = TempUnit_Celsius
      values: TempUnit_Celsius, TempUnit_Fahrenheit

      Note: To get correct EquivalentSeaLevel pressure (QNH or QFF) the altitude value should be independent
      on measured pressure. It is necessary to use fixed altitude point e.g. the altitude of barometer
      read in map.

float DewPoint(float temp, float hum, TempUnit = TempUnit_Celsius)

Calculate the dew point based on the temperature and humidity with the specified units.

    return: float dew point

    * Temperature: float
      values: any float related to TempUnit

    * Humidity: float, unit = % relative humidity
      values: any float

    * TempUnit: TempUnit, default = TempUnit_Celsius
      values: TempUnit_Celsius = return degrees Celsius, TempUnit_Fahrenheit = return degrees Fahrenheit

float AbsoluteHumidity(float temperature, float humidity, TempUnit = TempUnit_Celsius)

Calculate the absolute humidity based on the temperature and humidity with the specified units.

    return: float absolute humidity

    * Temperature: float
      values: any float related to TempUnit

    * Humidity: float, unit = % relative humidity
      values: any float

    * TempUnit: TempUnit, default = TempUnit_Celsius
      values: TempUnit_Celsius = return degrees Celsius, TempUnit_Fahrenheit = return degrees Fahrenheit

float HeatIndex(float temperature, float humidity, TempUnit tempUnit = TempUnit_Celsius)

Calculate the heat index based on the temperature and humidity with the specified units. The U.S. NWS algorithm is used.

    return: float heat index in TempUnit

    * Temperature: float
      values: any float related to TempUnit

    * Humidity: float, unit = % relative humidity
      values: any float

    * TempUnit: TempUnit, default = TempUnit_Celsius
      values: TempUnit_Celsius = return degrees Celsius, TempUnit_Fahrenheit = return degrees Fahrenheit

Contributing

  1. Fork the project.
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request.

History

Credits

Written by Tyler Glenn, 2016.

Special thanks to Mike Glenn for editing and reviewing the code.

License

GNU GPL, see License.txt