kopia lustrzana https://github.com/robert-hh/BME280
bme280_xxx.py: Add methods for altitude and dew_point
The Documentation is extended accordinglypull/6/head
rodzic
d8d78924a8
commit
5a283cf149
30
README.md
30
README.md
|
@ -5,7 +5,7 @@ for use with MicroPython on Pycom of ESP8266 boards. It is also compatible with
|
||||||
the BMP280 which provides the same interface but temperature + pressure only.
|
the BMP280 which provides the same interface but temperature + pressure only.
|
||||||
|
|
||||||
Two different variants of the library are supplied. bme20_int.py uses integer
|
Two different variants of the library are supplied. bme20_int.py uses integer
|
||||||
arithmetic. bme280_float.py uses float arithmetic for the compensation of the
|
arithmetic, bme280_float.py uses float arithmetic for the compensation of the
|
||||||
raw values. The results are (almost) the identical, but the format of the
|
raw values. The results are (almost) the identical, but the format of the
|
||||||
returned values differs.
|
returned values differs.
|
||||||
|
|
||||||
|
@ -24,21 +24,37 @@ bme= BME280(i2c=i2c, mode=BME280_OSAMPLE_8, address=BME280_I2CADDR)
|
||||||
mode is the setting for oversampling of the humidity value, address the i2c
|
mode is the setting for oversampling of the humidity value, address the i2c
|
||||||
address used.
|
address used.
|
||||||
|
|
||||||
## Property
|
## Properties
|
||||||
|
|
||||||
### values = BME280.value
|
### values = BME280.values
|
||||||
|
|
||||||
The `values` property is a convenience function that provides a tuple of
|
The `values` property is a convenience function that provides a tuple of
|
||||||
human-readable string values to quickly check that the sensor is working.
|
human-readable string values to quickly check that the sensor is working.
|
||||||
In practice, the method to use is `read_compensated_data()` which returns
|
In practice, the method to use is `read_compensated_data()` which returns
|
||||||
a `(temperature, pressure, humidity)`-tuple
|
a `(temperature, pressure, humidity)`-tuple
|
||||||
|
|
||||||
|
### altitude = bmp.altitude
|
||||||
|
Altitude in m. The altitude is calculated based on the value given to
|
||||||
|
the property sealevel (see below). Obviously, this value does not have to be the
|
||||||
|
sealevel pressure, but any pressure you may select, for instance to measure
|
||||||
|
altitude difference in general.
|
||||||
|
|
||||||
|
### bmp.sealevel = sealevel
|
||||||
|
### sealevel = bmp.sealevel
|
||||||
|
Setting and getting the pressure for altitude calculation.
|
||||||
|
The default is 101325 Pa, but you can use your local
|
||||||
|
QNH in Pa, or set a local pressure to determine altitude difference.
|
||||||
|
|
||||||
|
### dew_point = si7021.dew_point
|
||||||
|
Returns the dew_point temperature (°C) calculated from the actual temperature and humidity.
|
||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
|
||||||
### values = read_compensated_data(result = None)
|
### values = read_compensated_data(result = None)
|
||||||
|
|
||||||
Values is an array of either integers of floats, holding the values of temperature,
|
Values is an array of either integers (bme280_int.py) of floats (bme280_float.py),
|
||||||
pressure and humidity. The format differs for integers and floats:
|
holding the values of temperature, pressure and humidity.
|
||||||
|
The format differs for integers and floats:
|
||||||
|
|
||||||
#### Integer formats:
|
#### Integer formats:
|
||||||
* `temperature`: the temperature in hundredths of a degree Celsius. For example,
|
* `temperature`: the temperature in hundredths of a degree Celsius. For example,
|
||||||
|
@ -76,10 +92,10 @@ Copy `bme280.py` onto the board. Then:
|
||||||
# On pycom devuces that is P9 = SDA, P10 = scl
|
# On pycom devuces that is P9 = SDA, P10 = scl
|
||||||
#
|
#
|
||||||
import machine
|
import machine
|
||||||
import bme280
|
import bme280_float
|
||||||
|
|
||||||
i2c = machine.I2C()
|
i2c = machine.I2C()
|
||||||
bme = bme280.BME280(i2c=i2c)
|
bme = bme280_float.BME280(i2c=i2c)
|
||||||
|
|
||||||
print(bme.values)
|
print(bme.values)
|
||||||
```
|
```
|
||||||
|
|
|
@ -69,6 +69,7 @@ class BME280:
|
||||||
if i2c is None:
|
if i2c is None:
|
||||||
raise ValueError('An I2C object is required.')
|
raise ValueError('An I2C object is required.')
|
||||||
self.i2c = i2c
|
self.i2c = i2c
|
||||||
|
self.__sealevel = 101325
|
||||||
|
|
||||||
# load calibration data
|
# load calibration data
|
||||||
dig_88_a1 = self.i2c.readfrom_mem(self.address, 0x88, 26)
|
dig_88_a1 = self.i2c.readfrom_mem(self.address, 0x88, 26)
|
||||||
|
@ -186,6 +187,39 @@ class BME280:
|
||||||
|
|
||||||
return array("f", (temp, pressure, humidity))
|
return array("f", (temp, pressure, humidity))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def sealevel(self):
|
||||||
|
return self.__sealevel
|
||||||
|
|
||||||
|
@sealevel.setter
|
||||||
|
def sealevel(self, value):
|
||||||
|
if 30000 < value < 120000: # just ensure some reasonable value
|
||||||
|
self.__sealevel = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def altitude(self):
|
||||||
|
'''
|
||||||
|
Altitude in m.
|
||||||
|
'''
|
||||||
|
from math import pow
|
||||||
|
try:
|
||||||
|
p = 44330 * (1.0 - pow(self.read_compensated_data()[1]
|
||||||
|
/ self.__sealevel, 0.1903))
|
||||||
|
except:
|
||||||
|
p = 0.0
|
||||||
|
return p
|
||||||
|
|
||||||
|
@property
|
||||||
|
def dew_point(self):
|
||||||
|
"""
|
||||||
|
Compute the dew point temperature for the current Temperature
|
||||||
|
and Humidity measured pair
|
||||||
|
"""
|
||||||
|
from math import log
|
||||||
|
t, p, h = self.read_compensated_data()
|
||||||
|
h = (log(h, 10) - 2) / 0.4343 + (17.62 * t) / (243.12 + t)
|
||||||
|
return 243.12 * h / (17.62 - h)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def values(self):
|
def values(self):
|
||||||
""" human readable values """
|
""" human readable values """
|
||||||
|
|
|
@ -69,6 +69,7 @@ class BME280:
|
||||||
if i2c is None:
|
if i2c is None:
|
||||||
raise ValueError('An I2C object is required.')
|
raise ValueError('An I2C object is required.')
|
||||||
self.i2c = i2c
|
self.i2c = i2c
|
||||||
|
self.__sealevel = 101325
|
||||||
|
|
||||||
# load calibration data
|
# load calibration data
|
||||||
dig_88_a1 = self.i2c.readfrom_mem(self.address, 0x88, 26)
|
dig_88_a1 = self.i2c.readfrom_mem(self.address, 0x88, 26)
|
||||||
|
@ -189,6 +190,41 @@ class BME280:
|
||||||
|
|
||||||
return array("i", (temp, pressure, humidity))
|
return array("i", (temp, pressure, humidity))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def sealevel(self):
|
||||||
|
return self.__sealevel
|
||||||
|
|
||||||
|
@sealevel.setter
|
||||||
|
def sealevel(self, value):
|
||||||
|
if 300 < value < 1200: # just ensure some reasonable value
|
||||||
|
self.__sealevel = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def altitude(self):
|
||||||
|
'''
|
||||||
|
Altitude in m.
|
||||||
|
'''
|
||||||
|
from math import pow
|
||||||
|
try:
|
||||||
|
p = 44330 * (1.0 - pow((self.read_compensated_data()[1] / 256)
|
||||||
|
/ self.__sealevel, 0.1903))
|
||||||
|
except:
|
||||||
|
p = 0.0
|
||||||
|
return p
|
||||||
|
|
||||||
|
@property
|
||||||
|
def dew_point(self):
|
||||||
|
"""
|
||||||
|
Compute the dew point temperature for the current Temperature
|
||||||
|
and Humidity measured pair
|
||||||
|
"""
|
||||||
|
from math import log
|
||||||
|
t, p, h = self.read_compensated_data()
|
||||||
|
t /= 100
|
||||||
|
h /= 1024
|
||||||
|
h = (log(h, 10) - 2) / 0.4343 + (17.62 * t) / (243.12 + t)
|
||||||
|
return (243.12 * h / (17.62 - h)) * 100
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def values(self):
|
def values(self):
|
||||||
""" human readable values """
|
""" human readable values """
|
||||||
|
|
Ładowanie…
Reference in New Issue