|
| 1 | +# BME280 |
| 2 | +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. |
| 3 | + |
| 4 | +## Table of Contents |
| 5 | + |
| 6 | +1. [BME280](#bme280) |
| 7 | +2. [Table of Contents](#table-of-contents) |
| 8 | +3. [Summary](#summary) |
| 9 | +4. [Installation](#installation) |
| 10 | +5. [Usage](#usage) |
| 11 | +6. [Enumerations](#enumerations) |
| 12 | +7. [Settings](#settings) |
| 13 | + - [BME280I2C::Settings](#settings) |
| 14 | + - [BME280Spi::Settings](#settings) |
| 15 | + - [BME280SpiSw::Settings](#settings) |
| 16 | +8. [Methods](#methods) |
| 17 | + - [BME280I2C(const BME280I2C::Settings& settings)](#methods) |
| 18 | + - [BME280Spi(const BME280Spi::Settings& settings)](#methods) |
| 19 | + - [BME280SpiSw(const BME280SpiSw::Settings& settings)](#methods) |
| 20 | + - [bool begin()](#methods) |
| 21 | + - [void setSettings(const Settings& settings)](#methods) |
| 22 | + - [const Settings& getSettings() const](#methods) |
| 23 | + - [float temp(TempUnit unit)](#methods) |
| 24 | + - [float pres(PresUnit unit)](#methods) |
| 25 | + - [float hum()](#methods) |
| 26 | + - [void read(float& pressure, float& temp, float& humidity, TempUnit tempUnit, PresUnit presUnit)](#methods) |
| 27 | + - [ChipModel chipModel()](#methods) |
| 28 | + |
| 29 | +9. [Environment Calculations](#environment-calculations) |
| 30 | + - [float Altitude(float pressure, bool metric = true, float seaLevelPressure = 101325)](#environment-calculations) |
| 31 | + - [float EquivalentSeaLevelPressure(float altitude, float temp, float pres)](#environment-calculations) |
| 32 | + - [float DewPoint(float temp, float hum, bool metric = true)](#environment-calculations) |
| 33 | +10. [Contributing](#contributing) |
| 34 | +11. [History](#history) |
| 35 | +12. [Credits](#credits) |
| 36 | +13. [License](#license) |
| 37 | +<snippet> |
| 38 | +<content> |
| 39 | + |
| 40 | +## Summary |
| 41 | + |
| 42 | +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. |
| 43 | + |
| 44 | +## Installation |
| 45 | + |
| 46 | +To use this library download the zip file, uncompress it to a folder named BME280. Move the folder to {Arduino Path}/libraries. |
| 47 | + |
| 48 | +## Usage |
| 49 | + |
| 50 | +Include the library at the top of your Arduino script. `#include <BME280>` |
| 51 | +Create a global or local variable. `BME280 bme` |
| 52 | +In your start up call `bme.begin()`. |
| 53 | +Read the temperature, humidity, pressure, altitude and/or dew point. |
| 54 | + |
| 55 | +`float pres, temp, hum` |
| 56 | +`bme.read(pres, temp, hum)` |
| 57 | + |
| 58 | +or |
| 59 | + |
| 60 | +`temp = bme.temp()` |
| 61 | +`hum = bme.hum()` |
| 62 | +`pres = bme.pres()` |
| 63 | + |
| 64 | +## Enumerations |
| 65 | +#### TempUnit Enum |
| 66 | + * TempUnit_Celsius |
| 67 | + * TempUnit_Fahrenheit |
| 68 | + |
| 69 | +#### PresUnit Enum |
| 70 | + * PresUnit_Pa |
| 71 | + * PresUnit_hPa |
| 72 | + * PresUnit_inHg |
| 73 | + * PresUnit_atm |
| 74 | + * PresUnit_bar |
| 75 | + * PresUnit_torr |
| 76 | + * PresUnit_psi |
| 77 | + |
| 78 | +#### OSR Enum |
| 79 | + * OSR_X1 |
| 80 | + * OSR_X2 |
| 81 | + * OSR_X4 |
| 82 | + * OSR_X8 |
| 83 | + * OSR_X16 |
| 84 | + |
| 85 | +#### Mode Enum |
| 86 | + * Mode_Sleep |
| 87 | + * Mode_Forced |
| 88 | + * Mode_Normal |
| 89 | + |
| 90 | +#### StandbyTime Enum |
| 91 | + * StandbyTime_500us |
| 92 | + * StandbyTime_62500us |
| 93 | + * StandbyTime_125ms |
| 94 | + * StandbyTime_250ms |
| 95 | + * StandbyTime_50ms |
| 96 | + * StandbyTime_1000ms |
| 97 | + * StandbyTime_10ms |
| 98 | + * StandbyTime_20ms |
| 99 | + |
| 100 | +#### Filter Enum |
| 101 | + * Filter_Off |
| 102 | + * Filter_1 |
| 103 | + * Filter_2 |
| 104 | + * Filter_4 |
| 105 | + * Filter_8 |
| 106 | + * Filter_16 |
| 107 | + |
| 108 | +#### ChipModel Enum |
| 109 | + * ChipModel_Unknown |
| 110 | + * ChipModel_BME280 |
| 111 | + * ChipModel_BMP280 |
| 112 | + |
| 113 | +## Settings |
| 114 | + |
| 115 | +#### BME280::Settings Struct |
| 116 | +``` |
| 117 | + * Temperature Oversampling Rate (tempOSR): OSR Enum, default = OSR_X1 |
| 118 | +
|
| 119 | + * Humidity Oversampling Rate (humOSR): OSR Enum, default = OSR_X1 |
| 120 | +
|
| 121 | + * Pressure Oversampling Rate (presOSR): OSR Enum, default = OSR_X1 |
| 122 | +
|
| 123 | + * Mode (mode): Mode Enum, default = Mode_Forced |
| 124 | +
|
| 125 | + * Standby Time (standbyTime): StandbyTime Enum, default = StandbyTime_1000ms |
| 126 | +
|
| 127 | + * Filter (filter): Filter Enum, default = Filter_Off |
| 128 | +
|
| 129 | + * SPI Enable: SpiEnable Enum, default = false |
| 130 | + values: true = enable, false = disable |
| 131 | +``` |
| 132 | + |
| 133 | +#### BME280I2C::Settings Struct |
| 134 | + |
| 135 | + * Includes all fields in BME280 settings. |
| 136 | +``` |
| 137 | + * BME 280 Address (bme280Addr): uint8_t, default = 0x76 |
| 138 | +``` |
| 139 | +#### BME280Spi::Settings Struct |
| 140 | + |
| 141 | + * Includes all fields in BME280 settings. |
| 142 | +``` |
| 143 | + * SPI Chip Select Pin (spiCsPin): uint8_t |
| 144 | + values: Any pin 0-31 |
| 145 | +``` |
| 146 | + |
| 147 | +#### BME280Spi::Settings Struct |
| 148 | + * Includes all fields in BME280 settings. |
| 149 | +``` |
| 150 | + * SPI Chip Select Pin (spiCsPin): uint8_t |
| 151 | + values: Any pin 0-31 |
| 152 | +
|
| 153 | + * SPI Master Out Slave In Pin (spiMosiPin): uint8_t |
| 154 | + values: Any pin 0-31 |
| 155 | +
|
| 156 | + * SPI Master In Slave Out Pin (spiMisoPin): uint8_t |
| 157 | + values: Any pin 0-31 |
| 158 | +
|
| 159 | + * SPI Serial Clock Pin (spiSckPin): uint8_t |
| 160 | + values: Any pin 0-31 |
| 161 | +``` |
| 162 | +## Methods |
| 163 | + |
| 164 | + |
| 165 | +#### BME280I2C(const BME280I2C::Settings& settings) |
| 166 | + |
| 167 | + Constructor used to create the I2C Bme class. All parameters have default values. |
| 168 | + |
| 169 | +#### BME280Spi(const BME280Spi::Settings& settings) |
| 170 | + |
| 171 | + Constructor used to create the Spi Bme class. All parameters have default values except chip select. |
| 172 | + |
| 173 | +#### BME280SpiSw(const BME280SpiSw::Settings& settings) |
| 174 | + |
| 175 | + Constructor used to create the software Spi Bme class. All parameters have default values except chip select, mosi, miso and sck. |
| 176 | + |
| 177 | +#### bool begin() |
| 178 | + |
| 179 | + 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. |
| 180 | + ``` |
| 181 | + * return: bool, true = success, false = failure (no device found) |
| 182 | + ``` |
| 183 | + |
| 184 | +#### void setSettings(const Settings& settings) |
| 185 | + |
| 186 | + Method to set the sensor settings. |
| 187 | + |
| 188 | + |
| 189 | +#### const Settings& getSettings() const |
| 190 | + |
| 191 | + Method to get the sensor settings. |
| 192 | + |
| 193 | +#### float temp(TempUnit unit) |
| 194 | + |
| 195 | + Read the temperature from the BME280 and return a float. |
| 196 | +``` |
| 197 | + return: float = temperature |
| 198 | +
|
| 199 | + * unit: tempUnit, default = TempUnit_Celsius |
| 200 | +``` |
| 201 | + |
| 202 | +#### float pres(PresUnit unit) |
| 203 | + |
| 204 | + Read the pressure from the BME280 and return a float with the specified unit. |
| 205 | +``` |
| 206 | + return: float = pressure |
| 207 | +
|
| 208 | + * unit: uint8_t, default = PresUnit_Pa |
| 209 | +``` |
| 210 | + |
| 211 | +#### float hum() |
| 212 | + |
| 213 | + Read the humidity from the BME280 and return a percentage as a float. |
| 214 | +``` |
| 215 | + * return: float = percent relative humidity |
| 216 | +``` |
| 217 | +#### void read(float& pressure, float& temp, float& humidity, TempUnit tempUnit, PresUnit presUnit) |
| 218 | + |
| 219 | + Read the data from the BME280 with the specified units. |
| 220 | +``` |
| 221 | + return: None, however, pressure, temp and humidity are changed. |
| 222 | +
|
| 223 | + * Pressure: float, reference |
| 224 | + values: reference to storage float for pressure |
| 225 | +
|
| 226 | + * Temperature: float, reference |
| 227 | + values: reference to storage float for temperature |
| 228 | +
|
| 229 | + * Humidity: float, reference |
| 230 | + values: reference to storage float for humidity |
| 231 | +
|
| 232 | + * tempUnit: tempUnit, default = TempUnit_Celsius |
| 233 | +
|
| 234 | + * presUnit: uint8_t, default = PresUnit_Pa |
| 235 | +``` |
| 236 | + |
| 237 | +#### ChipModel chipModel() |
| 238 | +``` |
| 239 | + * return: [ChipModel](#chipmodel-enum) enum |
| 240 | +``` |
| 241 | + |
| 242 | +## Environment Calculations |
| 243 | + |
| 244 | +#### float Altitude(float pressure, bool metric = true, float seaLevelPressure = 101325) |
| 245 | + |
| 246 | + Calculate the altitude based on the pressure with the specified units. |
| 247 | + Return: float = altitude |
| 248 | +``` |
| 249 | + * Pressure: float, unit = Pa |
| 250 | + values: any float |
| 251 | +
|
| 252 | + * Metric: bool, default = true |
| 253 | + values: true = meters, false = feet |
| 254 | +
|
| 255 | + * Sea Level Pressure: float, unit = Pa, default = 101325 |
| 256 | + values: any float |
| 257 | +``` |
| 258 | + |
| 259 | +#### float EquivalentSeaLevelPressure(float altitude, float temp, float pres) |
| 260 | + |
| 261 | + Convert current pressure to equivalent sea-level pressure. |
| 262 | + |
| 263 | +``` |
| 264 | + return: The equivalent pressure at sea level. |
| 265 | +
|
| 266 | + * altitude: float |
| 267 | + values: meters |
| 268 | +
|
| 269 | + * temp: float |
| 270 | + values: celsius |
| 271 | +
|
| 272 | + * pres: float |
| 273 | + values: unit independent |
| 274 | +``` |
| 275 | + |
| 276 | +#### float DewPoint(float temp, float hum, bool metric = true) |
| 277 | + |
| 278 | + Calculate the dew point based on the temperature and humidity with the specified units. |
| 279 | +``` |
| 280 | + return: float = dew point |
| 281 | +
|
| 282 | + * Temperature: float, unit = Celsius if metric is true, Fahrenheit if metric is false |
| 283 | + values: any float |
| 284 | +
|
| 285 | + * Humidity: float, unit = % relative humidity |
| 286 | + values: any float |
| 287 | +
|
| 288 | + * Metric: bool, default = true |
| 289 | + values: true = return degrees Celsius, false = return degrees Fahrenheit |
| 290 | +``` |
| 291 | + |
| 292 | + |
| 293 | +## Contributing |
| 294 | + |
| 295 | +1. Fork the project. |
| 296 | +2. Create your feature branch: `git checkout -b my-new-feature` |
| 297 | +3. Commit your changes: `git commit -am 'Add some feature'` |
| 298 | +4. Push to the branch: `git push origin my-new-feature` |
| 299 | +5. Submit a pull request. |
| 300 | + |
| 301 | +## History |
| 302 | + |
| 303 | +- Jan 1, 2016 - Version 1.0.0 released |
| 304 | +- Sep 19, 2016 - Version 2.0.0 released (Restructure for I2C and SPI) |
| 305 | +- Nov 21, 2016 - Version 2.0.1 released (Set mode support) |
| 306 | +- Dec 19, 2016 - Version 2.1.0 released (Support for SPI) |
| 307 | +- Dec 21, 2016 - Version 2.1.1 released (Bugs) |
| 308 | +- Feb 17, 2017 - Version 2.1.2 released (Docs) |
| 309 | +- Sept 9, 2017 - Version 2.1.3 released (Formatting, reorg) |
| 310 | +- Sept 13, 2017 - Version 2.1.4 released (Examples update, bug fixes) |
| 311 | +- Oct 7, 2017 - Version 2.2.0 released (Enums, begin restructure) |
| 312 | +- Oct 10, 2017 - Version 2.2.1 released (Bug fixes) |
| 313 | +- Nov 21, 2017 - Version 2.3.0 released (Examples updates, env calc fixes, bugs) |
| 314 | + |
| 315 | +## Credits |
| 316 | + |
| 317 | +Written by Tyler Glenn, 2016. |
| 318 | + |
| 319 | +Special thanks to Mike Glenn for editing and reviewing the code. |
| 320 | + |
| 321 | +## License |
| 322 | + |
| 323 | +GNU GPL, see License.txt |
| 324 | +</content> |
| 325 | +</snippet> |
0 commit comments