mirror of
https://github.com/chirimen-oh/node-web-i2c.git
synced 2025-01-18 16:08:06 +00:00
I2C access with Node.js
.gitignore | ||
index.d.ts | ||
index.js | ||
index.ts | ||
LICENSE | ||
package.json | ||
README.md | ||
tsconfig.json | ||
yarn.lock |
node-web-i2c
I2C access with Node.js
Usage
const { requestI2CAccess } = require("node-web-i2c");
const ADT7410_ADDR = 0x48;
async function main() {
const i2cAccess = await requestI2CAccess();
const port = i2cAccess.ports.get(1);
const i2cSlave = await port.open(ADT7410_ADDR);
const temperature =
(((await i2cSlave.read8(0x00)) << 8) + (await i2cSlave.read8(0x01))) / 128;
console.log(`Temperature: ${temperature} ℃`);
}
main();