{"id":13454259,"url":"https://github.com/fivdi/i2c-bus","last_synced_at":"2025-04-12T14:57:43.838Z","repository":{"id":24390122,"uuid":"27790087","full_name":"fivdi/i2c-bus","owner":"fivdi","description":"I2C serial bus access with Node.js","archived":false,"fork":false,"pushed_at":"2024-03-21T11:46:23.000Z","size":1685,"stargazers_count":350,"open_issues_count":9,"forks_count":57,"subscribers_count":27,"default_branch":"master","last_synced_at":"2025-04-12T14:57:39.809Z","etag":null,"topics":["beaglebone","beaglebone-black","i2c","iot","javascript","nodejs","raspberry-pi","smbus"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/fivdi.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-12-09T22:18:35.000Z","updated_at":"2024-12-31T12:20:26.000Z","dependencies_parsed_at":"2024-01-11T20:42:57.381Z","dependency_job_id":"5a4ed14d-4f43-4505-80fd-1d87b75a38d1","html_url":"https://github.com/fivdi/i2c-bus","commit_stats":{"total_commits":257,"total_committers":6,"mean_commits":"42.833333333333336","dds":0.5136186770428015,"last_synced_commit":"80fc07fc2f60dbc157ea1a062f6c90bf4548d8b6"},"previous_names":[],"tags_count":50,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fivdi%2Fi2c-bus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fivdi%2Fi2c-bus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fivdi%2Fi2c-bus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fivdi%2Fi2c-bus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fivdi","download_url":"https://codeload.github.com/fivdi/i2c-bus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248586249,"owners_count":21128997,"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":["beaglebone","beaglebone-black","i2c","iot","javascript","nodejs","raspberry-pi","smbus"],"created_at":"2024-07-31T08:00:52.329Z","updated_at":"2025-04-12T14:57:43.817Z","avatar_url":"https://github.com/fivdi.png","language":"JavaScript","funding_links":[],"categories":["Packages","JavaScript","Repository","包","目录","Hardware"],"sub_categories":["Hardware","硬件"],"readme":"[![Build Status](https://app.travis-ci.com/fivdi/i2c-bus.svg?branch=master)](https://app.travis-ci.com/github/fivdi/i2c-bus)\n[![Coverage Status](https://coveralls.io/repos/github/fivdi/i2c-bus/badge.svg)](https://coveralls.io/github/fivdi/i2c-bus)\n[![npm Version](http://img.shields.io/npm/v/i2c-bus.svg)](https://www.npmjs.com/package/i2c-bus)\n[![Downloads Per Month](http://img.shields.io/npm/dm/i2c-bus.svg)](https://www.npmjs.com/package/i2c-bus)\n[![Mentioned in Awesome Node.js](https://awesome.re/mentioned-badge.svg)](https://github.com/sindresorhus/awesome-nodejs#hardware)\n\n# i2c-bus\n\nI2C serial bus access with **Node.js** on Linux boards like the Raspberry Pi\nor BeagleBone. The i2c-bus API supports promises and async/await, asynchronous\ncallbacks and synchronous execution.\n\ni2c-bus supports Node.js versions 10, 12, 14, 16, 18 and 20.\n\n## Contents\n\n * [Installation](#installation)\n * [Usage](#usage)\n * [API](#api)\n * [TypeScript Type Definitions](#typescript-type-definitions)\n\n\n## Installation\n\n```\nnpm install i2c-bus\n```\n\nThe way in which I2C is configured varies from board to board. Sometimes no\nconfiguraton is required, but sometimes it is:\n\n* [Configuring I2C on the Raspberry Pi](doc/raspberry-pi-i2c.md)\n* [Configuring Software I2C on the Raspberry Pi](doc/raspberry-pi-software-i2c.md)\n  * Consider software I2C when there are issues communicating with a device on a Raspberry Pi\n\n## Usage\n\nThe example programs below show how to use a\n[MCP9808 I2C temperature sensor](https://www.adafruit.com/product/1782)\nto determine the temperature.\n\n**MCP9808 I2C temperature sensor connected to a Raspberry Pi**\n![](example/mcp9808-pi.png)\n\n### Example 1 - Promises\n\nDetermine the temperature with a MCP9808 I2C temperature sensor using\npromises.\n\n```js\nconst i2c = require('i2c-bus');\n\nconst MCP9808_ADDR = 0x18;\nconst TEMP_REG = 0x05;\n\nconst toCelsius = rawData =\u003e {\n  rawData = (rawData \u003e\u003e 8) + ((rawData \u0026 0xff) \u003c\u003c 8);\n  let celsius = (rawData \u0026 0x0fff) / 16;\n  if (rawData \u0026 0x1000) {\n    celsius -= 256;\n  }\n  return celsius;\n};\n\ni2c.openPromisified(1).\nthen(i2c1 =\u003e i2c1.readWord(MCP9808_ADDR, TEMP_REG).\n  then(rawData =\u003e console.log(toCelsius(rawData))).\n  then(_ =\u003e i2c1.close())\n).catch(console.log);\n```\n\n### Example 2 - Promises, Plain I2C and Buffers\n\nDetermine the temperature with a MCP9808 I2C temperature sensor using\npromises, plain I2C and Buffer objects.\n\n```js\nconst i2c = require('i2c-bus');\n\nconst MCP9808_ADDR = 0x18;\nconst TEMP_REG = 0x05;\n\nconst toCelsius = rawData =\u003e {\n  let celsius = (rawData \u0026 0x0fff) / 16;\n  if (rawData \u0026 0x1000) {\n    celsius -= 256;\n  }\n  return celsius;\n};\n\nconst wbuf = Buffer.from([TEMP_REG]);\nconst rbuf = Buffer.alloc(2);\n\ni2c.openPromisified(1).\nthen(i2c1 =\u003e i2c1.i2cWrite(MCP9808_ADDR, wbuf.length, wbuf).\n  then(_ =\u003e i2c1.i2cRead(MCP9808_ADDR, rbuf.length, rbuf)).\n  then(data =\u003e console.log(toCelsius(data.buffer.readUInt16BE()))).\n  then(_ =\u003e i2c1.close())\n).catch(console.log);\n```\n\n### Example 3 - Asynchronous Callbacks\n\nDetermine the temperature with a MCP9808 I2C temperature sensor using\nasynchronous callbacks.\n\n```js\nconst i2c = require('i2c-bus');\n\nconst MCP9808_ADDR = 0x18;\nconst TEMP_REG = 0x05;\n\nconst toCelsius = rawData =\u003e {\n  rawData = (rawData \u003e\u003e 8) + ((rawData \u0026 0xff) \u003c\u003c 8);\n  let celsius = (rawData \u0026 0x0fff) / 16;\n  if (rawData \u0026 0x1000) {\n    celsius -= 256;\n  }\n  return celsius;\n};\n\nconst i2c1 = i2c.open(1, err =\u003e {\n  if (err) throw err;\n\n  i2c1.readWord(MCP9808_ADDR, TEMP_REG, (err, rawData) =\u003e {\n    if (err) throw err;\n\n    console.log(toCelsius(rawData));\n\n    i2c1.close(err =\u003e {\n      if (err) throw err;\n    });\n  });\n});\n```\n\n### Example 4 - Synchronous Methods\n\nDetermine the temperature with a MCP9808 I2C temperature sensor using\nsynchronous methods.\n\n```js\nconst i2c = require('i2c-bus');\n\nconst MCP9808_ADDR = 0x18;\nconst TEMP_REG = 0x05;\n\nconst toCelsius = rawData =\u003e {\n  rawData = (rawData \u003e\u003e 8) + ((rawData \u0026 0xff) \u003c\u003c 8);\n  let celsius = (rawData \u0026 0x0fff) / 16;\n  if (rawData \u0026 0x1000) {\n    celsius -= 256;\n  }\n  return celsius;\n};\n\nconst i2c1 = i2c.openSync(1);\nconst rawData = i2c1.readWordSync(MCP9808_ADDR, TEMP_REG);\nconsole.log(toCelsius(rawData));\ni2c1.closeSync();\n```\n\n## API\n\n * [Functions](#functions)\n * [Class Bus](#class-bus)\n * [Class PromisifiedBus](#class-promisifiedbus)\n * [Class I2cFuncs](#class-i2cfuncs)\n\n### Functions\n\n- [open(busNumber [, options], cb)](#openbusnumber--options-cb)\n- [openSync(busNumber [, options])](#opensyncbusnumber--options)\n- [openPromisified(busNumber [, options])](#openpromisifiedbusnumber--options)\n\n### Class Bus\n\nAll methods in class Bus have asynchronous callback and synchronous forms. For\npromise support see [class PromisifiedBus](#class-promisifiedbus).\n\nThe asynchronous callback form always take a completion callback as its last\nargument. The arguments passed to the completion callback depend on the\nmethod, but the first argument is always reserved for an exception. If the\noperation was completed successfully, then the first argument will be null or\nundefined.\n\nWhen using the synchronous form any exceptions are immediately thrown. You can\nuse try/catch to handle exceptions or allow them to bubble up.\n\n- Free resources\n  - [bus.close(cb)](#busclosecb)\n  - [bus.closeSync()](#busclosesync)\n\n- Information\n  - [bus.i2cFuncs(cb)](#busi2cfuncscb)\n  - [bus.i2cFuncsSync()](#busi2cfuncssync)\n  - [bus.scan([startAddr,] [endAddr,] cb)](#busscanstartaddr-endaddr-cb)\n  - [bus.scanSync([startAddr,] [endAddr])](#busscansyncstartaddr-endaddr)\n  - [bus.deviceId(addr, cb)](#busdeviceidaddr-cb)\n  - [bus.deviceIdSync(addr)](#busdeviceidsyncaddr)\n\n- Plain I2C\n  - [bus.i2cRead(addr, length, buffer, cb)](#busi2creadaddr-length-buffer-cb)\n  - [bus.i2cReadSync(addr, length, buffer)](#busi2creadsyncaddr-length-buffer)\n  - [bus.i2cWrite(addr, length, buffer, cb)](#busi2cwriteaddr-length-buffer-cb)\n  - [bus.i2cWriteSync(addr, length, buffer)](#busi2cwritesyncaddr-length-buffer)\n\n- SMBus\n  - [bus.readByte(addr, cmd, cb)](#busreadbyteaddr-cmd-cb)\n  - [bus.readByteSync(addr, cmd)](#busreadbytesyncaddr-cmd)\n  - [bus.readWord(addr, cmd, cb)](#busreadwordaddr-cmd-cb)\n  - [bus.readWordSync(addr, cmd)](#busreadwordsyncaddr-cmd)\n  - [bus.readI2cBlock(addr, cmd, length, buffer, cb)](#busreadi2cblockaddr-cmd-length-buffer-cb)\n  - [bus.readI2cBlockSync(addr, cmd, length, buffer)](#busreadi2cblocksyncaddr-cmd-length-buffer)\n  - [bus.receiveByte(addr, cb)](#busreceivebyteaddr-cb)\n  - [bus.receiveByteSync(addr)](#busreceivebytesyncaddr)\n  - [bus.sendByte(addr, byte, cb)](#bussendbyteaddr-byte-cb)\n  - [bus.sendByteSync(addr, byte)](#bussendbytesyncaddr-byte)\n  - [bus.writeByte(addr, cmd, byte, cb)](#buswritebyteaddr-cmd-byte-cb)\n  - [bus.writeByteSync(addr, cmd, byte)](#buswritebytesyncaddr-cmd-byte)\n  - [bus.writeWord(addr, cmd, word, cb)](#buswritewordaddr-cmd-word-cb)\n  - [bus.writeWordSync(addr, cmd, word)](#buswritewordsyncaddr-cmd-word)\n  - [bus.writeQuick(addr, bit, cb)](#buswritequickaddr-bit-cb)\n  - [bus.writeQuickSync(addr, bit)](#buswritequicksyncaddr-bit)\n  - [bus.writeI2cBlock(addr, cmd, length, buffer, cb)](#buswritei2cblockaddr-cmd-length-buffer-cb)\n  - [bus.writeI2cBlockSync(addr, cmd, length, buffer)](#buswritei2cblocksyncaddr-cmd-length-buffer)\n\n- Promises\n  - [bus.promisifiedBus()](#buspromisifiedbus)\n\n### Class PromisifiedBus\n\nAll methods in class PromisifiedBus have the asynchronous promise form. For\nasynchronous callback and synchronous forms see [class Bus](#class-bus).\n\n- Free resources\n  - [promisifiedBus.close()](#promisifiedbusclose)\n\n- Information\n  - [promisifiedBus.i2cFuncs()](#promisifiedbusi2cfuncs)\n  - [promisifiedBus.scan([startAddr,] [endAddr])](#promisifiedbusscanstartaddr-endaddr)\n  - [promisifiedBus.deviceId(addr)](#promisifiedbusdeviceidaddr)\n\n- Plain I2C\n  - [promisifiedBus.i2cRead(addr, length, buffer)](#promisifiedbusi2creadaddr-length-buffer)\n  - [promisifiedBus.i2cWrite(addr, length, buffer)](#promisifiedbusi2cwriteaddr-length-buffer)\n\n- SMBus\n  - [promisifiedBus.readByte(addr, cmd)](#promisifiedbusreadbyteaddr-cmd)\n  - [promisifiedBus.readWord(addr, cmd)](#promisifiedbusreadwordaddr-cmd)\n  - [promisifiedBus.readI2cBlock(addr, cmd, length, buffer)](#promisifiedbusreadi2cblockaddr-cmd-length-buffer)\n  - [promisifiedBus.receiveByte(addr)](#promisifiedbusreceivebyteaddr)\n  - [promisifiedBus.sendByte(addr, byte)](#promisifiedbussendbyteaddr-byte)\n  - [promisifiedBus.writeByte(addr, cmd, byte)](#promisifiedbuswritebyteaddr-cmd-byte)\n  - [promisifiedBus.writeWord(addr, cmd, word)](#promisifiedbuswritewordaddr-cmd-word)\n  - [promisifiedBus.writeQuick(addr, bit)](#promisifiedbuswritequickaddr-bit)\n  - [promisifiedBus.writeI2cBlock(addr, cmd, length, buffer)](#promisifiedbuswritei2cblockaddr-cmd-length-buffer)\n\n- Asynchronous callbacks and synchronous execution\n  - [promisifiedBus.bus()](#promisifiedbusbus)\n\n### Class I2cFuncs\n\n- [funcs.i2c](#funcsi2c---boolean)\n- [funcs.tenBitAddr](#funcstenbitaddr---boolean)\n- [funcs.protocolMangling](#funcsprotocolmangling---boolean)\n- [funcs.smbusPec](#funcssmbuspec---boolean)\n- [funcs.smbusBlockProcCall](#funcssmbusblockproccall---boolean)\n- [funcs.smbusQuick](#funcssmbusquick---boolean)\n- [funcs.smbusReceiveByte](#funcssmbusreceivebyte---boolean)\n- [funcs.smbusSendByte](#funcssmbussendbyte---boolean)\n- [funcs.smbusReadByte](#funcssmbusreadbyte---boolean)\n- [funcs.smbusWriteByte](#funcssmbuswritebyte---boolean)\n- [funcs.smbusReadWord](#funcssmbusreadword---boolean)\n- [funcs.smbusWriteWord](#funcssmbuswriteword---boolean)\n- [funcs.smbusProcCall](#funcssmbusproccall---boolean)\n- [funcs.smbusReadBlock](#funcssmbusreadblock---boolean)\n- [funcs.smbusWriteBlock](#funcssmbuswriteblock---boolean)\n- [funcs.smbusReadI2cBlock](#funcssmbusreadi2cblock---boolean)\n- [funcs.smbusWriteI2cBlock](#funcssmbuswritei2cblock---boolean)\n\n### open(busNumber [, options], cb)\n- busNumber - the number of the I2C bus/adapter to open, 0 for /dev/i2c-0, 1 for /dev/i2c-1, ...\n- options - an optional options object\n- cb - completion callback\n\nAsynchronous open. Returns a new Bus object. The callback gets one argument (err).\n\nThe following options are supported:\n- forceAccess - A boolean value specifying whether access to devices on the\nI2C bus should be allowed even if they are already in use by a kernel\ndriver/module. Corresponds to I2C_SLAVE_FORCE on Linux. The valid values for\nforceAccess are true and false. Optional, the default value is false.\n\n### openSync(busNumber [, options])\n- busNumber - the number of the I2C bus/adapter to open, 0 for /dev/i2c-0, 1 for /dev/i2c-1, ...\n- options - an optional options object\n\nSynchronous open. Returns a new Bus object.\n\nThe following options are supported:\n- forceAccess - A boolean value specifying whether access to devices on the\nI2C bus should be allowed even if they are already in use by a kernel\ndriver/module. Corresponds to I2C_SLAVE_FORCE on Linux. The valid values for\nforceAccess are true and false. Optional, the default value is false.\n\n### openPromisified(busNumber [, options])\n- busNumber - the number of the I2C bus/adapter to open, 0 for /dev/i2c-0, 1 for /dev/i2c-1, ...\n- options - an optional options object\n\nAsynchronous open. Returns a Promise that, when resolved, yields a PromisifiedBus object.\n\nThe following options are supported:\n- forceAccess - A boolean value specifying whether access to devices on the\nI2C bus should be allowed even if they are already in use by a kernel\ndriver/module. Corresponds to I2C_SLAVE_FORCE on Linux. The valid values for\nforceAccess are true and false. Optional, the default value is false.\n\n### bus.close(cb)\n- cb - completion callback\n\nAsynchronous close. Frees system resources used by this instance. The callback\ngets one argument (err).\n\n### bus.closeSync()\n\nSynchronous close. Frees system resources used by this instance.\n\n### bus.i2cFuncs(cb)\n- cb - completion callback\n\nDetermine functionality of the bus/adapter asynchronously. The callback gets\ntwo argument (err, funcs). funcs is a frozen\n[I2cFuncs](#class-i2cfuncs)\nobject describing the functionality available.\nSee also [I2C functionality](https://www.kernel.org/doc/Documentation/i2c/functionality).\n\n### bus.i2cFuncsSync()\n\nDetermine functionality of the bus/adapter Synchronously. Returns a frozen\n[I2cFuncs](#class-i2cfuncs)\nobject describing the functionality available.\nSee also [I2C functionality](https://www.kernel.org/doc/Documentation/i2c/functionality).\n\n### bus.scan([startAddr,] [endAddr,] cb)\n- startAddr - an integer specifying the start address of the scan range, optional\n- endAddr - an integer specifying the end addrerss of the scan range, optional\n- cb - completion callback\n\nbus.scan(cb) - scan for I2C devices in address range 0x03 through 0x77 \u003cbr/\u003e\nbus.scan(addr, cb) - scan for an I2C device at address addr \u003cbr/\u003e\nbus.scan(startAddr, endAddr, cb) - scan for I2C devices in address range startAddr through endAddr \u003cbr/\u003e\n\nScans the I2C bus asynchronously for devices. The default address range 0x03\nthrough 0x77 is the same as the default address range used by the `i2cdetect`\ncommand line tool. The callback gets two arguments (err, devices). devices is\nan array of numbers where each number represents the I2C address of a device\nwhich was detected.\n\n### bus.scanSync([startAddr,] [endAddr])\n- startAddr - an integer specifying the start address of the scan range, optional\n- endAddr - an integer specifying the end addrerss of the scan range, optional\n\nbus.scan() - scan for I2C devices in address range 0x03 through 0x77 \u003cbr/\u003e\nbus.scan(addr) - scan for an I2C device at address addr \u003cbr/\u003e\nbus.scan(startAddr, endAddr) - scan for I2C devices in address range startAddr through endAddr \u003cbr/\u003e\n\nScans the I2C bus synchronously for devices. The default address range 0x03\nthrough 0x77 is the same as the default address range used by the `i2cdetect`\ncommand line tool. Returns an array of numbers where each number represents\nthe I2C address of a device which was detected.\n\n### bus.deviceId(addr, cb)\n- addr - I2C device address\n- cb - completion callback\n\nAsynchronous I2C device Id.  The callback gets two arguments (err, id). id is\nan object with the properties `manufacturer`, `product` and if known a human\nreadable `name` for the associated manufacturer. `manufacturer` and `product`\nare numbers, `name` is a string.\n\n### bus.deviceIdSync(addr)\n- addr - I2C device address\n\nSynchronous I2C device Id. Returns an object with the properties \n`manufacturer`, `product` and if known a human readable `name` for the\nassociated manufacturer. `manufacturer` and `product` are numbers, `name` is a\nstring.\n\n### bus.i2cRead(addr, length, buffer, cb)\n- addr - I2C device address\n- length - an integer specifying the number of bytes to read\n- buffer - the [Buffer](https://nodejs.org/dist/latest/docs/api/buffer.html)\ninstance that the data will be written to (must conatin at least length bytes)\n- cb - completion callback\n\nAsynchronous plain I2C read. The callback gets three argument (err, bytesRead, buffer).\nbytesRead is the number of bytes read.\n\n### bus.i2cReadSync(addr, length, buffer)\n- addr - I2C device address\n- length - an integer specifying the number of bytes to read\n- buffer - the [Buffer](https://nodejs.org/dist/latest/docs/api/buffer.html)\ninstance that the data will be written to (must conatin at least length bytes)\n\nSynchronous plain I2C read. Returns the number of bytes read.\n\n### bus.i2cWrite(addr, length, buffer, cb)\n- addr - I2C device address\n- length - an integer specifying the number of bytes to write\n- buffer - the [Buffer](https://nodejs.org/dist/latest/docs/api/buffer.html)\ninstance containing the data to write (must conatin at least length bytes)\n- cb - completion callback\n\nAsynchronous plain I2C write. The callback gets three argument (err, bytesWritten, buffer).\nbytesWritten is the number of bytes written.\n\n### bus.i2cWriteSync(addr, length, buffer)\n- addr - I2C device address\n- length - an integer specifying the number of bytes to write\n- buffer - the [Buffer](https://nodejs.org/dist/latest/docs/api/buffer.html) instance\ncontaining the data to write (must conatin at least length bytes)\n\nSynchronous plain I2C write. Returns the number of bytes written.\n\n### bus.readByte(addr, cmd, cb)\n- addr - I2C device address\n- cmd - command code\n- cb - completion callback\n\nAsynchronous SMBus read byte. The callback gets two arguments (err, byte).\nbyte is an unsigned integer in the range 0 to 255.\n\n### bus.readByteSync(addr, cmd)\n- addr - I2C device address\n- cmd - command code\n\nSynchronous SMBus read byte. Returns the byte read. byte is an unsigned\ninteger in the range 0 to 255.\n\n### bus.readWord(addr, cmd, cb)\n- addr - I2C device address\n- cmd - command code\n- cb - completion callback\n\nAsynchronous SMBus read word. The callback gets two arguments (err, word).\nword is an unsigned integer in the range 0 to 65535.\n\n### bus.readWordSync(addr, cmd)\n- addr - I2C device address\n- cmd - command code\n\nSynchronous SMBus read word. Returns the word read. word is an unsigned\ninteger in the range 0 to 65535.\n\n### bus.readI2cBlock(addr, cmd, length, buffer, cb)\n- addr - I2C device address\n- cmd - command code\n- length - an integer specifying the number of bytes to read (max 32)\n- buffer - the [Buffer](https://nodejs.org/dist/latest/docs/api/buffer.html)\ninstance that the data will be written to (must conatin at least length bytes)\n- cb - completion callback\n\nAsynchronous I2C block read (not defined by the SMBus specification). Reads a\nblock of bytes from a device, from a designated register that is specified by\ncmd. The callback gets three arguments (err, bytesRead, buffer). bytesRead is\nthe number of bytes read.\n\n### bus.readI2cBlockSync(addr, cmd, length, buffer)\n- addr - I2C device address\n- cmd - command code\n- length - an integer specifying the number of bytes to read (max 32)\n- buffer - the [Buffer](https://nodejs.org/dist/latest/docs/api/buffer.html)\ninstance that the data will be written to (must conatin at least length bytes)\n\nSynchronous I2C block read (not defined by the SMBus specification). Reads a\nblock of bytes from a device, from a designated register that is specified by\ncmd. Returns the number of bytes read.\n\n### bus.receiveByte(addr, cb)\n- addr - I2C device address\n- cb - completion callback\n\nAsynchronous SMBus receive byte. The callback gets two arguments (err, byte).\nbyte is an unsigned integer in the range 0 to 255.\n\n### bus.receiveByteSync(addr)\n- addr - I2C device address\n\nSynchronous SMBus receive byte. Returns the byte received. byte is an unsigned\ninteger in the range 0 to 255.\n\n### bus.sendByte(addr, byte, cb)\n- addr - I2C device address\n- byte - data byte. byte is an unsigned integer in the range 0 to 255.\n- cb - completion callback\n\nAsynchronous SMBus send byte. The callback gets one argument (err).\n\n### bus.sendByteSync(addr, byte)\n- addr - I2C device address\n- byte - data byte. byte is an unsigned integer in the range 0 to 255.\n\nSynchronous SMBus send byte.\n\n### bus.writeByte(addr, cmd, byte, cb)\n- addr - I2C device address\n- cmd - command code\n- byte - data byte. byte is an unsigned integer in the range 0 to 255.\n- cb - completion callback\n\nAsynchronous SMBus write byte. The callback gets one argument (err).\n\n### bus.writeByteSync(addr, cmd, byte)\n- addr - I2C device address\n- cmd - command code\n- byte - data byte. byte is an unsigned integer in the range 0 to 255.\n\nSynchronous SMBus write byte.\n\n### bus.writeWord(addr, cmd, word, cb)\n- addr - I2C device address\n- cmd - command code\n- word - data word. word is an unsigned integer in the range 0 to 65535.\n- cb - completion callback\n\nAsynchronous SMBus write word. The callback gets one argument (err).\n\n### bus.writeWordSync(addr, cmd, word)\n- addr - I2C device address\n- cmd - command code\n- word - data word. word is an unsigned integer in the range 0 to 65535.\n\nSynchronous SMBus write word.\n\n### bus.writeQuick(addr, bit, cb)\n- addr - I2C device address\n- bit - bit to write (0 or 1)\n- cb - completion callback\n\nAsynchronous SMBus quick command. Writes a single bit to the device.\nThe callback gets one argument (err).\n\n### bus.writeQuickSync(addr, bit)\n- addr - I2C device address\n- bit - bit to write (0 or 1)\n\nSynchronous SMBus quick command. Writes a single bit to the device.\n\n### bus.writeI2cBlock(addr, cmd, length, buffer, cb)\n- addr - I2C device address\n- cmd - command code\n- length - an integer specifying the number of bytes to write (max 32)\n- buffer - the [Buffer](https://nodejs.org/dist/latest/docs/api/buffer.html)\ninstance containing the data to write (must conatin at least length bytes)\n- cb - completion callback\n\nAsynchronous I2C block write (not defined by the SMBus specification). Writes a\nblock of bytes to a device, to a designated register that is specified by cmd.\nThe callback gets three argument (err, bytesWritten, buffer). bytesWritten is\nthe number of bytes written.\n\n### bus.writeI2cBlockSync(addr, cmd, length, buffer)\n- addr - I2C device address\n- cmd - command code\n- length - an integer specifying the number of bytes to write (max 32)\n- buffer - the [Buffer](https://nodejs.org/dist/latest/docs/api/buffer.html)\ninstance containing the data to write (must conatin at least length bytes)\n\nSynchronous I2C block write (not defined by the SMBus specification). Writes a\nblock of bytes to a device, to a designated register that is specified by cmd.\n\n### bus.promisifiedBus()\nReturn the PromisifiedBus instance for this Bus instance.\n\n### promisifiedBus.close()\n\nAsynchronous close. Returns a Promise that will be resolved with no arguments\nonce the underlying resources have been released, or will be rejected if an\nerror occurs while closing.\n\n### promisifiedBus.i2cFuncs()\n\nDetermine functionality of the bus/adapter asynchronously. Returns a Promise\nthat on success will be resolved with a frozen [I2cFuncs](#class-i2cfuncs)\nobject describing the functionality available. The returned Promise will be\nrejected if an error occurs.\nSee also [I2C functionality](https://www.kernel.org/doc/Documentation/i2c/functionality).\n\n### promisifiedBus.scan([startAddr,] [endAddr])\n- startAddr - an integer specifying the start address of the scan range, optional\n- endAddr - an integer specifying the end addrerss of the scan range, optional\n\nbus.scan() - scan for I2C devices in address range 0x03 through 0x77 \u003cbr/\u003e\nbus.scan(addr) - scan for an I2C device at address addr \u003cbr/\u003e\nbus.scan(startAddr, endAddr) - scan for I2C devices in address range startAddr through endAddr \u003cbr/\u003e\n\nScans the I2C bus asynchronously for devices. The default address range 0x03\nthrough 0x77 is the same as the default address range used by the `i2cdetect`\ncommand line tool. Returns a Promise that on success will be resolved with an\narray of numbers where each number represents the I2C address of a device\nwhich was detected. The returned Promise will be rejected if an error occurs.\n\n### promisifiedBus.deviceId(addr)\n- addr - I2C device address\n\nAsynchronous I2C device Id. Returns a Promise that will be resolved with an id\nobject on success, or will be rejected if an error occurs. id is an object\nwith the properties `manufacturer`, `product` and if known a human readable\n`name` for the associated manufacturer. `manufacturer` and `product` are\nnumbers, `name` is a string.\n\n### promisifiedBus.i2cRead(addr, length, buffer)\n- addr - I2C device address\n- length - an integer specifying the number of bytes to read\n- buffer - the [Buffer](https://nodejs.org/dist/latest/docs/api/buffer.html)\ninstance that the data will be written to (must conatin at least length bytes)\n\nAsynchronous plain I2C read. Returns a Promise that on success will be\nresolved with an object with a bytesRead property identifying the number of\nbytes read, and a buffer property that is a reference to the passed in buffer\nargument. The returned Promise will be rejected if an error occurs.\n\n### promisifiedBus.i2cWrite(addr, length, buffer)\n- addr - I2C device address\n- length - an integer specifying the number of bytes to write\n- buffer - the [Buffer](https://nodejs.org/dist/latest/docs/api/buffer.html)\ninstance containing the data to write (must conatin at least length bytes)\n\nAsynchronous plain I2C write. Returns a Promise that on success will be\nresolved with an object with a bytesWritten property identifying the number of\nbytes written, and a buffer property that is a reference to the passed in\nbuffer argument. The returned promise will be rejected if an error occurs.\n\n### promisifiedBus.readByte(addr, cmd)\n- addr - I2C device address\n- cmd - command code\n\nAsynchronous SMBus read byte. Returns a Promise that will be resolved with a\nnumber representing the byte read on success, or will be rejected if an error\noccurs. byte is an unsigned integer in the range 0 to 255.\n\n### promisifiedBus.readWord(addr, cmd)\n- addr - I2C device address\n- cmd - command code\n\nAsynchronous SMBus read word. Returns a Promise that will be resolved with a\nnumber representing the word read on success, or will be rejected if an error\noccurs. word is an unsigned integer in the range 0 to 65535.\n\n### promisifiedBus.readI2cBlock(addr, cmd, length, buffer)\n- addr - I2C device address\n- cmd - command code\n- length - an integer specifying the number of bytes to read (max 32)\n- buffer - the [Buffer](https://nodejs.org/dist/latest/docs/api/buffer.html)\ninstance that the data will be written to (must conatin at least length bytes)\n\nAsynchronous I2C block read (not defined by the SMBus specification). Reads a\nblock of bytes from a device, from a designated register that is specified by\ncmd. Returns a Promise that on success will be resolved with an object with a\nbytesRead property identifying the number of bytes read, and a buffer property\nthat is a reference to the passed in buffer argument. The returned Promise\nwill be rejected if an error occurs.\n\n### promisifiedBus.receiveByte(addr)\n- addr - I2C device address\n\nAsynchronous SMBus receive byte. Returns a Promise that will be resolved with\na number representing the byte received on success, or will be rejected if an\nerror occurs. byte is an unsigned integer in the range 0 to 255.\n\n### promisifiedBus.sendByte(addr, byte)\n- addr - I2C device address\n- byte - data byte. byte is an unsigned integer in the range 0 to 255.\n\nAsynchronous SMBus send byte. Returns a Promise that will be resolved with no\narguments on success, or will be rejected if an error occurs.\n\n### promisifiedBus.writeByte(addr, cmd, byte)\n- addr - I2C device address\n- cmd - command code\n- byte - data byte. byte is an unsigned integer in the range 0 to 255.\n\nAsynchronous SMBus write byte. Returns a Promise that will be resolved with no\narguments on success, or will be rejected if an error occurs.\n\n### promisifiedBus.writeWord(addr, cmd, word)\n- addr - I2C device address\n- cmd - command code\n- word - data word. word is an unsigned integer in the range 0 to 65535.\n\nAsynchronous SMBus write word. Returns a Promise that will be resolved with no\narguments on success, or will be rejected if an error occurs.\n\n### promisifiedBus.writeQuick(addr, bit)\n- addr - I2C device address\n- bit - bit to write (0 or 1)\n\nAsynchronous SMBus quick command. Writes a single bit to the device. Returns a\nPromise that will be resolved with no arguments on success, or will be\nrejected if an error occurs.\n\n### promisifiedBus.writeI2cBlock(addr, cmd, length, buffer)\n- addr - I2C device address\n- cmd - command code\n- length - an integer specifying the number of bytes to write (max 32)\n- buffer - the [Buffer](https://nodejs.org/dist/latest/docs/api/buffer.html)\ninstance containing the data to write (must conatin at least length bytes)\n\nAsynchronous I2C block write (not defined by the SMBus specification). Writes a\nblock of bytes to a device, to a designated register that is specified by cmd.\nReturns a Promise that on success will be resolved with an object with a\nbytesWritten property identifying the number of bytes written, and a buffer\nproperty that is a reference to the passed in buffer argument. The returned\npromise will be rejected if an error occurs.\n\n### promisifiedBus.bus()\nReturn the Bus instance for this PromisifiedBus instance.\n\n### funcs.i2c - boolean\nSpecifies whether or not the adapter handles plain I2C-level commands (Pure\nSMBus adapters typically can not do these,\nI2C_FUNC_I2C).\n\n### funcs.tenBitAddr - boolean\nSpecifies whether or not the adapter handles the 10-bit address extensions\n(I2C_FUNC_10BIT_ADDR).\n\n### funcs.protocolMangling - boolean\nSpecifies whether or not the adapter knows about the I2C_M_IGNORE_NAK,\nI2C_M_REV_DIR_ADDR and I2C_M_NO_RD_ACK flags (which modify the I2C protocol!\nI2C_FUNC_PROTOCOL_MANGLING).\n\n### funcs.smbusPec - boolean\nSpecifies whether or not the adapter handles packet error checking\n(I2C_FUNC_SMBUS_PEC).\n\n### funcs.smbusBlockProcCall - boolean\nSpecifies whether or not the adapter handles the SMBus block process call\ncommand\n(I2C_FUNC_SMBUS_BLOCK_PROC_CALL).\n\n### funcs.smbusQuick - boolean\nSpecifies whether or not the adapter handles the SMBus quick command\n(I2C_FUNC_SMBUS_QUICK).\n\n### funcs.smbusReceiveByte - boolean\nSpecifies whether or not the adapter handles the SMBus receive byte command\n(I2C_FUNC_SMBUS_READ_BYTE).\n\n### funcs.smbusSendByte - boolean\nSpecifies whether or not the adapter handles the SMBus send byte command\n(I2C_FUNC_SMBUS_WRITE_BYTE).\n\n### funcs.smbusReadByte - boolean\nSpecifies whether or not the adapter handles the SMBus read byte command\n(I2C_FUNC_SMBUS_READ_BYTE_DATA).\n\n### funcs.smbusWriteByte - boolean\nSpecifies whether or not the adapter handles the SMBus write byte command\n(I2C_FUNC_SMBUS_WRITE_BYTE_DATA).\n\n### funcs.smbusReadWord - boolean\nSpecifies whether or not the adapter handles the SMBus read word command\n(I2C_FUNC_SMBUS_READ_WORD_DATA).\n\n### funcs.smbusWriteWord - boolean\nSpecifies whether or not the adapter handles the SMBus write word command\n(I2C_FUNC_SMBUS_WRITE_WORD_DATA).\n\n### funcs.smbusProcCall - boolean\nSpecifies whether or not the adapter handles the SMBus process call command\n(I2C_FUNC_SMBUS_PROC_CALL).\n\n### funcs.smbusReadBlock - boolean\nSpecifies whether or not the adapter handles the SMBus read block command\n(I2C_FUNC_SMBUS_READ_BLOCK_DATA).\n\n### funcs.smbusWriteBlock - boolean\nSpecifies whether or not the adapter handles the SMBus write block command\n(I2C_FUNC_SMBUS_WRITE_BLOCK_DATA).\n\n### funcs.smbusReadI2cBlock - boolean\nSpecifies whether or not the adapter handles the SMBus read I2C block command\n(I2C_FUNC_SMBUS_READ_I2C_BLOCK).\n\n### funcs.smbusWriteI2cBlock - boolean\nSpecifies whether or not the adapter handles the SMBus write i2c block command\n(I2C_FUNC_SMBUS_WRITE_I2C_BLOCK).\n\n## TypeScript Type Definitions\n\nTypeScript type definitions for i2c-bus can be found in the Definitely Typed\nrepository at\nhttps://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/i2c-bus.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffivdi%2Fi2c-bus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffivdi%2Fi2c-bus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffivdi%2Fi2c-bus/lists"}