{"id":13802421,"url":"https://github.com/triplepoint/micropython_bme280_i2c","last_synced_at":"2026-03-05T21:38:27.977Z","repository":{"id":147824445,"uuid":"142641765","full_name":"triplepoint/micropython_bme280_i2c","owner":"triplepoint","description":"A Micropython module for communicating with the Bosch BME280 temperature, humidity, and pressure sensor.","archived":false,"fork":false,"pushed_at":"2018-09-06T01:23:30.000Z","size":16,"stargazers_count":10,"open_issues_count":0,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-22T12:35:58.208Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/triplepoint.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-07-28T02:57:57.000Z","updated_at":"2023-04-21T06:06:58.000Z","dependencies_parsed_at":"2023-05-27T15:15:25.962Z","dependency_job_id":null,"html_url":"https://github.com/triplepoint/micropython_bme280_i2c","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/triplepoint%2Fmicropython_bme280_i2c","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/triplepoint%2Fmicropython_bme280_i2c/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/triplepoint%2Fmicropython_bme280_i2c/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/triplepoint%2Fmicropython_bme280_i2c/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/triplepoint","download_url":"https://codeload.github.com/triplepoint/micropython_bme280_i2c/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225218052,"owners_count":17439713,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T00:01:44.151Z","updated_at":"2026-03-05T21:38:27.945Z","avatar_url":"https://github.com/triplepoint.png","language":"Python","readme":"# Introduction\nThis Micropython module enables I2C communication with a Bosch BME280 temperature, humidity, and pressure sensor.\n\n# Usage\nThis module pretty closely follows the Bosch reference library's behavior (see the references below).\n\nThe basic operation of the module requires initialization of an `BME280_I2C` instance, followed by sensor configuration, and finally acquiring a measurement.\n\nNote that the BME280 has a couple of different operating modes (FORCED, and NORMAL), as well as several oversampling and filtering options, and it's a good idea to understand these specifics in order to get the most out of the part.  See the data sheet, specifically section `3. Functional description` to get an understanding of how this sensor works.\n\nAlso, in the examples below, the I2C address is supplied as `bme280_i2c.BME280_I2C_ADDR_SEC` (`0x77`).  Be aware that `bme280_i2c.BME280_I2C_ADDR_PRIM` (`0x76`) is also available.\n\n## Available Methods\n### `get_measurement_settings()`\nReturns a dict with the sensor's currently-configured settings for the filter coefficient, standby time, and the oversampling settings for each of humidity, pressure, and temperature.  The result would look like:\n``` python\nsensor.get_measurement_settings()\n\n{\n    'filter': 0,\n    'standby_time': 0,\n    'osr_h': 1,\n    'osr_p': 1,\n    'osr_t': 1\n}\n```\nWhere the values are constants that represent the values of the various settings.  See the various `BME280_OVERSAMPLING_*`, `BME280_STANDBY_TIME_*`, and `BME280_FILTER_COEFF_*` defines at the top of `bme280_i2c.py` and listed below.\n\n### `set_measurement_settings(settings: dict)`\nSets the sensor configuration with a dict similar to the one returned by `get_measurement_settings()` above.  Note that all the keys are optional, and leaving one out will retain the currently-set value.\n\n### `get_power_mode()`\nReturns the currently set sensor power mode, where the value is one of the `BME280_*_MODE` constants.  \n\n### `set_power_mode(mode: int)`\nSet the sensor power mode, where the value is one of the `BME280_*_MODE` constants.  \n\nBe sure to read section 3.3.1 of the data sheet, and understand that setting the power mode to FORCED will immediately return the sensor to the SLEEP mode, after taking a single sample.\n\n### `get_measurement()`\nAcquire and return a dict of the sensor's values, like:\n``` python\nsensor.get_measurement()\n\n{\n    'temperature': 27.86,\n    'pressure': 101412.0,\n    'humidity': 39.5\n}\n```\nWhere the values are in Degrees Celsius, Pascals, and % Relative Humidity, respectively.\n\n## Configuration Constants\n``` python\n# BME280 default address\nBME280_I2C_ADDR_PRIM         : 0x76\nBME280_I2C_ADDR_SEC          : 0x77\n\n# Sensor Power Mode Options\nBME280_SLEEP_MODE            : 0x00\nBME280_FORCED_MODE           : 0x01\nBME280_NORMAL_MODE           : 0x03\n\n# Oversampling Options\nBME280_NO_OVERSAMPLING       : 0x00\nBME280_OVERSAMPLING_1X       : 0x01\nBME280_OVERSAMPLING_2X       : 0x02\nBME280_OVERSAMPLING_4X       : 0x03\nBME280_OVERSAMPLING_8X       : 0x04\nBME280_OVERSAMPLING_16X      : 0x05\n\n# Standby Duration Options\nBME280_STANDBY_TIME_500_US   : 0x00  # Note this is microseconds, so 0.5 ms\nBME280_STANDBY_TIME_62_5_MS  : 0x01\nBME280_STANDBY_TIME_125_MS   : 0x02\nBME280_STANDBY_TIME_250_MS   : 0x03\nBME280_STANDBY_TIME_500_MS   : 0x04\nBME280_STANDBY_TIME_1000_MS  : 0x05\nBME280_STANDBY_TIME_10_MS    : 0x06\nBME280_STANDBY_TIME_20_MS    : 0x07\n\n# Filter Coefficient Options\nBME280_FILTER_COEFF_OFF      : 0x00\nBME280_FILTER_COEFF_2        : 0x01\nBME280_FILTER_COEFF_4        : 0x02\nBME280_FILTER_COEFF_8        : 0x03\nBME280_FILTER_COEFF_16       : 0x04\n```\n\n## \"Normal\" Power Mode Example\nOnce enabled, Normal mode samples automatically at a given rate for as long as the sensor has power.  This mode makes sense for high sample-rate applications.\n\nThis example implements the advised settings from the data sheet section `3.5.3 Indoor navigation`:\n\n``` python\nimport machine\nimport bme280_i2c\nimport time\n\n# Create a micropython I2C object with the appropriate device pins\ni2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4))\n\n# Create a sensor object to represent the BME280\n# Note that this will error if the device can't be reached over I2C.\nsensor = bme280_i2c.BME280_I2C(address=bme280_i2c.BME280_I2C_ADDR_SEC, i2c=i2c)\n\n# Configure the sensor for the application in question.\nsensor.set_measurement_settings({\n    'filter': bme280_i2c.BME280_FILTER_COEFF_16,\n    'standby_time': bme280_i2c.BME280_STANDBY_TIME_500_US,\n    'osr_h': bme280_i2c.BME280_OVERSAMPLING_1X,\n    'osr_p': bme280_i2c.BME280_OVERSAMPLING_16X,\n    'osr_t': bme280_i2c.BME280_OVERSAMPLING_2X})\n\n# Start the sensor automatically sensing\nsensor.set_power_mode(bme280_i2c.BME280_NORMAL_MODE)\n\n# Wait for the measurement settle time, print the measurement, and repeat\nwhile 1:\n    time.sleep_ms(70)\n    print( sensor.get_measurement() )\n\n# The above code repeatedly prints a line like:\n# {'pressure': 101412.0, 'humidity': 39.5, 'temperature': 27.86}\n```\n\n## \"Forced\" Power Mode Example\nOnce enabled, forced mode takes a single measurement and then returns the sensor to sleep mode.  Acquiring a new sample requires another set to forced mode.  This mode is convenient to conserve power for low sample rate applications.\n\nThis example implements the advised settings from the data sheet section `3.5.1 Weather monitoring`:\n\n``` python\nimport machine\nimport bme280_i2c\nimport time\n\ni2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4))\n\nsensor = bme280_i2c.BME280_I2C(address=bme280_i2c.BME280_I2C_ADDR_SEC, i2c=i2c)\n\nsensor.set_measurement_settings({\n    'filter': bme280_i2c.BME280_FILTER_COEFF_OFF,\n    'osr_h': bme280_i2c.BME280_OVERSAMPLING_1X,\n    'osr_p': bme280_i2c.BME280_OVERSAMPLING_1X,\n    'osr_t': bme280_i2c.BME280_OVERSAMPLING_1X})\n\nwhile 1:\n    sensor.set_power_mode(bme280_i2c.BME280_FORCED_MODE)\n    time.sleep_ms(40)\n    print( sensor.get_measurement() )\n\n# {'pressure': 101412.0, 'humidity': 39.5, 'temperature': 27.86}\n```\n\n## A Note About Measurement Duration\nIn the above examples there are sleep commands issued prior to each measurement to pause a given number of milliseconds before acquiring a new sample.  These pauses are defined by the data sheet in section `9. Appendix B: Measurement time and current calculation`.  \n\nYou should read the whole thing to properly understand the determination of delays before sampling, but the basic idea is that the measurement itself has a typical and maximum amount of time to complete, depending on the 3 different oversampling configuration values.\n\nIn addition, the Normal power mode has an additional standby time which you can configure, and which adds to the measurement duration.\n\nSee the data sheet for the details.  Note that the weird factor of 1000 in their calculations is just to deal with the milliseconds vs seconds conversion.\n\n# Reference Material\n- [Bosch BME280 Product Information](https://www.bosch-sensortec.com/bst/products/all_products/bme280)\n- [Bosch BME280 Datasheet](https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BME280_DS001-12.pdf)\n- [Bosch Sensortec Reference Driver (in C)](https://github.com/BoschSensortec/BME280_driver)\n","funding_links":[],"categories":["Libraries"],"sub_categories":["Sensors"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftriplepoint%2Fmicropython_bme280_i2c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftriplepoint%2Fmicropython_bme280_i2c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftriplepoint%2Fmicropython_bme280_i2c/lists"}