Skip to main content

Meadow.Foundation.Sensors.Power.Ina260

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

Code Example

Ina260 ina260;

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

var bus = Device.CreateI2cBus(I2cBusSpeed.Fast);
ina260 = new Ina260(bus);
ina260.Configure(Ina260.ConversionTime.ConversionTime_8244us, Ina260.ConversionTime.ConversionTime_8244us, Ina260.Averaging.Average_4);
//Resolver.SensorService.RegisterSensor(ina260);

Resolver.Log.Info($"--- INA260 Sample App ---");
Resolver.Log.Info($"Manufacturer: {ina260.ManufacturerID}");
Resolver.Log.Info($"DeviceID: 0x{ina260.DeviceID:X3}");
Resolver.Log.Info($"Revision: 0x{ina260.DeviceRevision:X2}");
ina260.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...");
ina260.StartUpdating(TimeSpan.FromSeconds(2));
return Task.CompletedTask;
}

Sample project(s) available on GitHub

Class Ina260

Represents a INA260 Precision Digital Current and Power Monitor

Assembly: Ina2xx.dll
View Source
Declaration
public class Ina260 : 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(ConversionTime, ConversionTime, Averaging, Mode)

Sets Configuration of sensor

View Source
Declaration
public void Configure(Ina260.ConversionTime currentConversionTime = ConversionTime.ConversionTime_1100us, Ina260.ConversionTime voltageConversionTime = ConversionTime.ConversionTime_1100us, Ina260.Averaging averaging = Averaging.Average_1, Ina260.Mode mode = Mode.ContinuousAll)
Parameters
TypeNameDescription
Meadow.Foundation.Sensors.Power.Ina260.ConversionTimecurrentConversionTimeConversion time for Current measurements
Meadow.Foundation.Sensors.Power.Ina260.ConversionTimevoltageConversionTimeConversion time for Voltage measurements
Meadow.Foundation.Sensors.Power.Ina260.AveragingaveragingOn-chip value averaging
Meadow.Foundation.Sensors.Power.Ina260.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

AlertOnVoltageLimit(Voltage, bool, bool, bool)

Configures the Voltage Limit Alert function.

View Source
Declaration
public void AlertOnVoltageLimit(Voltage threshold, bool activeHigh = false, bool latching = false, bool overLimit = false)
Parameters
TypeNameDescription
Meadow.Units.VoltagethresholdMeadow.Units.Voltage threshold for triggering the Alert.
System.BooleanactiveHighState of the alert pin to use for the Alert Signal
System.BooleanlatchingWhether to latch the Alert until cleared.
System.BooleanoverLimitSet true to trigger an alert when the measured voltage is <b>above</b> the <code class="paramref">threshold</code>.
Exceptions

System.ArgumentOutOfRangeException
Thrown if the <code class="paramref">threshold</code> is outside the limits of the power monitor IC.

AlertOnCurrentLimit(Current, bool, bool, bool)

Configures the Current Limit Alert function.

View Source
Declaration
public void AlertOnCurrentLimit(Current threshold, bool activeHigh = false, bool latching = false, bool overLimit = false)
Parameters
TypeNameDescription
Meadow.Units.CurrentthresholdMeadow.Units.Current threshold for triggering the Alert.
System.BooleanactiveHighState of the alert pin to use for the Alert Signal
System.BooleanlatchingWhether to latch the Alert until cleared.
System.BooleanoverLimitSet true to trigger an alert when the measured Current is <b>above</b> the <code class="paramref">threshold</code>.
Exceptions

System.ArgumentOutOfRangeException
Thrown if the <code class="paramref">threshold</code> is outside the limits of the power monitor IC.

AlertOnPowerLimit(Power, bool, bool)

Configures the Power Limit Alert function.

View Source
Declaration
public void AlertOnPowerLimit(Power threshold, bool activeHigh = false, bool latching = false)
Parameters
TypeNameDescription
Meadow.Units.PowerthresholdMeadow.Units.Power threshold for triggering the Alert.
System.BooleanactiveHighState of the alert pin to use for the Alert Signal
System.BooleanlatchingWhether to latch the Alert until cleared.
Exceptions

System.ArgumentOutOfRangeException
Thrown if the <code class="paramref">threshold</code> is outside the limits of the power monitor IC.

AlertOnConversionComplete(bool, bool)

Configures the Alert function to activate when all ADC conversions are complete.

View Source
Declaration
public void AlertOnConversionComplete(bool activeHigh = false, bool latching = false)
Parameters
TypeNameDescription
System.BooleanactiveHighState of the alert pin to use for the Alert Signal
System.BooleanlatchingWhether to latch the Alert until cleared.

GetStatus(out bool, out bool, out bool)

Reads all status bits.

View Source
Declaration
public void GetStatus(out bool alert, out bool conversionReady, out bool overflow)
Parameters
TypeNameDescription
System.Booleanalerttrue if the Alert condition was the source of the Alert pin output.
System.BooleanconversionReadytrue if all conversions and calculations are completed since last time this bit was read.
System.Booleanoverflowtrue indicates the internal arithmetic for Power may have exceeded the maximum of 419.43 W

Dispose(bool)

Dispose of the object

View Source
Declaration
protected override void Dispose(bool disposing)
Parameters
TypeNameDescription
System.BooleandisposingIs disposing

Events

AlertChanged

Raised when the Alert signal changes.

View Source
Declaration
public event EventHandler AlertChanged
Event Type

System.EventHandler

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