npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ina219-async

v1.1.0

Published

Node.js INA219 driver for Adafruit INA219 High Side DC Current Sensor using promises

Downloads

97

Readme

node-ina219-async

Node.js Driver for INA219 current sensing module. Returns promises for easier operation chaining.

This library supports having multiple sensors connected by passing in i2c bus number and i2c device address.

Based on the ina219 node module, which in turn is based on Adafruit's INA219 library.

Install

$ npm install ina219-async

##Usage

Take a single reading, chained with then:


  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:

  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:


  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.

  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:

calibrate32V1A()

Configures the INA219 to be able to measure up to 32V and 1A of current. Each unit of current corresponds to 40uA, and each unit of power corresponds to 800mW. Counter overflow occurs at 1.3A. Note: These calculations assume a 0.1 ohm shunt resistor is used.

Returns a promise which is completed upon successfully configuring the sensor.

calibrate32V2A()

Configures the INA219 to be able to measure up to 32V and 2A of current.

Returns a promise which is completed upon successfully configuring the sensor.

getBusVoltage_V()

Gets the bus voltage in volts. Returns a promise.

getShuntVoltage_mV()

Gets the shunt voltage in mV (so +-327mV). Returns a promise.

getCurrent_mA()

Gets the current value in mA, taking into account the config settings and current LSB. Returns a promise.

closeSync()

Closes the underlying i2c bus object used for communicating with the INA219 device to free resources.