import bme280
The bme280 module reads Bosch BME280 environmental sensors over I2C. It is meant for weather stations, room monitors, pressure/altitude checks, and general environment sensing from MojoScale Studio scripts.
Quick example
import bme280 room = bme280.BME280(sda=21, scl=22, address=0x76) outside = bme280.BME280(sda=21, scl=22, address=0x77) reading = room.read() print(reading["c"]) print(reading["humidity"]) print(reading["pressure_hpa"]) outside.configure(osrs_t=1, osrs_p=1, osrs_h=1, mode="forced")
importbme280
BME280 temperature, humidity, and pressure module.
The bme280 module reads Bosch BME280 environmental sensors over I2C. It is meant for weather stations, room monitors, pressure/altitude checks, and general environment sensing from MojoScale Studio scripts.
bme280.BME280(sda: int, scl: int, address: int = None, frequency: int = None, port: int = None) -> bme280_sensor
bme280.BME280(sda: int, scl: int, address: int = None, frequency: int = None, port: int = None) -> bme280_sensorCreate and initialize an independent BME280 environmental sensor.
Use one BME280 object for each physical sensor. Multiple sensors can share one I2C bus when each board has a different address, normally 0x76 or 0x77.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
sda |
int |
positional or keyword | Yes | GPIO pin used for I2C SDA. |
scl |
int |
positional or keyword | Yes | GPIO pin used for I2C SCL. |
address |
int |
positional or keyword | No | Optional I2C address. Use 0x76 or 0x77. Defaults to 0x76. |
frequency |
int |
positional or keyword | No | Optional I2C bus speed in hertz. Defaults to 100000. |
port |
int |
positional or keyword | No | Optional ESP-IDF I2C port number. Defaults to 0. |
bme280_sensor bme280_sensor object.
bme280.BME280().configure(osrs_t=None, osrs_p=None, osrs_h=None, filter=None, standby_ms=None, mode=None) -> bool
bme280.BME280().configure(osrs_t=None, osrs_p=None, osrs_h=None, filter=None, standby_ms=None, mode=None) -> boolConfigure oversampling, IIR filter, standby time, and operating mode for this sensor.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
osrs_t |
int |
positional or keyword | No | Optional value. Defaults to None. |
osrs_p |
int |
positional or keyword | No | Optional value. Defaults to None. |
osrs_h |
int |
positional or keyword | No | Optional value. Defaults to None. |
filter |
int |
positional or keyword | No | Optional value. Defaults to None. |
standby_ms |
int |
positional or keyword | No | Optional value. Defaults to None. |
mode |
str |
positional or keyword | No | Optional value. Defaults to None. |
bme280.BME280().read() -> dict
bme280.BME280().read() -> dictRead temperature, humidity, and pressure from this sensor.
bme280.BME280().temperature() -> float
bme280.BME280().temperature() -> floatRead temperature in degrees Celsius.
bme280.BME280().humidity() -> float
bme280.BME280().humidity() -> floatRead relative humidity percentage.
bme280.BME280().pressure() -> float
bme280.BME280().pressure() -> floatRead barometric pressure in hPa.
bme280.BME280().altitude(sea_level_hpa=None) -> float
bme280.BME280().altitude(sea_level_hpa=None) -> floatEstimate altitude in meters using an optional sea-level pressure.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
sea_level_hpa |
float |
positional or keyword | No | Optional value. Defaults to None. |
bme280.BME280().reset() -> bool
bme280.BME280().reset() -> boolSoft-reset this sensor and reload calibration.
bme280.BME280().id() -> int
bme280.BME280().id() -> intRead this sensor's chip id register.
bme280.BME280().info() -> dict
bme280.BME280().info() -> dictReturn I2C settings, sampling settings, and mode for this sensor.
bme280.BME280().close() -> bool
bme280.BME280().close() -> boolRelease this BME280 handle.
bme280.BME280().Example
bme280.BME280().Examplesensor = bme280.BME280(sda=21, scl=22, address=0x76) print(sensor.read())
bme280.begin(sda: int, scl: int, address: int = None, frequency: int = None, port: int = None) -> bool
bme280.begin(sda: int, scl: int, address: int = None, frequency: int = None, port: int = None) -> boolLegacy: initialize the module-level default BME280 sensor.
Prefer ``sensor = bme280.BME280(...)`` for new projects. The legacy wrapper keeps older singleton-style scripts working.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
sda |
int |
positional or keyword | Yes | GPIO pin used for I2C SDA. |
scl |
int |
positional or keyword | Yes | GPIO pin used for I2C SCL. |
address |
int |
positional or keyword | No | Optional I2C address. Use 0x76 or 0x77. Defaults to 0x76. |
frequency |
int |
positional or keyword | No | Optional I2C bus speed in hertz. Defaults to 100000. |
port |
int |
positional or keyword | No | Optional ESP-IDF I2C port number. Defaults to 0. |
bool True when a BME280 with chip id 0x60 is detected and configured.
bme280.configure(osrs_t: int = None, osrs_p: int = None, osrs_h: int = None, filter: int = None, standby_ms: int = None, mode: str = None) -> bool
bme280.configure(osrs_t: int = None, osrs_p: int = None, osrs_h: int = None, filter: int = None, standby_ms: int = None, mode: str = None) -> boolConfigure BME280 sampling behavior.
Oversampling values are multipliers: 0 disables a channel, then 1, 2, 4, 8, or 16 select x1 through x16 oversampling. The default mode is forced, which makes each read trigger one fresh measurement.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
osrs_t |
int |
positional or keyword | No | Optional temperature oversampling multiplier. Defaults to 1. |
osrs_p |
int |
positional or keyword | No | Optional pressure oversampling multiplier. Defaults to 1. |
osrs_h |
int |
positional or keyword | No | Optional humidity oversampling multiplier. Defaults to 1. |
filter |
int |
positional or keyword | No | Optional IIR filter coefficient. Use 0, 2, 4, 8, or 16. |
standby_ms |
int |
positional or keyword | No | Optional standby time for normal mode in milliseconds. |
mode |
str |
positional or keyword | No | Optional operating mode. Use "forced", "normal", or "sleep". |
bool True when the configuration was written.
bme280.read() -> dict
bme280.read() -> dictRead temperature, humidity, and pressure.
In forced mode this starts one measurement, waits for completion, and then returns compensated values.
dict Dict with ``ok``, ``c``, ``f``, ``temperature``, ``humidity``, ``pressure_pa``, ``pressure_hpa``, raw ADC values, and ``address``.
bme280.temperature() -> float
bme280.temperature() -> floatRead temperature in Celsius.
float Float temperature in degrees Celsius.
bme280.humidity() -> float
bme280.humidity() -> floatRead relative humidity.
float Float relative humidity percentage.
bme280.pressure() -> float
bme280.pressure() -> floatRead barometric pressure.
float Float pressure in hPa.
bme280.altitude(sea_level_hpa: float = None) -> float
bme280.altitude(sea_level_hpa: float = None) -> floatEstimate altitude from pressure.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
sea_level_hpa |
float |
positional or keyword | No | Optional sea-level pressure in hPa. Defaults to 1013.25. |
float Float estimated altitude in meters.
bme280.reset() -> bool
bme280.reset() -> boolSoft-reset the BME280 and reload calibration.
bool True when reset and calibration reload succeed.
bme280.id() -> int
bme280.id() -> intRead the BME280 chip id register.
int Integer chip id. A BME280 reports 0x60.
bme280.info() -> dict
bme280.info() -> dictReturn BME280 module state.
dict Dict with initialization state, I2C pins, address, sampling settings, and mode.