Node.js INA219 driver for Adafruit INA219 High Side DC Current Sensor using promises
npm install ina219-asyncbash
$ npm install ina219-async
``
##Usage
Take a single reading, chained with then:
`javascript
const Ina219Board = require('ina219-async');
const ina219 = Ina219Board();
ina219.calibrate32V2A()
.then(() => ina219.getBusVoltage_V())
.then(volts => console.log("Voltage: " + volts))
.then(() => ina219.getCurrent_mA())
.then(current => console.log("Current (mA): " + current))
.then(() => ina219.closeSync());
`
Async example:
`javascript
const Ina219Board = require('ina219-async');
const ina219 = Ina219Board();
// Inside an async function:
await ina219.calibrate32V2A();
const volts = await ina219.getBusVoltage_V();
console.log("Voltage: " + volts);
const current = await ina219.getCurrent_mA();
console.log("Current (mA): " + current);
// Make sure to call closeSync() to close the undelying i2c bus reference
// to free resources when the ina219 object is no longer needed
ina219.closeSync();
`
Multiple sensors:
`javascript
const Ina219Board = require('ina219-async');
const bus1 = Ina219Board(0x40, 1);
await bus1.calibrate32V2A();
const bus2 = Ina219Board(0x42, 1);
await bus2.calibrate32V1A();
const volts1 = await bus1.getBusVoltage_V();
const volts2 = await bus2.getBusVoltage_V();
console.log("Voltage:", volts1, volts2);
`
Module export
The ina219-async library exports a single function to be used as a constructor.
`javascript
const Ina219Board = require('ina219-async');
const ina219 = Ina219Board(i2cAddress = 0x40, i2cBus = 1);
`
This function takes 2 parameters - i2c address of the ina219 device and i2c bus where the device is connected.
If not specified, address 0x40 and device 1 are used by default.
Make sure to call one of the calibrate methods before reading voltage and current values.
Methods
The Ina219Board` object created above has the following methods: