{"id":16526188,"url":"https://github.com/alejandroherr/async-i2c-bus","last_synced_at":"2025-03-15T11:33:22.733Z","repository":{"id":33834929,"uuid":"161072106","full_name":"AlejandroHerr/async-i2c-bus","owner":"AlejandroHerr","description":"Bus and Device classes for i2c-bus, with promised functions.","archived":false,"fork":false,"pushed_at":"2025-03-10T18:26:33.000Z","size":1197,"stargazers_count":3,"open_issues_count":40,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-10T19:36:49.190Z","etag":null,"topics":["i2c","i2c-bus","i2c-device","i2c-display","i2c-interface","i2c-protocol","i2c-sensors","i2c-slave","raspberry-pi","raspberrypi"],"latest_commit_sha":null,"homepage":"https://async-i2c-bus.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-09T19:08:48.000Z","updated_at":"2020-10-25T18:46:03.000Z","dependencies_parsed_at":"2024-03-11T21:32:53.413Z","dependency_job_id":"418a7bfc-38b6-4d99-8f1f-693bd4cd5955","html_url":"https://github.com/AlejandroHerr/async-i2c-bus","commit_stats":{"total_commits":151,"total_committers":3,"mean_commits":"50.333333333333336","dds":0.6158940397350994,"last_synced_commit":"2a990accdc542e7a835586a1f6a333bf0bbe7b61"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlejandroHerr%2Fasync-i2c-bus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlejandroHerr%2Fasync-i2c-bus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlejandroHerr%2Fasync-i2c-bus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlejandroHerr%2Fasync-i2c-bus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlejandroHerr","download_url":"https://codeload.github.com/AlejandroHerr/async-i2c-bus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243725077,"owners_count":20337660,"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":["i2c","i2c-bus","i2c-device","i2c-display","i2c-interface","i2c-protocol","i2c-sensors","i2c-slave","raspberry-pi","raspberrypi"],"created_at":"2024-10-11T17:26:26.506Z","updated_at":"2025-03-15T11:33:22.243Z","avatar_url":"https://github.com/AlejandroHerr.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003easync-i2c-bus\u003c/h1\u003e\n\u003cp align=\"center\"\u003e\n\t\t\u003ca href=\"https://npmcharts.com/compare/async-i2c-bus?minimal=true\"\u003e\u003cimg alt=\"Downloads per month\" src=\"https://img.shields.io/npm/dm/async-i2c-bus.svg\" height=\"20\"/\u003e\u003c/a\u003e\r\n\u003ca href=\"https://www.npmjs.com/package/async-i2c-bus\"\u003e\u003cimg alt=\"NPM Version\" src=\"https://img.shields.io/npm/v/async-i2c-bus.svg\" height=\"20\"/\u003e\u003c/a\u003e\r\n\u003ca href=\"https://david-dm.org/AlejandroHerr/async-i2c-bus\"\u003e\u003cimg alt=\"Dependencies\" src=\"https://img.shields.io/david/AlejandroHerr/async-i2c-bus.svg\" height=\"20\"/\u003e\u003c/a\u003e\r\n\u003ca href=\"https://github.com/AlejandroHerr/async-i2c-bus/graphs/contributors\"\u003e\u003cimg alt=\"Contributors\" src=\"https://img.shields.io/github/contributors/AlejandroHerr/async-i2c-bus.svg\" height=\"20\"/\u003e\u003c/a\u003e\r\n\u003ca href=\"https://circleci.com/gh/AlejandroHerr/async-i2c-bus\"\u003e\u003cimg alt=\"CircleCI\" src=\"https://img.shields.io/circleci/project/github/AlejandroHerr/async-i2c-bus/master.svg?style=flat-square\u0026logo=circleci\" height=\"20\"/\u003e\u003c/a\u003e\r\n\u003ca href=\"https://codecov.io/gh/AlejandroHerr/async-i2c-bus\"\u003e\u003cimg alt=\"codecov\" src=\"https://codecov.io/gh/AlejandroHerr/async-i2c-bus/branch/master/graph/badge.svg\" height=\"20\"/\u003e\u003c/a\u003e\r\n\u003ca href=\"http://commitizen.github.io/cz-cli/\"\u003e\u003cimg alt=\"Commitizen friendly\" src=\"https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=flat-square\" height=\"20\"/\u003e\u003c/a\u003e\r\n\u003ca href=\"https://github.com/semantic-release/semantic-release\"\u003e\u003cimg alt=\"semantic-release\" src=\"https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square\" height=\"20\"/\u003e\u003c/a\u003e\n\t\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cb\u003eBus and Device classes for i2c-bus, with promised functions.\u003c/b\u003e\u003c/br\u003e\n  \u003csub\u003e\u003csub\u003e\n\u003c/p\u003e\n\n\u003cbr /\u003e\n\nBus and Device classes for [i2c-bus](https://www.npmjs.com/package/i2c-bus), with promised functions.\n\n**You probably don't need this library anymore**. The original purpose of the library was to have `async` methods instead of callbacks. Currently `i2c-bus` support promises.\n\n**Besides that** it is still useful for me to have a class for Bus and Device, and an easy way to catch the errors produced in the bus, as well as typexcript typings. And it saves some time not having to write it for every library.\n\n\r\n[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/dark.png)](#table-of-contents)\r\n\r\n## Table of Contents\n\n* [Installation](#installation)\r\n* [Usage](#usage)\r\n\t* [Bus](#bus)\r\n\t* [Device](#device)\r\n\t* [BusError](#buserror)\r\n\t* [Example](#example)\r\n\t* [Example using custom device](#example-using-custom-device)\r\n* [License](#license)\n\r\n[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/dark.png)](#installation)\r\n\r\n## Installation\n\n```javascript\nyarn add async-i2c-bus\n\n// or\n\nnpm i async-i2c-bus\n```\n\n\r\n[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/dark.png)](#usage)\r\n\r\n## Usage\n\nThe package exports the `Bus`, `Device` and `BusError` classes.\n\nYou can check the [full documentation](https://async-i2c-bus.alejandroherr.io/)\n\n### Bus\n\nThe `Bus` wraps the original implementation with a `typescript` class.\n\nTo create a `Bus` use the static method `create` or `createAndOpen` (also opens the `bus`) with the following signatures:\n\n`Bus.create({ busNumber }): Bus`\n\n| Name        | Type   |\n| ----------- | ------ |\n| `busNumber` | number |\n\n**Returns:** Bus\n\n`Bus.createAndOpen({ busNumber }): Promise\u003cBus\u003e`\n\n| Name        | Type   |\n| ----------- | ------ |\n| `busNumber` | number |\n\n**Returns:** Promise‹Bus›\n\n### Device\n\n`Device` inherits all the device-oriented methods from `Bus` and calls them with the device's address.\n\nAlso you can extends / compose it to create your specific device class. Read further for an example of it.\n\nTo create a `Device` use the static method `create` with the following signature:\n\n`Device.create({ busNumber }): Device`\n\n| Name      | Type   |\n| --------- | ------ |\n| `bus`     | bus    |\n| `address` | number |\n\n**Returns:** Device\n\n### BusError\n\nAll the errors thrown by the bus are wrapped into `BusError`, which keeps the message and stack of the original error, but makes it easier to catch bus-specific errors.\n\n### Example\n\n```javascript\nimport { Bus, Device } from 'async-i2c-bus';\n\nconst WEATHER_SENSOR_ADDRESS = 0x77;\n\nconst main = async () =\u003e {\n  const bus = Bus.create();\n\n  await bus.open();\n\n  const devices = await bus.scan();\n\n  console.log(`Connected devices ${devices}`);\n\n  const weatherSensor = Device.create({ address: WEATHER_SENSOR_ADDRESS, bus });\n\n  // Configure Weather Sensor (BMP280)\n  await weatherSensor.writeByte(0xf4, 0b00100101);\n  await weatherSensor.writeByte(0xf5, 0b00100100);\n\n  // Read temperature\n  const temperatureBuffer = Buffer.alloc(3);\n  await weatherSensor.readI2cBlock(0xfa, 3, temperatureBuffer);\n  const temperature = temperatureBuffer.readUIntBE(0, 3) \u003e\u003e\u003e 4;\n\n  console.log(`Temperature: ${temperature}`);\n};\n```\n\n### Example using custom device\n\n```javascript\nimport { Device } from 'async-i2c-bus';\n\nconst WEATHER_SENSOR_ADDRESS = 0x77;\n\nclass WeatherSensor {\n  constructor({ bus }) {\n    this.device = Device.create({ bus, address: WEATHER_SENSOR_ADDRESS });\n  }\n\n  async readTemperature() {\n    const buffer = Buffer.alloc(3);\n\n    await this.bus.readI2cBlock(0xfa, 3, buffer);\n\n    return buffer.readUIntBE(0, 3) \u003e\u003e\u003e 4;\n  }\n}\n```\n\n\r\n[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/dark.png)](#license)\r\n\r\n## License\n\t\nLicensed under [MIT](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falejandroherr%2Fasync-i2c-bus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falejandroherr%2Fasync-i2c-bus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falejandroherr%2Fasync-i2c-bus/lists"}