{"id":21101157,"url":"https://github.com/crycode-de/node-ina226","last_synced_at":"2025-05-16T18:34:27.435Z","repository":{"id":57273216,"uuid":"342576903","full_name":"crycode-de/node-ina226","owner":"crycode-de","description":"Node.js module to read values from the INA226 bi-directional current and power monitor.","archived":false,"fork":false,"pushed_at":"2021-02-26T13:10:55.000Z","size":48,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-02T06:54:12.445Z","etag":null,"topics":["i2c-bus","ina226","nodejs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/crycode-de.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["crycode-de"],"custom":["https://www.paypal.me/petercrycode"]}},"created_at":"2021-02-26T13:00:50.000Z","updated_at":"2024-05-24T19:09:38.000Z","dependencies_parsed_at":"2022-09-17T05:11:05.107Z","dependency_job_id":null,"html_url":"https://github.com/crycode-de/node-ina226","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crycode-de%2Fnode-ina226","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crycode-de%2Fnode-ina226/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crycode-de%2Fnode-ina226/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crycode-de%2Fnode-ina226/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crycode-de","download_url":"https://codeload.github.com/crycode-de/node-ina226/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224859664,"owners_count":17381679,"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-bus","ina226","nodejs"],"created_at":"2024-11-19T23:40:39.921Z","updated_at":"2024-11-19T23:40:40.520Z","avatar_url":"https://github.com/crycode-de.png","language":"TypeScript","funding_links":["https://github.com/sponsors/crycode-de","https://www.paypal.me/petercrycode"],"categories":[],"sub_categories":[],"readme":"# ina226\n\n[![NPM version](https://img.shields.io/npm/v/ina226.svg)](https://www.npmjs.com/package/ina226)\n[![Downloads](https://img.shields.io/npm/dm/ina226.svg)](https://www.npmjs.com/package/iina226)\n\n[![NPM](https://nodei.co/npm/ina226.png?downloads=true)](https://nodei.co/npm/ina226/)\n\nNode.js module to read values from the INA226 bi-directional current and power monitor.\n\nFor more information about the INA226 please consult the [data sheet from Texas Instruments](http://www.ti.com/lit/ds/symlink/ina226.pdf).\n\n## Features\n\n* Read shunt and bus voltages.\n* Calculate current and power.\n* Read the value from a register.\n* Write a value to a register.\n\n\n## Installation\n\nMake sure you are using Node.js v8.x or higher.\n\n```\nnpm install ina226\n```\n\nThis module is written in TypeScript and typings are included.\n\n\n## Example\n\nNote that you need to construct the [i2c-bus](https://npmjs.org/package/i2c-bus) object and pass it in to the INA226 class.\n\nThe example blow can be found in the [examples directory](https://github.com/crycode-de/node-ina226/tree/main/examples) of this package together with a TypeScript example.\n\n\n```js\n// Require the ina226 module\nvar INA226 = require('ina226').INA226;\n\n// Require the i2c-bus module and open the bus\nvar i2cBus = require('i2c-bus').openSync(1);\n\n// Define the address of the INA226 and the shunt resistance value\nvar addr = 0x40;\nvar rShunt = 0.1;\n\n// Init a new INA226\nvar ina = new INA226(i2cBus, addr, rShunt);\n\n// Write to the Configuration Register\n// 0x4427 means 16 averages, 1.1ms conversion time, shunt and bus continuous\nina.writeRegister(CONFIGURATION_REGISTER, 0x4427)\n.then(function(){\n  console.log('Configuration written');\n});\n\n// Read the actual bus voltage\nina.readBusVoltage()\n.then(function(busVoltage){\n  console.log('Bus Voltage: ' + busVoltage.toFixed(2) + 'V');\n});\n\n// Read the actual shunt voltage\nina.readShuntVoltage()\n.then(function(shuntVoltage){\n  console.log('Shunt Voltage: ' + shuntVoltage.toFixed(5) + 'V');\n});\n\n// Read the actual shunt voltage and calculate the current\nina.readShuntVoltage()\n.then(function(){\n  var current = ina.calcCurrent();\n  console.log('Current: ' + current.toFixed(2) + 'A');\n})\n\n// Then read the actual bus voltage and calculate the power\n.then(ina.readBusVoltage.bind(ina))\n.then(function(){\n  var power = ina.calcPower();\n  console.log('Power: ' + power.toFixed(2) + 'W');\n});\n```\n\n\n## API\n\n### new INA226(i2cBus, address, rShunt)\n\n```ts\nconstructor(i2cBus:I2cBus, address:number, rShunt:number=0.1)\n```\n\nConstructor for a new INA226 instance.\n\n* `i2cBus` - Instance of an opened i2c-bus.\n* `address` - The address of the INA226 IC.\n* `rShunt` - The shunt resistance value. Defaults to 0.1 Ohm.\n\nNote that you need to construct the [i2c-bus](https://npmjs.org/package/i2c-bus) object and pass it in to the module.\n\n### writeRegister(register, value)\n\n```ts\nwriteRegister(register:number, value:number):Promise\u003c{}\u003e\n```\n\nWrites a value to a specific register.\nReturns a Promise which will be resolves if the value is written, or rejected in case of an error.\n* `register` - The register address.\n* `value` - The value. Should be 16bit integer.\n\n### readRegister(register)\n\n```ts\nreadRegister(register:number):Promise\u003cnumber\u003e\n```\n\nReads a value from a specific register.\nReturns a Promise which will be resolved with the read value, or rejected in case of an error.\n* `register` - The register address.\n\n### readBusVoltage()\n\n```ts\nreadBusVoltage():Promise\u003cnumber\u003e\n```\n\nReads the actual bus voltage.\nReturns a Promise which will be resolved with the bus voltage, or rejected in case of an error.\n\n### readShuntVoltage()\n\n```ts\nreadShuntVoltage():Promise\u003cnumber\u003e\n```\n\nReads the actual shunt voltage.\nReturns a Promise which will be resolved with the shunt voltage, or rejected in case of an error.\n\n### calcCurrent(shuntVoltage)\n\n```ts\ncalcCurrent(shuntVoltage?:number):number\n```\n\nCalculates the current in Ampere based on the shunt voltage an the shunt resistance value.\n* `shuntVoltage` - *Optional.* The shunt voltage which is used for the calculation. Defaults to the last read shunt voltage.\n\n### calcPower(busVoltage, shuntVoltage)\n\n```ts\ncalcPower(busVoltage?:number, shuntVoltage?:number):number\n```\n\nCalculates the power in Watt based on the bus voltage, the shunt voltage and the shunt resistance value.\n* `busVoltage` - *Optional.* The bus voltage which is used for the calculation. Defaults to the last read bus voltage.\n* `shuntVoltage` - *Optional.* The shunt voltage which is used for the calculation. Defaults to the last read shunt voltage.\n\n### Exported constants\n\nThe register addresses are exported as constants.\n\n| Constant | Value |\n|---|---|\n| CONFIGURATION_REGISTER | 0x00 |\n| SHUNT_VOLTAGE_REGISTER | 0x01 |\n| BUS_VOLTAGE_REGISTER | 0x02 |\n| POWER_REGISTER | 0x03 |\n| CURRENT_REGISTER | 0x04 |\n| CALIBRATION_REGISTER | 0x05 |\n| MASK_ENABLE_REGISTER | 0x06 |\n| ALERT_LIMIT_REGISTER | 0x07 |\n| MANUFACTOR_ID_REGISTER | 0xFE |\n| DIE_ID_REGISTER | 0xFF |\n\n\n\n## License\n\nCreative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)\n\nCopyright (c) 2017-2021 Peter Müller \u003cpeter@crycode.de\u003e [https://crycode.de/](https://crycode.de/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrycode-de%2Fnode-ina226","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrycode-de%2Fnode-ina226","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrycode-de%2Fnode-ina226/lists"}