Class Ads1115
Analog-to-Digital Converter ADS1115.
public class Ads1115
- Inheritance
-
Ads1115
Constructors
Ads1115(I2cDevice, InputMultiplexer, MeasuringRange, DataRate, DeviceMode)
Initializes a new instance of the Ads1115 class connected through I2C.
public Ads1115(I2cDevice i2cDevice, InputMultiplexer inputMultiplexer = InputMultiplexer.AIN0, MeasuringRange measuringRange = MeasuringRange.FS4096, DataRate dataRate = DataRate.SPS128, DeviceMode deviceMode = DeviceMode.Continuous)
Parameters
i2cDevice
I2cDeviceThe I2C device used for communication.
inputMultiplexer
InputMultiplexerInput Multiplexer.
measuringRange
MeasuringRangeProgrammable Gain Amplifier.
dataRate
DataRateData Rate.
deviceMode
DeviceModeInitial device mode.
Ads1115(I2cDevice, GpioController?, int, bool, InputMultiplexer, MeasuringRange, DataRate, DeviceMode)
Initializes a new instance of the Ads1115 class connected through I2C with an additional GPIO controller for interrupt handling.
public Ads1115(I2cDevice i2cDevice, GpioController? gpioController, int gpioInterruptPin, bool shouldDispose = true, InputMultiplexer inputMultiplexer = InputMultiplexer.AIN0, MeasuringRange measuringRange = MeasuringRange.FS4096, DataRate dataRate = DataRate.SPS128, DeviceMode deviceMode = DeviceMode.Continuous)
Parameters
i2cDevice
I2cDeviceThe I2C device used for communication.
gpioController
GpioControllerThe GPIO Controller used for interrupt handling.
gpioInterruptPin
intThe pin number where the interrupt line is attached on the GPIO controller.
shouldDispose
boolTrue (the default) if the GPIO controller shall be disposed when disposing this instance.
inputMultiplexer
InputMultiplexerInput Multiplexer.
measuringRange
MeasuringRangeProgrammable Gain Amplifier.
dataRate
DataRateData Rate.
deviceMode
DeviceModeInitial device mode.
Properties
ComparatorLatching
Gets or sets comparator latching mode. If enabled, the ALRT/RDY Pin will be kept signaled until the conversion value is read. Only relevant when the comparator is enabled.
public ComparatorLatching ComparatorLatching { get; set; }
Property Value
ComparatorMode
Gets Comparator mode. Only relevant if the comparator trigger event is set up and is changed by EnableComparator(short, short, ComparatorMode, ComparatorQueue).
public ComparatorMode ComparatorMode { get; }
Property Value
ComparatorPolarity
Gets or sets comparator polarity. Indicates whether the rising or the falling edge of the ALRT/RDY Pin is relevant. Default: Low (falling edge).
public ComparatorPolarity ComparatorPolarity { get; set; }
Property Value
ComparatorQueue
Minimum number of samples exceeding the lower/upper threshold before the ALRT pin is asserted. This can only be set with EnableComparator(short, short, ComparatorMode, ComparatorQueue).
public ComparatorQueue ComparatorQueue { get; }
Property Value
DataRate
Gets or sets ADS1115 Data Rate. The number of conversions per second that will take place. One conversion will take "1/rate" seconds to become ready. If in power-down mode, only one conversion will happen automatically, then another request is required. Setting this property will wait until a new value is available.
public DataRate DataRate { get; set; }
Property Value
DeviceMode
Gets or sets ADS1115 operation mode. When set to Continuous the chip continously measures the input and the values can be read directly. If set to PowerDown the chip enters idle mode after each conversion and a new value will be requested each time a read request is performed. This is the recommended setting when frequently swapping between input channels, because a change of the channel requires a new conversion anyway.
public DeviceMode DeviceMode { get; set; }
Property Value
InputMultiplexer
Gets or sets ADS1115 Input Multiplexer. This selects the channel(s) for the next read operation, InputMultiplexer. Setting this property will wait until a value is available from the newly selected input channel.
public InputMultiplexer InputMultiplexer { get; set; }
Property Value
MeasuringRange
Gets or sets ADS1115 Programmable Gain Amplifier This sets the maximum value that can be measured. Regardless of this setting, the input value on any pin must not exceed VDD + 0.3V, so high ranges are only usable with a VDD of more than 5V. Setting this property will wait until a new value is available.
public MeasuringRange MeasuringRange { get; set; }
Property Value
Methods
Dispose()
Cleanup. Failing to dispose this class, especially when callbacks are active, may lead to undefined behavior.
public void Dispose()
EnableComparator(short, short, ComparatorMode, ComparatorQueue)
Enable comparator callback mode. In traditional comparator mode, the callback is triggered each time the measured value exceeds the given upper value (for the given queueLength number of samples). It deasserts when the lower value is reached. In window comparator mode, the callback is triggered each time the measured value exceeds the given upper value or gets less than the given lower value.
public void EnableComparator(short lowerValue, short upperValue, ComparatorMode mode, ComparatorQueue queueLength)
Parameters
lowerValue
shortLower value for the comparator.
upperValue
shortUpper value for the comparator.
mode
ComparatorModeTraditional or Window comparator mode.
queueLength
ComparatorQueueMinimum number of samples that must exceed the threshold to trigger the event.
Exceptions
- InvalidOperationException
The GPIO Controller for the interrupt handler has not been set up.
EnableComparator(ElectricPotential, ElectricPotential, ComparatorMode, ComparatorQueue)
Enable comparator callback mode. In traditional comparator mode, the callback is triggered each time the measured value exceeds the given upper value (for the given queueLength number of samples). It deasserts when the lower value is reached. In window comparator mode, the callback is triggered each time the measured value exceeds the given upper value or gets less than the given lower value.
public void EnableComparator(ElectricPotential lowerValue, ElectricPotential upperValue, ComparatorMode mode, ComparatorQueue queueLength)
Parameters
lowerValue
ElectricPotentialLower value for the comparator.
upperValue
ElectricPotentialUpper value for the comparator.
mode
ComparatorModeTraditional or Window comparator mode.
queueLength
ComparatorQueueMinimum number of samples that must exceed the threshold to trigger the event.
Exceptions
- InvalidOperationException
The GPIO Controller for the interrupt handler has not been set up.
EnableConversionReady()
Enable conversion ready event. The AlertReadyAsserted event fires each time a new value is available after this method is called.
public void EnableConversionReady()
Exceptions
- InvalidOperationException
The conversion ready event is already set up or no GPIO Controller configured for interrupt handling.
FrequencyFromDataRate(DataRate)
Returns the sampling frequency in Hz for the given data rate enumeration member.
public double FrequencyFromDataRate(DataRate dataRate)
Parameters
Returns
- double
A frequency, in Hertz.
MaxVoltageFromMeasuringRange(MeasuringRange)
Returns the voltage assigned to the given MeasuringRange enumeration value.
public ElectricPotential MaxVoltageFromMeasuringRange(MeasuringRange measuringRange)
Parameters
measuringRange
MeasuringRangeOne of the MeasuringRange enumeration members.
Returns
- ElectricPotential
An electric potential (voltage).
RawToVoltage(short)
Convert Raw Data to Voltage.
public ElectricPotential RawToVoltage(short val)
Parameters
val
shortRaw Data.
Returns
- ElectricPotential
Voltage, based on the current measuring range.
ReadRaw()
Read Raw Data. If in PowerDown (single-shot) mode, one new sample is requested first.
public short ReadRaw()
Returns
- short
Raw Value.
ReadRaw(InputMultiplexer)
Reads the next raw value, first switching to the given input and ranges.
public short ReadRaw(InputMultiplexer inputMultiplexer)
Parameters
inputMultiplexer
InputMultiplexerNew input multiplexer setting.
Returns
- short
Measured value as short.
Remarks
For performance reasons, it is advised to use this method if quick readings with different input channels are required, instead of setting all the properties first and then calling ReadRaw().
ReadRaw(InputMultiplexer, MeasuringRange, DataRate)
Reads the next raw value, first switching to the given input and ranges.
public short ReadRaw(InputMultiplexer inputMultiplexer, MeasuringRange measuringRange, DataRate dataRate)
Parameters
inputMultiplexer
InputMultiplexerNew input multiplexer setting.
measuringRange
MeasuringRangeNew measuring range.
dataRate
DataRateNew data rate.
Returns
- short
Measured value as short.
Remarks
For performance reasons, it is advised to use this method if quick readings with different settings (i.e. different input channels) are required, instead of setting all the properties first and then calling ReadRaw().
ReadVoltage()
Returns the electric potential (voltage) of the currently selected input.
public ElectricPotential ReadVoltage()
Returns
- ElectricPotential
The measured voltage of the currently selected input channel. In volts.
ReadVoltage(InputMultiplexer)
Returns the electric potential (voltage) of the given channel, performs a measurement first.
public ElectricPotential ReadVoltage(InputMultiplexer inputMultiplexer)
Parameters
inputMultiplexer
InputMultiplexerChannel to use.
Returns
- ElectricPotential
The voltage at the selected channel.
VoltageToRaw(ElectricPotential)
Converts voltage to raw data.
public short VoltageToRaw(ElectricPotential voltage)
Parameters
voltage
ElectricPotentialInput voltage.
Returns
- short
Corresponding raw value, based on the current measuring range.
Events
AlertReadyAsserted
This event fires when a new value is available (in conversion ready mode) or the comparator threshold is exceeded. Requires setup through EnableConversionReady() or EnableComparator(ElectricPotential, ElectricPotential, ComparatorMode, ComparatorQueue).
public event Action? AlertReadyAsserted