{"id":14978089,"url":"https://github.com/alejandroherr/async-bmp280","last_synced_at":"2025-10-28T08:31:48.478Z","repository":{"id":33884122,"uuid":"162916606","full_name":"AlejandroHerr/async-bmp280","owner":"AlejandroHerr","description":"Interface for the weather sensor BMP280","archived":false,"fork":false,"pushed_at":"2024-10-04T18:39:22.000Z","size":463,"stargazers_count":0,"open_issues_count":18,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-11T17:20:37.189Z","etag":null,"topics":["bmp280","envirophat","i2c","i2c-sensors","pressure-sensor","raspberry","raspberry-pi","raspberry-pi-3","raspberry-pi-zero","raspberrypi","rpi","rpi-iot","temperature-sensor","weather","weather-sensors"],"latest_commit_sha":null,"homepage":"https://async-bmp280.alejandroherr.io","language":"TypeScript","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/AlejandroHerr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-12-23T18:58:29.000Z","updated_at":"2020-10-25T17:54:11.000Z","dependencies_parsed_at":"2023-01-15T03:15:54.518Z","dependency_job_id":"60c2650b-81e7-4c36-b18b-f384d327824e","html_url":"https://github.com/AlejandroHerr/async-bmp280","commit_stats":{"total_commits":44,"total_committers":2,"mean_commits":22.0,"dds":0.2954545454545454,"last_synced_commit":"4feddb48f82ac76d97f4c2c5c67d20033c9e32d1"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlejandroHerr%2Fasync-bmp280","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlejandroHerr%2Fasync-bmp280/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlejandroHerr%2Fasync-bmp280/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlejandroHerr%2Fasync-bmp280/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlejandroHerr","download_url":"https://codeload.github.com/AlejandroHerr/async-bmp280/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219859904,"owners_count":16556031,"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":["bmp280","envirophat","i2c","i2c-sensors","pressure-sensor","raspberry","raspberry-pi","raspberry-pi-3","raspberry-pi-zero","raspberrypi","rpi","rpi-iot","temperature-sensor","weather","weather-sensors"],"created_at":"2024-09-24T13:56:50.952Z","updated_at":"2025-10-28T08:31:43.160Z","avatar_url":"https://github.com/AlejandroHerr.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# async-bmp280\n\n[![Npm Package](https://img.shields.io/npm/v/async-bmp280.svg)](https://www.npmjs.com/package/async-bmp280) [![Dependencies](https://img.shields.io/david/AlejandroHerr/async-bmp280.svg?style=flat-square)](https://david-dm.org/alejandroherr/async-bmp280) [![Dev Dependencies](https://img.shields.io/david/dev/AlejandroHerr/async-bmp280.svg?style=flat-square)](https://david-dm.org/alejandroherr/async-bmp280?type=dev) ![CircleCI](https://img.shields.io/circleci/project/github/AlejandroHerr/async-bmp280/master.svg?style=flat-square\u0026logo=circleci) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release) [![MIT License](https://img.shields.io/github/license/AlejandroHerr/async-bmp280.svg?style=flat-square)](https://github.com/AlejandroHerr/async-bmp280/blob/master/LICENSE.md)\n\nJavaScript interface to control the temperature and pressure sensors [BMP280](https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BMP280-DS001.pdf), like the one used in the [Enviro pHat](https://pinout.xyz/pinout/enviro_phat). The `BMP280Interface` extends the `DeviceInterface` of [async-i2c-bus](https://github.com/AlejandroHerr/async-i2c-bus).\n\n## Installation\n\nTo use this library you will also have to install [async-i2c-bus](https://github.com/AlejandroHerr/async-i2c-bus).\n\nYarn:\n\n```bash\nyarn add async-i2c-bus async-i2c-bus\n```\n\nor npm:\n\n```bash\nnpm i -P async-i2c-bus async-i2c-bus\n```\n\nAnd you're ready to go.\n\n### Requirements\n\nThe package requires node `v8.10.x` or higher.\nIf you need a compatibility with lower versions of node, you can build it. To do so clone the repo in your workspace, and modify the `target` options in the `tsconfig.json`, e.g:\n\n```js\n{\n  \"compilerOptions\": {\n    \"target\": \"es5\", // \u003c-- Line changed\n    \"outDir\": \"dist/main\",\n    \"rootDir\": \"src\",\n    // ..\n  }\n}\n```\n\nAnd build the module with `yarn build` or `npm run build`.\n\n## Usage\n\nThe [`BMP280` factory](https://async-bmp280.alejandroherr.io/globals.html#bmp280) takes as argument an instance of the [`BusInterface`](https://alejandroherr.github.io/async-i2c-bus/interfaces/businterface.html) and returns an instance of the [`BMP280Interface`](https://async-bmp280.alejandroherr.io/interfaces/bmp280interface.html).\n\n```javascript\nfunction BMP280({ bus }: { bus: BusInterface }): BMP280Interface;\n```\n\nThe `BMP280Interfaces` inherits from [`DeviceInterface`](https://alejandroherr.github.io/async-i2c-bus/interfaces/deviceinterface.html), hence all the low level methods such as `writeByte`, `readByte`,... are available to work with the device.\n\nBut it also offers some specific methods to work with the sensor.\n\n### `init` and configuration\n\nThe `init` method performs a reset of the device, acquires temperature/pressure correction and configures the device with the values selected (if none present, it will use the default ones):\n\n```javascript\ninit(params?: Partial\u003cBMP280ControlMeasurement \u0026 BMP280Config\u003e): Promise\u003cBMP280Interface\u003e;\n```\n\nThe interfaces in the params are:\n\n```javascript\ninterface BMP280ControlMeasurement {\n  temperatureOversampling: BMP280Oversampling;\n  pressureOversampling: BMP280Oversampling;\n  mode: BMP280Mode;\n}\ninterface BMP280Config {\n  standbyTime: BMP280StandbyTime;\n  iirFilter: BMP280IirFilter;\n}\n\n// Types:\ntype BMP280Oversampling = 'x0' | 'x1' | 'x2' | 'x4' | 'x8' | 'x16';\ntype BMP280Mode = 'SLEEP' | 'FORCED' | 'NORMAL';\ntype BMP280StandbyTime = '500us' | '62ms' | '125ms' | '250ms' | '500ms' | '1s' | '2s' | '4s';\ntype BMP280IirFilter = 'x0' | 'x1' | 'x2' | 'x4' | 'x8' | 'x16';\n```\n\n**This is the recommended way of initializing the sensor.**\n\nIf you don't use it, be sure to call `readTemperatureCorrection` and `readPressureCorrection` to be able to read the right temperature/pressure values.\n\nExample of `init` vs no `init`\n\n```javascript\nimport { Bus } from 'async-i2c-bus';\nimport { BMP280, REGISTERS, OFFSETS, OVERSAMPLING, MODE, STANDBY_TIME, IIR_FILTER } from 'async-i2c-bus';\n\n// ...\n\nconst bus = Bus();\nawait bus.open();\n\nconst bmp280 = BMP280({ bus });\n\n// init version\nawait bmp280.init();\n\n// no-init version;\n\nawait bmp280.reset();\nawait bmp280.readTemperatureCorrection();\nawait bmp280.readPressureCorrection();\n\nawait bmp280.writeByte(\n  REGISTERS.CTRL_MEAS,\n  (OVERSAMPLING.x1 \u003c\u003c OFFSETS.OSRS_T) | (OVERSAMPLING.x1 \u003c\u003c OFFSETS.OSRS_P) | MODE.NORMAL,\n);\nawait bmp280.writeByte(REGISTERS.CONFIG, (STANDBY_TIME['500us'] \u003c\u003c OFFSETS.T_SB) | (IIR_FILTER.x16 \u003c\u003c OFFSETS.FILTER));\n```\n\nAfter this step, the device is ready to `readTemperature` and to `readPressure`.\n\nFor more details, check the full auto-generated [documentation](https://async-bmp280.alejandroherr.io/) and get familiar with [BMP280 datasheet](https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BMP280-DS001.pdf).\n\n### Read/write `config` and `ctrl_meas`\n\nThe module exports\nThere's two handy methods to read/write the registers `config` and `ctrl_meas`.\n\n#### `write`\n\n```javascript\nwriteControlMeasurement(controlMeasurement: Partial\u003cBMP280ControlMeasurement\u003e): Promise\u003cBMP280Interface\u003e\nwriteConfig(controlMeasurement: Partial\u003cBMP280Config\u003e): Promise\u003cBMP280Interface\u003e\n```\n\nBoth functions will apply the values passed in the argument and apply them on the current value. That means that it is possible to change only one value or more in the register and leave the rest untouched.\n\n```javascript\nawait bmp280.writeConfig({ iirFilter: 'x16' });\n\n// it is equivalent as:\n\nconst currentValue = await bmp280.readByte(REGISTERS.config);\nconst nextValue = (currentValue ^ (MASKS.FILTER \u003c\u003c OFFSETS.FILTER)) | (IIR_FILTER.x16 \u003c\u003c OFFSETS.FILTER);\nawait bmp280.writeByte(REGISTERS.CONFIG, nextValue);\n```\n\n#### `read`\n\nRead is the inverse function of the previous two functions:\n\n```javascript\nreadControlMeasurement(): Promise\u003cBMP280ControlMeasurement\u003e\nreadConfig(): Promise\u003cBMP280Config\u003e\n```\n\nExample:\n\n```javascript\nawait bmp280.writeConfig({ iirFilter: 'x16', standbyTime: '4s' });\nawait bmp280.readConfig(); // Returns { iirFilter: 'x16', standbyTime: '4s' }\n```\n\n### `readTemperature` and `readPressure`\n\n```javascript\nreadTemperature(): Promise\u003cnumber\u003e\nreadPressure(): Promise\u003cnumber\u003e\n```\n\nRead temperature returns the celsius degrees.\nRead pressure returns the pressure in Pascals.\n\n### Constants\n\nIn case that you want or need to work with lower level method, the module exposes several constants to work with:\n\n- [`REGISTERS`](https://async-bmp280.alejandroherr.io/globals.html#registers)\n- [`MASKS`](https://async-bmp280.alejandroherr.io/globals.html#masks)\n- [`OFFSETS`](https://async-bmp280.alejandroherr.io/globals.html#offsets)\n- [`OVERSAMPLING`](https://async-bmp280.alejandroherr.io/globals.html#oversampling)\n- [`MODE`](https://async-bmp280.alejandroherr.io/globals.html#mode)\n- [`STANDBY_TIME`](https://async-bmp280.alejandroherr.io/globals.html#standby_time)\n- [`IIR_FILTER`](https://async-bmp280.alejandroherr.io/globals.html#iir_filter)\n\nExample:\n\n```javascript\n// ...\nawait bmp280.writeByte(\n  REGISTERS.CTRL_MEAS,\n  (OVERSAMPLING.x1 \u003c\u003c OFFSETS.OSRS_T) | (OVERSAMPLING.x1 \u003c\u003c OFFSETS.OSRS_P) | MODE.NORMAL,\n);\n\nconst ctrlMeas = await bmp280.readByte(REGISTERS.CTRL_MEAS);\nconst temperatureOversampling = (ctrlMeas \u0026 MASKS.OSRS_T) \u003e\u003e\u003e OFFSETS.OSRS_T;\n```\n\n### Full example of `NORMAL` (mode) usage\n\n```javascript\nimport { Bus } from 'async-i2c-bus';\nimport { BMP280 } from 'async-i2c-bus';\n\nconst main = async () =\u003e {\n  const busNumber = 1;\n  const bus = Bus({ busNumber });\n\n  await bus.open();\n\n  const bmp280 = BMP280({ bus });\n\n  await bmp280.init();\n\n  let temperature = 0;\n  let pressure = 0;\n\n  /** Read temperature/pressure every second */\n  while (1) {\n    [temperature, pressure] = await Promise.all([bmp280.readTemperature(), bmp280.readPressure()]);\n\n    console.log(`Temperature: ${temperature}°C`);\n    console.log(`Pressure: ${pressure}Pa`);\n\n    await new Promise(resolve =\u003e {\n      setTimeout(() =\u003e {\n        resolve();\n      }, 1000);\n    });\n  }\n};\n```\n\n### Example of `FORCED` (mode) usage\n\n```javascript\nimport { Bus } from 'async-i2c-bus';\nimport { BMP280, IIR_FILTER, MODE, OVERSAMPLING } from 'async-i2c-bus';\n\nconst main = async () =\u003e {\n  const busNumber = 1;\n  const bus = Bus({ busNumber });\n\n  await bus.open();\n\n  const bmp280 = BMP280({ bus });\n\n  // Use your values\n  await bmp280.init({\n    temperatureOversampling: OVERSAMPLING.x16,\n    pressureOversampling: OVERSAMPLING.x16,\n    mode: MODE.FORCED,\n    iirFilter: IIR_FILTER.x0,\n  });\n\n  /** Read temperature/pressure once */\n  const [temperature, pressure] = await Promise.all([bmp280.readTemperature(), bmp280.readPressure()]);\n\n  console.log(`Temperature: ${temperature}°C`);\n  console.log(`Pressure: ${pressure}Pa`);\n};\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falejandroherr%2Fasync-bmp280","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falejandroherr%2Fasync-bmp280","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falejandroherr%2Fasync-bmp280/lists"}