Class Ads1115
A Texas Instruments ADS1115 16-bit analog-to-digital converter, and a driver for one on an I2C bus.
public sealed class Ads1115 : IDisposable
- Inheritance
-
Ads1115
- Implements
- Inherited Members
Remarks
The static members are the part's datasheet, decoded exactly as the manufacturer specifies, and Ads1115.Sim, a part that is not there.
An instance drives one part over an I2cBus, converting one input on demand and leaving the part powered down between conversions. The part has no id register, so Init() writes the configuration and reads it back. Nothing is sent until Init() or the first Sample().
Constructors
Ads1115(I2cBus, byte, Mux, Pga, DataRate)
Creates a driver for the part at address on bus.
public Ads1115(I2cBus bus, byte address, Ads1115.Mux input = Mux.Ain0Ain1, Ads1115.Pga gain = Pga.Fsr2_048, Ads1115.DataRate rate = DataRate.Sps128)
Parameters
busI2cBusThe bus the part is on.
addressbyteOne of the
Addressconstants, by where ADDR is tied.inputAds1115.MuxThe input the part converts.
gainAds1115.PgaThe full-scale range, and with it the size of one count.
rateAds1115.DataRateThe data rate, and with it the conversion time and the noise.
Exceptions
- PamojaException
The native driver could not be created.
Fields
AddressGnd
The address with ADDR tied to ground.
public const byte AddressGnd = 72
Field Value
AddressScl
The address with ADDR tied to SCL.
public const byte AddressScl = 75
Field Value
AddressSda
The address with ADDR tied to SDA.
public const byte AddressSda = 74
Field Value
AddressVdd
The address with ADDR tied to VDD.
public const byte AddressVdd = 73
Field Value
ConfigReset
The value the configuration register reads after a reset.
public const ushort ConfigReset = 34179
Field Value
Properties
Config
The configuration the driver writes.
public Ads1115Config Config { get; }
Property Value
Methods
ConfigBits(Ads1115Config)
Assembles the 16-bit configuration register value.
public static ushort ConfigBits(Ads1115Config config)
Parameters
configAds1115ConfigThe settings to encode.
Returns
- ushort
The register value to write, most significant bit first.
ConfigFromBits(ushort)
Parses a 16-bit configuration register value.
public static Ads1115Config ConfigFromBits(ushort bits)
Parameters
bitsushortThe register value, as read from the device.
Returns
- Ads1115Config
The decoded settings. Every value decodes, so this never throws.
Exceptions
- PamojaException
The native call failed.
ConversionMicros(DataRate)
Returns how long a conversion takes at a data rate: one period plus the datasheet's ten percent variation.
public static uint ConversionMicros(Ads1115.DataRate rate)
Parameters
Returns
- uint
The time in microseconds.
Dispose()
Releases the driver and its share of the bus.
public void Dispose()
FullScaleMicrovolts(byte)
Returns the full-scale range a gain code selects.
public static uint FullScaleMicrovolts(byte pga)
Parameters
pgabyteThe gain code, 0 to 7.
Returns
- uint
The full scale in microvolts.
Init()
Writes the input, range, and data rate, and reads the configuration back.
public void Init()
Exceptions
- PamojaException
Nothing answered, or the configuration read back differently.
Sample()
Runs one conversion of the configured input, initializing the part first if needed.
public Ads1115Sample Sample()
Returns
- Ads1115Sample
The conversion, with the range it ran at.
Exceptions
- PamojaException
As Init(), and when the conversion never finishes.
SampleInput(Mux)
Converts another input once, leaving the configured input as it was.
public Ads1115Sample SampleInput(Ads1115.Mux input)
Parameters
Returns
- Ads1115Sample
The conversion.
Exceptions
SamplesPerSecond(byte)
Returns the sample rate a data-rate code selects.
public static ushort SamplesPerSecond(byte dataRate)
Parameters
dataRatebyteThe data-rate code, 0 to 7.
Returns
- ushort
The rate in samples per second.
ToNanovolts(byte, short)
Converts a raw conversion result to nanovolts.
public static long ToNanovolts(byte pga, short raw)
Parameters
Returns
- long
The measured voltage, exact at every gain setting.
ToVolts(byte, short)
Converts a raw conversion result to volts.
public static float ToVolts(byte pga, short raw)
Parameters
Returns
- float
The measured voltage.