Giter VIP home page Giter VIP logo

ina219's Introduction

INA219

Build Status Hex.pm Hippocratic License HL3-FULL

A library for interacting with the Texas Instruments INA219 high side current and power monitoring chip via I2C using Elixir ALE.

I'm using the Adafruit INA219 breakout for prototyping, so am using their calibrations straight from their Arduino library, but you can do the maths and calibrate it yourself if you're using a different shunt resistor value.

Usage

This library uses the Wafer project to connect to the I2C device - this allows you to bring your own driver.

Example using Elixir Circuits

iex> {:ok, conn} = Wafer.Driver.CircuitsI2C.acquire(bus: "i2c-1", address: 0x41)
...> {:ok, conn} = INA219.acquire(conn: conn, current_divisor: 10, power_divisor: 2)
...> :ok = INA219.calibrate_32V_2A(conn)
...> INA219.bus_voltage(conn)
{:ok, 12.0}

Calibration

Calibrating these wee chips is a bit of a pain in the donkey, but is easily achieved by following the equation in the data sheet. Once you have the calibration and divisor values you wish to use you can configure the device manually. For example:

iex> {:ok, conn} = Wafer.Driver.CircuitsI2C.acquire(bus: "i2c-1", address: 0x41)
...> {:ok, conn} = INA219.acquire(conn: conn, current_divisor: 10, power_divisor: 2)
...> INA219.calibrate(conn, 4096)
...> INA219.bus_voltage_range(conn, 32)
...> INA219.shunt_voltage_pga(conn, 8)
...> INA219.bus_adc_resolution_and_averaging(conn, {1, 12})
...> INA219.shunt_adc_resolution_and_averaging(conn, {1, 12})
...> INA219.mode(conn, :shunt_and_bus_voltage_continuous)

The current_divisor and power_divisor values are stored in the connection struct because there's no way to store them in the device's registers. You can alter them as required.

Installation

The ina219 package is available on hex so it can be installed by adding ina219 to your list of dependencies in mix.exs. You'll also need to install an appropriate connection driver.

def deps do
  [
    {:ina219, "~> 2.0.1"}
  ]
end

Documentation for the latest release is always available on HexDocs and for the main branch on docs.harton.nz.

Github Mirror

This repository is mirrored on Github from it's primary location on my Forgejo instance. Feel free to raise issues and open PRs on Github.

License

This software is licensed under the terms of the HL3-FULL, see the LICENSE.md file included with this package for the terms.

This license actively proscribes this software being used by and for some industries, countries and activities. If your usage of this software doesn't comply with the terms of this license, then contact me with the details of your use-case to organise the purchase of a license - the cost of which may include a donation to a suitable charity or NGO.

ina219's People

Contributors

jimsynz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.