Git Product home page Git Product logo

bme280's Introduction

BME280

Provides an Arduino library for reading and interpreting Bosch BME280 data over I2C and SPI.

Table of Contents

Summary

Reads temperature, humidity, and pressure. Calculates altitude 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, uncompress 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()

float altitude, dewPoint altitude = bme.alt() dewPoint = bme.dew()

Use setMode(0x01) to trigger a new measurement in forced mode. NOTE: It takes ~8ms to measure all values (temp, humidity & pressure) when using x1 oversampling (see datasheet 11.1). Thus a delay of >8ms should be used after triggering a measurement and before reading data to ensure that read values are the latest ones.

Methods

BME280I2C(uint8_t tosr = 0x1, uint8_t hosr = 0x1, uint8_t posr = 0x1, uint8_t mode = 0x3, uint8_t st = 0x5, uint8_t filter = 0x0, bool spiEnable = false, uint8_t bme_280_addr = 0x76)

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

* Temperature Oversampling Rate (tosr): uint8_t, default = 0x1
  values: B000 = Skipped, B001 = x1, B010 = x2, B011 = x4, B100 = x8, B101/other = x16

* Humidity Oversampling Rate (hosr): uint8_t, default = 0x1
  values: B000 = Skipped, B001 = x1, B010 = x2, B011 = x4, B100 = x8, B101/other = x16

* Pressure Oversampling Rate (posr): uint8_t, default = 0x1
  values: B000 = Skipped, B001 = x1, B010 = x2, B011 = x4, B100 = x8, B101/other = x16

* Mode: uint8_t, default = Normal
  values: Sleep = B00, Forced = B01 and B10, Normal = B11

* Standby Time (st): uint8_t, default = 1000ms
  values: B000 = 0.5ms, B001 = 62.5ms, B010 = 125ms, B011 = 250ms, B100 = 250ms, B101 = 1000ms, B110 = 10ms, B111 = 20ms

* Filter: uint8_t, default = None
  values: B000 = off, B001 = 2, B010 = 4, B011 = 8, B100/other = 16

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

* BME280 Address: uint8_t, default = 0x76
  values: any uint8_t

BME280Spi(uint8_t spiCsPin, uint8_t tosr = 0x1, uint8_t hosr = 0x1, uint8_t posr = 0x1, uint8_t mode = 0x3, uint8_t st = 0x5, uint8_t filter = 0x0)

Constructor used to create the Spi Bme class. All parameters have default values. Return: None

* SPI Chip Select Pin (spiCsPin): uint8_t
  values: Any pin 0-31

* Temperature Oversampling Rate (tosr): uint8_t, default = 0x1
  values: B000 = Skipped, B001 = x1, B010 = x2, B011 = x4, B100 = x8, B101/other = x16

* Humidity Oversampling Rate (hosr): uint8_t, default = 0x1
  values: B000 = Skipped, B001 = x1, B010 = x2, B011 = x4, B100 = x8, B101/other = x16

* Pressure Oversampling Rate (posr): uint8_t, default = 0x1
  values: B000 = Skipped, B001 = x1, B010 = x2, B011 = x4, B100 = x8, B101/other = x16

* Mode: uint8_t, default = Normal
  values: Sleep = B00, Forced = B01 and B10, Normal = B11

* Standby Time (st): uint8_t, default = 1000ms
  values: B000 = 0.5ms, B001 = 62.5ms, B010 = 125ms, B011 = 250ms, B100 = 250ms, B101 = 1000ms, B110 = 10ms, B111 = 20ms

* Filter: uint8_t, default = None
  values: B000 = off, B001 = 2, B010 = 4, B011 = 8, B100/other = 16

BME280SpiSw(uint8_t spiCsPin, uint8_t spiMosiPin, uint8_t spiMisoPin, uint8_t spiSckPin, uint8_t tosr = 0x1, uint8_t hosr = 0x1, uint8_t posr = 0x1, uint8_t mode = 0x3, uint8_t st = 0x5, uint8_t filter = 0x0)

Constructor used to create the software Spi Bme class. All parameters have default values. Return: None

* SPI Chip Select Pin (spiCsPin): uint8_t
  values: Any pin 0-31

* SPI Master Out Slave In Pin (spiMosiPin): uint8_t
  values: Any pin 0-31

* SPI Master In Slave Out Pin (spiMisoPin): uint8_t
  values: Any pin 0-31

* SPI Serial Clock Pin (spiSckPin): uint8_t
  values: Any pin 0-31

* Temperature Oversampling Rate (tosr): uint8_t, default = 0x1
  values: B000 = Skipped, B001 = x1, B010 = x2, B011 = x4, B100 = x8, B101/other = x16

* Humidity Oversampling Rate (hosr): uint8_t, default = 0x1
  values: B000 = Skipped, B001 = x1, B010 = x2, B011 = x4, B100 = x8, B101/other = x16

* Pressure Oversampling Rate (posr): uint8_t, default = 0x1
  values: B000 = Skipped, B001 = x1, B010 = x2, B011 = x4, B100 = x8, B101/other = x16

* Mode: uint8_t, default = Normal
  values: Sleep = B00, Forced = B01 and B10, Normal = B11

* Standby Time (st): uint8_t, default = 1000ms
  values: B000 = 0.5ms, B001 = 62.5ms, B010 = 125ms, B011 = 250ms, B100 = 250ms, B101 = 1000ms, B110 = 10ms, B111 = 20ms

* Filter: uint8_t, default = None
  values: B000 = off, B001 = 2, B010 = 4, B011 = 8, B100/other = 16

bool begin()

Method used at start up to initialize the class. Starts the I2C or SPI interface. Return: bool, true = success, false = failure (no device found)

void setMode(uint8_t mode)

Method to set the sensor mode. Sleep = B00, Forced = B01 and B10, Normal = B11. Set to B01 to trigger a new measurement when using forced mode.

float temp(bool celsius = true)

Read the temperature from the BME280 and return a float. Return: float = temperature

* Celsius: bool, default = true
  values: true = return temperature in degrees Celsius, false = return
  temperature in degrees Fahrenheit

float pres(uint8_t unit = 0x0)

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

* Unit: uint8_t, default = 0x0
  values: B000 = Pa, B001 = hPa, B010 = Hg, B011 = atm, B100 = bar,
  B101 = torr, B110 = N/m^2, B111 = psi

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, bool metric = true, uint8_t p_unit = 0x0)

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

* Metric: bool, default = true
  values: true = meters, false = feet

* Pressure Unit: uint8_t, default = 0x0
    values: B000 = Pa, B001 = hPa, B010 = Hg, B011 = atm, B100 = bar,
    B101 = torr, B110 = N/m^2, B111 = psi

float alt(bool metric = true, float seaLevelPressure = 101325)

Read the data from the BME280 with the specified units and then calculate the altitude. Return: float = altitude

* Metric: bool, default = true
  values: true = meters, false = feet

* Sea Level Pressure: float, unit = Pa, default = 101325
  values:  any float

float alt(float pressure, bool metric = true, float seaLevelPressure = 101325)

Calculate the altitude based on the pressure with the specified units. Return: float = altitude

* Pressure: float, unit = Pa
  values: any float

* Metric: bool, default = true
  values: true = meters, false = feet

* Sea Level Pressure: float, unit = Pa, default = 101325
  values:  any float

float dew(bool metric = true)

Read BME280 data and calculate the dew point with the specified units. Return: float = dew point

* Metric: bool, default = true
  values: true = return temperature in degrees Celsius, false = return
  temperature in degrees Fahrenheit

float dew(float temp, float hum, bool metric = true)

Calculate the dew point based on the temperature and humidity with the specified units. Return: float = dew point

* Temperature: float, unit = Celsius if metric is true, Fahrenheit if metric is false
  values: any float

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

* Metric: bool, default = true
  values: true = return degrees Celsius, false = 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

  • Jan 1, 2016 - Version 1.0.0 released.
  • Sep 19, 2016 - Version 2.0.0 released (restructure for I2C and SPI).
  • Dec 19, 2016 - Version 2.1.0 released (support for SPI)
  • Dec 21, 2016 - Version 2.1.1 released (Fixing compilation errors)

Credits

Written by Tyler Glenn, 2016.

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

License

GNU GPL, see License.txt

bme280's People

Contributors

chacal avatar finitespace avatar guruathwal avatar jamesmyatt avatar klagr avatar maru-sama avatar osos avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.