Skip to main content

Meadow.Foundation.Sensors.Power.Ina219

Ina219
StatusStatus badge: working
Source codeGitHub
Datasheet(s)GitHub
NuGet packageNuGet Gallery for Meadow.Foundation.Sensors.Power.Ina2xx

Code Example

Ina219 ina219;

public override Task Initialize()
{
Resolver.Log.Debug("Initialize...");

var bus = Device.CreateI2cBus(I2cBusSpeed.Fast);
ina219 = new Ina219(bus);
ina219.Configure(busVoltageRange: Ina219.BusVoltageRange.Range_32V,
maxExpectedCurrent: new Current(1.0),
adcMode: Ina219.ADCModes.ADCMode_4xAvg_2128us);
Resolver.SensorService.RegisterSensor(ina219);

Resolver.Log.Info($"--- INA219 Sample App ---");
ina219.Updated += (sender, result) =>
{
Resolver.Log.Info($"{result.New.Voltage:N3} V @ {result.New.Current:N3} A");
};

return Task.CompletedTask;
}

public override Task Run()
{
Resolver.Log.Debug("Run...");
ina219.StartUpdating(TimeSpan.FromSeconds(2));
return Task.CompletedTask;
}

Sample project(s) available on GitHub

Class Ina219

Represents a INA219 Precision Digital Current and Power Monitor

Assembly: Ina2xx.dll
View Source
Declaration
public class Ina219 : Ina2xx, IObservable<IChangeResult<(Current? Current, Voltage? Voltage, Power? Power)>>, ISamplingSensor<(Current? Current, Voltage? Voltage, Power? Power)>, ISensor<(Current? Current, Voltage? Voltage, Power? Power)>, IDisposable, ICurrentSensor, ISamplingSensor<Current>, ISensor<Current>, IVoltageSensor, ISamplingSensor<Voltage>, ISensor<Voltage>, IPowerSensor, ISamplingSensor<Power>, ISensor<Power>, ISensor, ISamplingSensor, II2cPeripheral

Inheritance: System.Object -> Meadow.Foundation.ObservableBase<UNIT>

Implements:

Expand

System.IObservable<Meadow.IChangeResult<System.ValueTuple<System.Nullable<Meadow.Units.Current>,System.Nullable<Meadow.Units.Voltage>,System.Nullable<Meadow.Units.Power>>>>, Meadow.Peripherals.Sensors.ISamplingSensor<System.ValueTuple<System.Nullable<Meadow.Units.Current>,System.Nullable<Meadow.Units.Voltage>,System.Nullable<Meadow.Units.Power>>>, Meadow.Peripherals.Sensors.ISensor<System.ValueTuple<System.Nullable<Meadow.Units.Current>,System.Nullable<Meadow.Units.Voltage>,System.Nullable<Meadow.Units.Power>>>, System.IDisposable, Meadow.Peripherals.Sensors.ICurrentSensor, Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Current>, Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Current>, Meadow.Peripherals.Sensors.IVoltageSensor, Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Voltage>, Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Voltage>, Meadow.Peripherals.Sensors.IPowerSensor, Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Power>, Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Power>, Meadow.Peripherals.Sensors.ISensor, Meadow.Peripherals.Sensors.ISamplingSensor, Meadow.Hardware.II2cPeripheral

Methods

Configure()

Sets the sensor Configuration to default values. Each implementation should provide overloads for specific available options.

View Source
Declaration
public override void Configure()

Configure(BusVoltageRange, ADCModes, ShuntVoltageRange, ADCModes, Mode)

Sets Configuration of sensor

View Source
Declaration
public void Configure(Ina219.BusVoltageRange busVoltageRange = BusVoltageRange.Range_32V, Ina219.ADCModes busADCMode = ADCModes.ADCMode_12bit_532us, Ina219.ShuntVoltageRange shuntVoltageRange = ShuntVoltageRange.Range_320mV, Ina219.ADCModes shuntADCMode = ADCModes.ADCMode_12bit_532us, Ina219.Mode mode = Mode.ContinuousAll)
Parameters
TypeNameDescription
Meadow.Foundation.Sensors.Power.Ina219.BusVoltageRange to use for Bus Voltage measurement
Meadow.Foundation.Sensors.Power.Ina219.ADCModesbusADCModeADC resolution/averaging for Bus Voltage
Meadow.Foundation.Sensors.Power.Ina219.ShuntVoltageRange to use for Shunt Voltage measurement
Meadow.Foundation.Sensors.Power.Ina219.ADCModesshuntADCModeADC resolution/averaging for Shunt Voltage
Meadow.Foundation.Sensors.Power.Ina219.Modemodeselection of values and trigger mode

Configure(BusVoltageRange, Current, ADCModes, Mode)

Sets Configuration of sensor, using best shunt voltage range possible based on the max expected current.

View Source
Declaration
public void Configure(Ina219.BusVoltageRange busVoltageRange, Current maxExpectedCurrent, Ina219.ADCModes adcMode = ADCModes.ADCMode_12bit_532us, Ina219.Mode mode = Mode.ContinuousAll)
Parameters
TypeNameDescription
Meadow.Foundation.Sensors.Power.Ina219.BusVoltageRangebusVoltageRangevoltage measurement range
Meadow.Units.CurrentmaxExpectedCurrentMaximum expected current for the application.
Meadow.Foundation.Sensors.Power.Ina219.ADCModesadcModeADC resolution/averaging setting common to both ADCs
Meadow.Foundation.Sensors.Power.Ina219.Modemodeselection of values and trigger mode

ReadCurrent()

Read the Current measurement from the power monitor IC.

View Source
Declaration
public override Current ReadCurrent()
Returns

Meadow.Units.Current

ReadBusVoltage()

Read the Voltage measurement from the power monitor IC.

View Source
Declaration
public override Voltage ReadBusVoltage()
Returns

Meadow.Units.Voltage

ReadShuntVoltage()

Read the Voltage across the Shunt (sense) resistor from the power monitor IC.

View Source
Declaration
public override Voltage ReadShuntVoltage()
Returns

Meadow.Units.Voltage

ReadPower()

Read the Power measurement from the power monitor IC.

View Source
Declaration
public override Power ReadPower()
Returns

Meadow.Units.Power

Implements

  • System.IObservable<Meadow.IChangeResult<System.ValueTuple<System.Nullable<Meadow.Units.Current>,System.Nullable<Meadow.Units.Voltage>,System.Nullable<Meadow.Units.Power>>>>
  • Meadow.Peripherals.Sensors.ISamplingSensor<System.ValueTuple<System.Nullable<Meadow.Units.Current>,System.Nullable<Meadow.Units.Voltage>,System.Nullable<Meadow.Units.Power>>>
  • Meadow.Peripherals.Sensors.ISensor<System.ValueTuple<System.Nullable<Meadow.Units.Current>,System.Nullable<Meadow.Units.Voltage>,System.Nullable<Meadow.Units.Power>>>
  • System.IDisposable
  • Meadow.Peripherals.Sensors.ICurrentSensor
  • Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Current>
  • Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Current>
  • Meadow.Peripherals.Sensors.IVoltageSensor
  • Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Voltage>
  • Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Voltage>
  • Meadow.Peripherals.Sensors.IPowerSensor
  • Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Power>
  • Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Power>
  • Meadow.Peripherals.Sensors.ISensor
  • Meadow.Peripherals.Sensors.ISamplingSensor
  • Meadow.Hardware.II2cPeripheral