bme280
— Atmospheric multi-sensor
The BME280 and BMP280 sensors provide a range of atmospheric measurements, being:
atmospheric temperature
atmospheric pressure
relative humidity (not the BMP280)
The data-sheet for the sensor can be found here. Various vendors offer BME280 break-out boards for use with microcomputers such as the Kookaberry.
Class BME280
The BME280 class in this module provides the principal functionality.
Example usage:
from machine import SoftI2C, Pin
from bme280 import BME280
import time
i2c = SoftI2C(scl=Pin('P3A'), sda=Pin('P3B')) # set up the I2C interface
sensor = BME280(i2c=i2c) # set up a BME280 sensor using the I2C bus
while True: # loop runs forever
temperature = sensor.values[0] # obtain the sensor readings
pressure = sensor.values[1]
humidity = sensor.values[2]
# add code to do something with the readings, e.g.
print(temperature, "C ", pressure, "hPa ", humidity, "%")
# Then sleep for 1 second to allow the BME280 to take the next reading
time.sleep(2)
BME280 Constructors
- class bme280.BME280(i2c=i2c, mode=BME280_OSAMPLE_8, address=BME280_I2CADDR, **kwargs)
Creates a BME280 sensor object.
i2c should be a
machine.SoftI2C
object.mode is the setting for oversampling of the humidity value, and has the default value shown if omitted. The valid operating modes (see the sensor data-sheet) are:
BME280_OSAMPLE_1 = 1
BME280_OSAMPLE_2 = 2
BME280_OSAMPLE_4 = 3
BME280_OSAMPLE_8 = 4 (default)
BME280_OSAMPLE_16 = 5
address is the I2C address of the bme280 sensor, which is usually hexadecimal 0x77 (which is 119 decimal).
BME280 Properties
The module presents the sensor readings as properties.
- property sensor.values
Returns a tuplet (temperature, pressure, humidity) where:
temperature: is the temperature in degrees Celsius.
pressure: is the atmospheric pressure in hectoPascals.
humidity: is the relative humidity in percent.
- property sensor.altitude
The altitude is in metres and is calculated based on the value given to the property bme.sealevel (see below). The value for sea-level pressure does not have to be the actual sea-level pressure, but any pressure you may select, for instance to measure altitude difference in general.
Sea level may be both read and set:
sensor.sealevel = sealevel
sealevel = sensor.sealevel
The default sea-level pressure is 1013.25 hPa, but you can use your local published pressure in hPa (look up QNH on your meteorological website), or set a local pressure to determine altitude difference. See also https://en.wikipedia.org/wiki/Altimeter_setting
- property sensor.dew_point
Provides the dew_point temperature (°C) calculated from the actual temperature and humidity. See also https://en.wikipedia.org/wiki/Dew_point
- property sensor.sensor
Provides a sensor type as a string variable being one of (‘BMP280’,’BME280’,’BME680’, or ‘unknown’) depending on the sensor id in the relevant sensor hardware register.