ina219 v0.1.0 INA219.Commands
This module allows execution of all I2C commands to and from the INA219.
It's pretty handy that the INA219 only has two-byte registers, which makes life a lot simpler for me.
Link to this section Summary
Functions
Retrieve the bus ADC resolution and averaging.
Set the bus ADC resolution and averaging.
Returns the bus voltage in mV.
Retrieve the configured bus voltage range.
Set the configured bus voltage range to either 16 or 32V.
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 Functions
bus_adc_resolution_and_averaging(pid)
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(pid, arg)
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(pid)
Returns the bus voltage in mV.
bus_voltage_range(pid)
Retrieve the configured bus voltage range.
bus_voltage_range(pid, int)
Set the configured bus voltage range to either 16 or 32V.
calibrate(pid, value)
Set the calibration value.
calibrate_16V_400mA!(pid)
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!(pid)
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!(pid)
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?(pid)
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(pid, divisor)
Returns the current in mA.
math_overflow?(pid)
Returns true
when power or current calculations are out of range.
This indicates that current and power data may be meaningless.
mode(pid)
Retrieve the current operating mode of the device.
mode(pid, atom)
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(pid, divisor)
Returns the power in mW
reset!(pid)
Power-on-reset the device,
shunt_adc_resolution_and_averaging(pid)
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(pid, 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(pid)
Returns the shunt voltage in mV.
shunt_voltage_pga(pid)
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(pid, int)
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.