Skip to content

Instantly share code, notes, and snippets.

@kou029w
Last active November 3, 2019 01:19
Show Gist options
  • Save kou029w/ac7cc2ea8e64095a4d97cf6e379cca54 to your computer and use it in GitHub Desktop.
Save kou029w/ac7cc2ea8e64095a4d97cf6e379cca54 to your computer and use it in GitHub Desktop.
ads1x15 example

Usage

npm i
node index.js
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
global.sleep = sleep;
const {requestI2CAccess} = require("node-web-i2c");
const ADS1115 = require("@chirimen/ads1x15");
const ads1115Addr = 0x48;
async function main() {
const i2cAccess = await requestI2CAccess();
const port = i2cAccess.ports.get(1);
const ads1115 = new ADS1115(port, ads1115Addr);
await ads1115.init(true);
let value = ads1115.getVoltage(await ads1115.read(0));
console.log(`Value0: ${value}`);
value = ads1115.getVoltage(await ads1115.read(1));
console.log(`Value1: ${value}`);
value = ads1115.getVoltage(await ads1115.read(2));
console.log(`Value2: ${value}`);
value = ads1115.getVoltage(await ads1115.read(3));
console.log(`Value3: ${value}`);
}
main();
{
"name": "i2c-ads1015-example",
"version": "1.0.0",
"private": true,
"dependencies": {
"@chirimen/ads1x15": "^1.0.0-alpha.0",
"node-web-i2c": "^1.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment