Table of Contents

Class Ads1115

Namespace
Pamoja.Sensors
Assembly
Pamoja.Sensors.dll

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

bus I2cBus

The bus the part is on.

address byte

One of the Address constants, by where ADDR is tied.

input Ads1115.Mux

The input the part converts.

gain Ads1115.Pga

The full-scale range, and with it the size of one count.

rate Ads1115.DataRate

The 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

byte

AddressScl

The address with ADDR tied to SCL.

public const byte AddressScl = 75

Field Value

byte

AddressSda

The address with ADDR tied to SDA.

public const byte AddressSda = 74

Field Value

byte

AddressVdd

The address with ADDR tied to VDD.

public const byte AddressVdd = 73

Field Value

byte

ConfigReset

The value the configuration register reads after a reset.

public const ushort ConfigReset = 34179

Field Value

ushort

Properties

Config

The configuration the driver writes.

public Ads1115Config Config { get; }

Property Value

Ads1115Config

Methods

ConfigBits(Ads1115Config)

Assembles the 16-bit configuration register value.

public static ushort ConfigBits(Ads1115Config config)

Parameters

config Ads1115Config

The 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

bits ushort

The 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

rate Ads1115.DataRate

The data rate.

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

pga byte

The 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

input Ads1115.Mux

The input for this one conversion.

Returns

Ads1115Sample

The conversion.

Exceptions

PamojaException

As Sample().

SamplesPerSecond(byte)

Returns the sample rate a data-rate code selects.

public static ushort SamplesPerSecond(byte dataRate)

Parameters

dataRate byte

The 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

pga byte

The gain the conversion was taken at.

raw short

The signed conversion register value.

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

pga byte

The gain the conversion was taken at.

raw short

The signed conversion register value.

Returns

float

The measured voltage.