|
@@ -5,7 +5,7 @@
|
|
|
|
|
|
This module provides a simple interface to [BME280/BMP280 temperature/air presssure/humidity sensors](http://www.bosch-sensortec.com/bst/products/all_products/bme280) (Bosch Sensortec).
|
|
|
|
|
|
-Note that you must call [`init()`](#bme280init) before you can start reading values!
|
|
|
+Note that you must call [`setup()`](#bme280setup) before you can start reading values!
|
|
|
|
|
|
## bme280.altitude()
|
|
|
|
|
@@ -69,13 +69,72 @@ none
|
|
|
|
|
|
Initializes module. Initialization is mandatory before read values.
|
|
|
|
|
|
+!!! attention
|
|
|
+
|
|
|
+ This function is deprecated and will be removed in upcoming releases. Use `bme280.setup()` instead.
|
|
|
+
|
|
|
#### Syntax
|
|
|
|
|
|
`bme280.init(sda, scl, [temp_oss, press_oss, humi_oss, power_mode, inactive_duration, IIR_filter])`
|
|
|
|
|
|
#### Parameters
|
|
|
-- `sda` - SDA pin
|
|
|
-- `scl` - SCL pin
|
|
|
+See [`setup()`](#bme280setup).
|
|
|
+
|
|
|
+## bme280.qfe2qnh()
|
|
|
+
|
|
|
+For given altitude converts the air pressure to sea level air pressure.
|
|
|
+
|
|
|
+#### Syntax
|
|
|
+`bme280.qfe2qnh(P, altitude)`
|
|
|
+
|
|
|
+#### Parameters
|
|
|
+- `P` measured pressure
|
|
|
+- `altitude` altitude in meters of measurement point
|
|
|
+
|
|
|
+#### Returns
|
|
|
+sea level pressure
|
|
|
+
|
|
|
+
|
|
|
+## bme280.read()
|
|
|
+
|
|
|
+Reads the sensor and returns the temperature, the air pressure, the air relative humidity and
|
|
|
+
|
|
|
+#### Syntax
|
|
|
+`bme280.read([altitude])`
|
|
|
+
|
|
|
+#### Parameters
|
|
|
+- (optional) `altitude`- altitude in meters of measurement point. If provided also the air pressure converted to sea level air pressure is returned.
|
|
|
+
|
|
|
+#### Returns
|
|
|
+- `T` temperature in celsius as an integer multiplied with 100
|
|
|
+- `P` air pressure in hectopascals multiplied by 1000
|
|
|
+- `H` relative humidity in percent multiplied by 1000
|
|
|
+- `QNH` air pressure in hectopascals multiplied by 1000 converted to sea level
|
|
|
+
|
|
|
+Any of these variables is `nil` if the readout of given measure was not successful.
|
|
|
+
|
|
|
+## bme280.startreadout()
|
|
|
+Starts readout (turns the sensor into forced mode). After the readout the sensor turns to sleep mode.
|
|
|
+
|
|
|
+#### Syntax
|
|
|
+`bme280.startreadout(delay, callback)`
|
|
|
+
|
|
|
+#### Parameters
|
|
|
+- `delay` sets sensor to forced mode and calls the `callback` (if provided) after given number of milliseconds. For 0 the default delay is set to 113ms (sufficient time to perform reading for oversampling settings 16x). For different oversampling setting please refer to [BME280 Final Datasheet - Appendix B: Measurement time and current calculation](http://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BME280_DS001-11.pdf#page=51).
|
|
|
+- `callback` if provided it will be invoked after given `delay`. The sensor reading should be finalized by then so.
|
|
|
+
|
|
|
+#### Returns
|
|
|
+`nil`
|
|
|
+
|
|
|
+## bme280.setup()
|
|
|
+
|
|
|
+Initializes module. Initialization is mandatory before read values.
|
|
|
+
|
|
|
+#### Syntax
|
|
|
+
|
|
|
+`bme280.setup([temp_oss, press_oss, humi_oss, power_mode, inactive_duration, IIR_filter])`
|
|
|
+
|
|
|
+#### Parameters
|
|
|
- (optional) `temp_oss` - Controls oversampling of temperature data. Default oversampling is 16x.
|
|
|
- (optional) `press_oss` - Controls oversampling of pressure data. Default oversampling is 16x.
|
|
|
- (optional) `humi_oss` - Controls oversampling of humidity data. Default oversampling is 16x
|
|
@@ -127,7 +186,9 @@ Using forced mode is recommended for applications which require low sampling rat
|
|
|
```lua
|
|
|
alt=320 -- altitude of the measurement place
|
|
|
|
|
|
-bme280.init(3, 4)
|
|
|
+sda, scl = 3, 4
|
|
|
+i2c.setup(0, sda, scl, i2c.SLOW) -- call i2c.setup() only once
|
|
|
+bme280.setup()
|
|
|
|
|
|
P, T = bme280.baro()
|
|
|
print(string.format("QFE=%d.%03d", P/1000, P%1000))
|
|
@@ -157,7 +218,9 @@ Or simpler and more efficient
|
|
|
```lua
|
|
|
alt=320 -- altitude of the measurement place
|
|
|
|
|
|
-bme280.init(3, 4)
|
|
|
+sda, scl = 3, 4
|
|
|
+i2c.setup(0, sda, scl, i2c.SLOW) -- call i2c.setup() only once
|
|
|
+bme280.setup()
|
|
|
|
|
|
T, P, H, QNH = bme280.read(alt)
|
|
|
local Tsgn = (T < 0 and -1 or 1); T = Tsgn*T
|
|
@@ -176,11 +239,13 @@ local curAltsgn = (curAlt < 0 and -1 or 1); curAlt = curAltsgn*curAlt
|
|
|
print(string.format("altitude=%s%d.%02d", curAltsgn<0 and "-" or "", curAlt/100, curAlt%100))
|
|
|
```
|
|
|
|
|
|
-Use `bme280.init(sda, scl, 1, 3, 0, 3, 0, 4)` for "game mode" - Oversampling settings pressure ×4, temperature ×1, humidity ×0, sensor mode: normal mode, inactive duration = 0.5 ms, IIR filter settings filter coefficient 16.
|
|
|
+Use `bme280.setup(1, 3, 0, 3, 0, 4)` for "game mode" - Oversampling settings pressure ×4, temperature ×1, humidity ×0, sensor mode: normal mode, inactive duration = 0.5 ms, IIR filter settings filter coefficient 16.
|
|
|
|
|
|
Example of readout in forced mode (asynchronous)
|
|
|
```lua
|
|
|
-bme280.init(3, 4, nil, nil, nil, 0) -- initialize to sleep mode
|
|
|
+sda, scl = 3, 4
|
|
|
+i2c.setup(0, sda, scl, i2c.SLOW) -- call i2c.setup() only once
|
|
|
+bme280.setup(nil, nil, nil, 0) -- initialize to sleep mode
|
|
|
bme280.startreadout(0, function ()
|
|
|
T, P = bme280.read()
|
|
|
local Tsgn = (T < 0 and -1 or 1); T = Tsgn*T
|
|
@@ -188,52 +253,6 @@ bme280.startreadout(0, function ()
|
|
|
end)
|
|
|
```
|
|
|
|
|
|
-## bme280.qfe2qnh()
|
|
|
-
|
|
|
-For given altitude converts the air pressure to sea level air pressure.
|
|
|
-
|
|
|
-#### Syntax
|
|
|
-`bme280.qfe2qnh(P, altitude)`
|
|
|
-
|
|
|
-#### Parameters
|
|
|
-- `P` measured pressure
|
|
|
-- `altitude` altitude in meters of measurement point
|
|
|
-
|
|
|
-#### Returns
|
|
|
-sea level pressure
|
|
|
-
|
|
|
-
|
|
|
-## bme280.read()
|
|
|
-
|
|
|
-Reads the sensor and returns the temperature, the air pressure, the air relative humidity and
|
|
|
-
|
|
|
-#### Syntax
|
|
|
-`bme280.read([altitude])`
|
|
|
-
|
|
|
-#### Parameters
|
|
|
-- (optional) `altitude`- altitude in meters of measurement point. If provided also the air pressure converted to sea level air pressure is returned.
|
|
|
-
|
|
|
-#### Returns
|
|
|
-- `T` temperature in celsius as an integer multiplied with 100
|
|
|
-- `P` air pressure in hectopascals multiplied by 1000
|
|
|
-- `H` relative humidity in percent multiplied by 1000
|
|
|
-- `QNH` air pressure in hectopascals multiplied by 1000 converted to sea level
|
|
|
-
|
|
|
-Any of these variables is `nil` if the readout of given measure was not successful.
|
|
|
-
|
|
|
-## bme280.startreadout()
|
|
|
-Starts readout (turns the sensor into forced mode). After the readout the sensor turns to sleep mode.
|
|
|
-
|
|
|
-#### Syntax
|
|
|
-`bme280.startreadout(delay, callback)`
|
|
|
-
|
|
|
-#### Parameters
|
|
|
-- `delay` sets sensor to forced mode and calls the `callback` (if provided) after given number of milliseconds. For 0 the default delay is set to 113ms (sufficient time to perform reading for oversampling settings 16x). For different oversampling setting please refer to [BME280 Final Datasheet - Appendix B: Measurement time and current calculation](http://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BME280_DS001-11.pdf#page=51).
|
|
|
-- `callback` if provided it will be invoked after given `delay`. The sensor reading should be finalized by then so.
|
|
|
-
|
|
|
-#### Returns
|
|
|
-`nil`
|
|
|
-
|
|
|
## bme280.temp()
|
|
|
|
|
|
Reads the sensor and returns the temperature in celsius as an integer multiplied with 100.
|