node-web-i2c/README.md

27 lines
530 B
Markdown
Raw Normal View History

2019-10-18 21:41:11 +09:00
# node-web-i2c
2019-10-18 03:23:29 +09:00
I2C access with Node.js
## Usage
```js
2019-10-18 21:41:11 +09:00
const { requestI2CAccess } = require("node-web-i2c");
2019-10-18 03:23:29 +09:00
const ADT7410_ADDR = 0x48;
async function main() {
const i2cAccess = await requestI2CAccess();
2019-10-18 10:27:56 +09:00
const port = i2cAccess.ports.get(1);
2019-10-18 03:23:29 +09:00
const i2cSlave = await port.open(ADT7410_ADDR);
const temperature =
(((await i2cSlave.read8(0x00)) << 8) + (await i2cSlave.read8(0x01))) / 128;
console.log(`Temperature: ${temperature} ℃`);
}
main();
```
## Document
[Web I2C API](http://browserobo.github.io/WebI2C)