INA219 (ina219 v2.0.0)
INA219 Driver using Wafer.
Link to this section Summary
Functions
Acquire a connection to the INA219 device using the passed in I2C connection.
Retrieve the bus ADC resolution and averaging.
Set the bus ADC resolution and averaging.
Returns the bus voltage in V.
Retrieve the configured bus voltage range.
Set the configured bus voltage range to either 16 or 32V.
Get the calibration value.
Set the calibration value.
This is a convenient helper function to set the configuration to the right values for 16V input and 400mA current range at the highest resolution (0.1mA). This only works for devices with a 0.1Ω shunt resistor (ie Adafruit's breakout).
This is a convenient helper function to set the configuration to the right values for 32V input voltage range and 1A current range at the cost of accuracy. This only works for devices with a 0.1Ω shunt resistor (ie Adafruit's breakout).
This is a convenient helper function to set the configuration to the right values for 32V input voltage range and 2A current range at the cost of accuracy. This only works for devices with a 0.1Ω shunt resistor (ie Adafruit's breakout).
Are new samples ready since the last time you read them? Calling this function will clear the value until next time new samples are ready.
Returns the current in mA.
Returns true
when power or current calculations are out of range.
This indicates that current and power data may be meaningless.
Retrieve the current operating mode of the device.
Set the current operating mode for the device.
Returns the power in mW
Power-on-reset the device,
Retrieve the shunt ADC resolution.
Set the shunt ADC resolution and averaging.
Returns the shunt voltage in mV.
Retrieve the configured shunt voltage PGA.
Set the configured shunt voltage PGA to a configured value.
Link to this section Types
acquire_option()
@type acquire_option() :: {:conn, Wafer.Conn.t()} | {:current_divisor, number()} | {:power_divisor, number()}
acquire_options()
@type acquire_options() :: [acquire_option()]
milliamps()
@type milliamps() :: float()
millivolts()
@type millivolts() :: float()
milliwatts()
@type milliwatts() :: float()
operating_mode()
@type operating_mode() ::
:power_down
| :shunt_voltage_triggered
| :bus_voltage_triggered
| :adc_off
| :shunt_voltage_continuous
| :bus_voltage_continuous
| :shunt_and_bus_voltage_continuous
sample_averaging()
@type sample_averaging() :: 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128
sample_resolution()
@type sample_resolution() :: 9 | 10 | 12
shunt_voltage_pga()
@type shunt_voltage_pga() :: 1 | 2 | 4 | 8
@type t() :: %INA219{ conn: Wafer.Conn.t(), current_divisor: number(), power_divisor: number() }
volts()
@type volts() :: float()
Link to this section Functions
acquire(options)
@spec acquire(acquire_options()) :: {:ok, t()} | {:error, reason :: any()}
Acquire a connection to the INA219 device using the passed in I2C connection.
options
Options:
conn
an I2C connection, probably fromElixirALE.I2C
orCircuits.I2C
.current_divisor
seeINA219.Commands
for more information.power_divisor
seeINA219.Commands
for more information.
bus_adc_resolution_and_averaging(conn)
@spec bus_adc_resolution_and_averaging(t()) :: {:ok, {sample_averaging(), sample_resolution()}} | {:error, reason :: any()}
Retrieve the bus ADC resolution and averaging.
Returns the number of samples and the resolution as a two element tuple.
eg {1, 9}
refers to 9-bit ADC resolution and 1-sample averaging.
bus_adc_resolution_and_averaging(conn, arg)
@spec bus_adc_resolution_and_averaging( t(), {sample_averaging(), sample_resolution()} ) :: :ok | {:error, reason :: any()}
Set the bus ADC resolution and averaging.
Expects a tuple of the form {samples, bits}
. Be aware that changing this value affects
the amount of time it takes to compute values. Refer to the datasheet for more information.
Valid values are:
{ 1, 9}
- 1 sample averaging and 9 bit ADC resolution.{ 1, 10}
- 1 sample averaging and 10 bit ADC resolution.{ 1, 11}
- 1 sample averaging and 11 bit ADC resolution.{ 1, 12}
- 1 sample averaging and 12 bit ADC resolution.{ 2, 12}
- 2 sample averaging and 12 bit ADC resolution.{ 4, 12}
- 4 sample averaging and 12 bit ADC resolution.{ 8, 12}
- 8 sample averaging and 12 bit ADC resolution.{ 16, 12}
- 16 sample averaging and 12 bit ADC resolution.{ 32, 12}
- 32 sample averaging and 12 bit ADC resolition.{ 64, 12}
- 64 sample averaging and 12 bit ADC resolution.{128, 12}
- 128 sample averaging and 12 bit ADB resolution.
bus_voltage(conn)
Returns the bus voltage in V.
bus_voltage_range(conn)
Retrieve the configured bus voltage range.
bus_voltage_range(conn, int)
Set the configured bus voltage range to either 16 or 32V.
calibrate(conn)
@spec calibrate(t()) :: {:ok, non_neg_integer()} | {:error, reason :: any()}
Get the calibration value.
calibrate(conn, data)
@spec calibrate(t(), non_neg_integer()) :: :ok | {:error, reason :: any()}
Set the calibration value.
calibrate_16V_400mA(conn)
This is a convenient helper function to set the configuration to the right values for 16V input and 400mA current range at the highest resolution (0.1mA). This only works for devices with a 0.1Ω shunt resistor (ie Adafruit's breakout).
Make sure that you configure your device with a current_divisor
of 20
and a
power_divisor
of 1
.
calibrate_32V_1A(conn)
This is a convenient helper function to set the configuration to the right values for 32V input voltage range and 1A current range at the cost of accuracy. This only works for devices with a 0.1Ω shunt resistor (ie Adafruit's breakout).
Make sure that you configure your device with a current_divisor
of 25
and a
power_divisor
of 1
.
calibrate_32V_2A(conn)
This is a convenient helper function to set the configuration to the right values for 32V input voltage range and 2A current range at the cost of accuracy. This only works for devices with a 0.1Ω shunt resistor (ie Adafruit's breakout).
Make sure that you configure your device with a current_divisor
of 10
and a
power_divisor
of 2
.
conversion_ready?(conn)
Are new samples ready since the last time you read them? Calling this function will clear the value until next time new samples are ready.
current(conn)
Returns the current in mA.
math_overflow?(conn)
Returns true
when power or current calculations are out of range.
This indicates that current and power data may be meaningless.
mode(conn)
@spec mode(t()) :: {:ok, operating_mode()} | {:error, reason :: any()}
Retrieve the current operating mode of the device.
mode(conn, atom)
@spec mode(t(), operating_mode()) :: :ok | {:error, reason :: any()}
Set the current operating mode for the device.
Valid values are:
:power_down
:shunt_voltage_triggered
:bus_voltage_triggered
:adc_off
:shunt_voltage_continuous
:bus_voltage_continuous
:shunt_and_bus_voltage_continuous
power(conn)
@spec power(t()) :: {:ok, milliwatts()} | {:error, reason :: any()}
Returns the power in mW
reset(conn)
Power-on-reset the device,
shunt_adc_resolution_and_averaging(conn)
@spec shunt_adc_resolution_and_averaging(t()) :: {:ok, {sample_averaging(), sample_resolution()}} | {:error, reason :: any()}
Retrieve the shunt ADC resolution.
Returns the number of samples and the resolution as a two element tuple.
eg {1, 9}
refers to 9-bit ADC resolution and 1-sample averaging.
shunt_adc_resolution_and_averaging(conn, arg)
Set the shunt ADC resolution and averaging.
Expects a tuple of the form {samples, bits}
. Be aware that changing this value affects
the amount of time it takes to compute values. Refer to the datasheet for more information.
Valid values are:
{ 1, 9}
- 1 sample averaging and 9 bit ADC resolution.{ 1, 10}
- 1 sample averaging and 10 bit ADC resolution.{ 1, 11}
- 1 sample averaging and 11 bit ADC resolution.{ 1, 12}
- 1 sample averaging and 12 bit ADC resolution.{ 2, 12}
- 2 sample averaging and 12 bit ADC resolution.{ 4, 12}
- 4 sample averaging and 12 bit ADC resolution.{ 8, 12}
- 8 sample averaging and 12 bit ADC resolution.{ 16, 12}
- 16 sample averaging and 12 bit ADC resolution.{ 32, 12}
- 32 sample averaging and 12 bit ADC resolition.{ 64, 12}
- 64 sample averaging and 12 bit ADC resolution.{128, 12}
- 128 sample averaging and 12 bit ADB resolution.
shunt_voltage(conn)
@spec shunt_voltage(t()) :: {:ok, millivolts()} | {:error, reason :: any()}
Returns the shunt voltage in mV.
shunt_voltage_pga(conn)
@spec shunt_voltage_pga(t()) :: {:ok, shunt_voltage_pga()} | {:error, reason :: any()}
Retrieve the configured shunt voltage PGA.
Returns the gain
value.
Valid values are:
1
- gain 1, range +40mV.2
- gain +2, range +80mV.4
- gain +4, range +160mV.8
- gain +8, range +320mV.
shunt_voltage_pga(conn, int)
@spec shunt_voltage_pga(t(), shunt_voltage_pga()) :: :ok | {:error, reason :: any()}
Set the configured shunt voltage PGA to a configured value.
Valid values are:
1
- gain 1, range +40mV.2
- gain +2, range +80mV.4
- gain +4, range +160mV.8
- gain +8, range +320mV.