import ads1115
The ads1115 module reads ADS1115-compatible 4-channel ADC boards over I2C. It supports single-ended reads, valid ADS1115 differential channel pairs, per-reading gain/data-rate overrides, continuous conversions, and the ADS1115 comparator.
Quick example
import ads1115 adc = ads1115.ADS1115(sda=21, scl=22, address=0x48) reading = adc.read(0) print(reading["raw"]) print(reading["voltage_v"]) battery = adc.voltage(channel=1, gain=6.144) adc.configure(gain=4.096, data_rate=128, mode="single") diff = adc.read_diff(positive=0, negative=1) print(diff["voltage_v"])
importads1115
ADS1115 16-bit I2C analog-to-digital converter module.
The ads1115 module reads ADS1115-compatible 4-channel ADC boards over I2C. It supports single-ended reads, valid ADS1115 differential channel pairs, per-reading gain/data-rate overrides, continuous conversions, and the ADS1115 comparator.
ads1115.ADS1115(sda: int, scl: int, address: int = None, frequency: int = None, port: int = None) -> ads1115_adc
ads1115.ADS1115(sda: int, scl: int, address: int = None, frequency: int = None, port: int = None) -> ads1115_adcCreate and initialize an independent ADS1115 ADC.
Use one ADS1115 object for each physical ADC board. Multiple ADS1115 devices can share one I2C bus when each board has a unique address.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
sda |
int |
positional or keyword | Yes | GPIO pin used for I2C SDA. |
scl |
int |
positional or keyword | Yes | GPIO pin used for I2C SCL. |
address |
int |
positional or keyword | No | Optional I2C address. Defaults to 0x48. |
frequency |
int |
positional or keyword | No | Optional I2C bus speed in hertz. Defaults to 100000. |
port |
int |
positional or keyword | No | Optional ESP-IDF I2C port number. Defaults to 0. |
ads1115_adc ads1115_adc object.
ads1115.ADS1115().configure(gain=None, data_rate=None, mode=None) -> bool
ads1115.ADS1115().configure(gain=None, data_rate=None, mode=None) -> boolSet default conversion range, data rate, and mode for this ADC.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
gain |
int |
positional or keyword | No | Optional value. Defaults to None. |
data_rate |
int |
positional or keyword | No | Optional value. Defaults to None. |
mode |
str |
positional or keyword | No | Optional value. Defaults to None. |
ads1115.ADS1115().read(channel, gain=None, data_rate=None) -> dict
ads1115.ADS1115().read(channel, gain=None, data_rate=None) -> dictRead one single-ended channel and return raw and voltage values.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
channel |
int |
positional or keyword | Yes | Required value. |
gain |
int |
positional or keyword | No | Optional value. Defaults to None. |
data_rate |
int |
positional or keyword | No | Optional value. Defaults to None. |
ads1115.ADS1115().voltage(channel, gain=None, data_rate=None) -> float
ads1115.ADS1115().voltage(channel, gain=None, data_rate=None) -> floatRead one single-ended channel and return volts.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
channel |
int |
positional or keyword | Yes | Required value. |
gain |
int |
positional or keyword | No | Optional value. Defaults to None. |
data_rate |
int |
positional or keyword | No | Optional value. Defaults to None. |
ads1115.ADS1115().read_diff(positive, negative, gain=None, data_rate=None) -> dict
ads1115.ADS1115().read_diff(positive, negative, gain=None, data_rate=None) -> dictRead a valid differential input pair.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
positive |
int |
positional or keyword | Yes | Required value. |
negative |
int |
positional or keyword | Yes | Required value. |
gain |
int |
positional or keyword | No | Optional value. Defaults to None. |
data_rate |
int |
positional or keyword | No | Optional value. Defaults to None. |
ads1115.ADS1115().voltage_diff(positive, negative, gain=None, data_rate=None) -> float
ads1115.ADS1115().voltage_diff(positive, negative, gain=None, data_rate=None) -> floatRead a valid differential pair and return volts.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
positive |
int |
positional or keyword | Yes | Required value. |
negative |
int |
positional or keyword | Yes | Required value. |
gain |
int |
positional or keyword | No | Optional value. Defaults to None. |
data_rate |
int |
positional or keyword | No | Optional value. Defaults to None. |
ads1115.ADS1115().start(channel, continuous=None) -> bool
ads1115.ADS1115().start(channel, continuous=None) -> boolStart a single-ended conversion without waiting for the value.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
channel |
int |
positional or keyword | Yes | Required value. |
continuous |
bool |
positional or keyword | No | Optional value. Defaults to None. |
ads1115.ADS1115().start_diff(positive, negative, continuous=None) -> bool
ads1115.ADS1115().start_diff(positive, negative, continuous=None) -> boolStart a differential conversion without waiting for the value.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
positive |
int |
positional or keyword | Yes | Required value. |
negative |
int |
positional or keyword | Yes | Required value. |
continuous |
bool |
positional or keyword | No | Optional value. Defaults to None. |
ads1115.ADS1115().ready() -> bool
ads1115.ADS1115().ready() -> boolCheck whether the current conversion is ready.
ads1115.ADS1115().last() -> dict
ads1115.ADS1115().last() -> dictRead the latest conversion register without starting a new conversion.
ads1115.ADS1115().set_comparator(channel, high_threshold, low_threshold=None, latching=None, active_high=None, window=None, queue=None) -> bool
ads1115.ADS1115().set_comparator(channel, high_threshold, low_threshold=None, latching=None, active_high=None, window=None, queue=None) -> boolEnable the comparator for one single-ended channel.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
channel |
int |
positional or keyword | Yes | Required value. |
high_threshold |
int |
positional or keyword | Yes | Required value. |
low_threshold |
int |
positional or keyword | No | Optional value. Defaults to None. |
latching |
bool |
positional or keyword | No | Optional value. Defaults to None. |
active_high |
bool |
positional or keyword | No | Optional value. Defaults to None. |
window |
bool |
positional or keyword | No | Optional value. Defaults to None. |
queue |
int |
positional or keyword | No | Optional value. Defaults to None. |
ads1115.ADS1115().disable_comparator() -> bool
ads1115.ADS1115().disable_comparator() -> boolDisable the comparator.
ads1115.ADS1115().reset() -> bool
ads1115.ADS1115().reset() -> boolRestore this ADC's defaults.
ads1115.ADS1115().info() -> dict
ads1115.ADS1115().info() -> dictReturn I2C, gain, mode, comparator, and last-channel state for this ADC.
ads1115.ADS1115().close() -> bool
ads1115.ADS1115().close() -> boolRelease this ADS1115 handle.
ads1115.ADS1115().Example
ads1115.ADS1115().Exampleadc = ads1115.ADS1115(sda=21, scl=22) print(adc.voltage(0))
ads1115.begin(sda: int, scl: int, address: int = None, frequency: int = None, port: int = None) -> bool
ads1115.begin(sda: int, scl: int, address: int = None, frequency: int = None, port: int = None) -> boolLegacy: initialize the module-level default ADS1115 ADC.
Prefer ``adc = ads1115.ADS1115(...)`` for new projects. The legacy wrapper keeps older singleton-style scripts working.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
sda |
int |
positional or keyword | Yes | GPIO pin used for I2C SDA. |
scl |
int |
positional or keyword | Yes | GPIO pin used for I2C SCL. |
address |
int |
positional or keyword | No | Optional I2C address. Defaults to 0x48. |
frequency |
int |
positional or keyword | No | Optional I2C bus speed in hertz. Defaults to 100000. |
port |
int |
positional or keyword | No | Optional ESP-IDF I2C port number. Defaults to 0. |
bool True when the device acknowledges the initial ADS1115 register setup.
ads1115.configure(gain: float = None, data_rate: int = None, mode: str = None) -> bool
ads1115.configure(gain: float = None, data_rate: int = None, mode: str = None) -> boolSet the default ADS1115 conversion settings.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
gain |
float |
positional or keyword | No | Optional full-scale input range in volts. Use 6.144, 4.096, 2.048, 1.024, 0.512, or 0.256. Defaults to 4.096. |
data_rate |
int |
positional or keyword | No | Optional samples per second. Use 8, 16, 32, 64, 128, 250, 475, or 860. Defaults to 128. |
mode |
str |
positional or keyword | No | Optional conversion mode. Use "single" or "continuous". Defaults to "single". |
bool True when the config register is written.
ads1115.read(channel: int, gain: float = None, data_rate: int = None) -> dict
ads1115.read(channel: int, gain: float = None, data_rate: int = None) -> dictRead one single-ended channel and return raw and voltage values.
This performs a blocking single conversion. Use a lower gain value, such as 0.256, for small signals and a larger range, such as 6.144, when the input can be higher.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
channel |
int |
positional or keyword | Yes | Single-ended ADC input channel. Use 0, 1, 2, or 3. |
gain |
float |
positional or keyword | No | Optional full-scale input range in volts for this read only. |
data_rate |
int |
positional or keyword | No | Optional samples per second for this read only. |
dict Dict with ``ok``, ``raw``, ``voltage``, ``voltage_v``, ``channel``, ``positive``, ``negative``, ``differential``, ``ready``, ``gain``, ``fsr_v``, ``data_rate``, ``mode``, and ``address`` fields.
ads1115.voltage(channel: int, gain: float = None, data_rate: int = None) -> float
ads1115.voltage(channel: int, gain: float = None, data_rate: int = None) -> floatRead one single-ended channel and return volts.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
channel |
int |
positional or keyword | Yes | Single-ended ADC input channel. Use 0, 1, 2, or 3. |
gain |
float |
positional or keyword | No | Optional full-scale input range in volts for this read only. |
data_rate |
int |
positional or keyword | No | Optional samples per second for this read only. |
float Float measured input voltage in volts.
ads1115.read_diff(positive: int, negative: int, gain: float = None, data_rate: int = None) -> dict
ads1115.read_diff(positive: int, negative: int, gain: float = None, data_rate: int = None) -> dictRead a valid ADS1115 differential input pair.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
positive |
int |
positional or keyword | Yes | Positive differential input channel. |
negative |
int |
positional or keyword | Yes | Negative differential input channel. Valid pairs are 0-1, 0-3, 1-3, and 2-3. |
gain |
float |
positional or keyword | No | Optional full-scale input range in volts for this read only. |
data_rate |
int |
positional or keyword | No | Optional samples per second for this read only. |
dict Dict with the same fields as ``read()``, with ``differential`` set to True and ``positive``/``negative`` set to the selected pair.
ads1115.voltage_diff(positive: int, negative: int, gain: float = None, data_rate: int = None) -> float
ads1115.voltage_diff(positive: int, negative: int, gain: float = None, data_rate: int = None) -> floatRead a valid ADS1115 differential pair and return volts.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
positive |
int |
positional or keyword | Yes | Positive differential input channel. |
negative |
int |
positional or keyword | Yes | Negative differential input channel. Valid pairs are 0-1, 0-3, 1-3, and 2-3. |
gain |
float |
positional or keyword | No | Optional full-scale input range in volts for this read only. |
data_rate |
int |
positional or keyword | No | Optional samples per second for this read only. |
float Float differential voltage in volts.
ads1115.start(channel: int, continuous: bool = None) -> bool
ads1115.start(channel: int, continuous: bool = None) -> boolStart a single-ended conversion without waiting for the value.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
channel |
int |
positional or keyword | Yes | Single-ended ADC input channel. Use 0, 1, 2, or 3. |
continuous |
bool |
positional or keyword | No | Optional mode flag. True starts continuous conversion, False starts one single-shot conversion. Defaults to False. |
bool True when the conversion command is written.
ads1115.start_diff(positive: int, negative: int, continuous: bool = None) -> bool
ads1115.start_diff(positive: int, negative: int, continuous: bool = None) -> boolStart a differential conversion without waiting for the value.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
positive |
int |
positional or keyword | Yes | Positive differential input channel. |
negative |
int |
positional or keyword | Yes | Negative differential input channel. Valid pairs are 0-1, 0-3, 1-3, and 2-3. |
continuous |
bool |
positional or keyword | No | Optional mode flag. True starts continuous conversion, False starts one single-shot conversion. Defaults to False. |
bool True when the conversion command is written.
ads1115.ready() -> bool
ads1115.ready() -> boolCheck whether the current ADS1115 conversion is ready.
bool True when the ADS1115 ready bit says the conversion is complete.
ads1115.last() -> dict
ads1115.last() -> dictRead the latest conversion register without starting a new conversion.
dict Dict with the same fields as ``read()`` for the last started channel or differential pair.
ads1115.set_comparator(channel: int, high_threshold: int, low_threshold: int = None, latching: bool = None, active_high: bool = None, window: bool = None, queue: int = None) -> bool
ads1115.set_comparator(channel: int, high_threshold: int, low_threshold: int = None, latching: bool = None, active_high: bool = None, window: bool = None, queue: int = None) -> boolEnable the ADS1115 comparator for one single-ended channel.
Threshold values are raw ADC counts, not volts. The comparator runs in continuous conversion mode after this call.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
channel |
int |
positional or keyword | Yes | Single-ended ADC input channel. Use 0, 1, 2, or 3. |
high_threshold |
int |
positional or keyword | Yes | Raw high threshold value from -32768 through 32767. |
low_threshold |
int |
positional or keyword | No | Optional raw low threshold value. Defaults to 0. |
latching |
bool |
positional or keyword | No | Optional latch mode. True keeps alert asserted until read. |
active_high |
bool |
positional or keyword | No | Optional alert polarity. True makes ALERT/RDY active high. |
window |
bool |
positional or keyword | No | Optional comparator mode. True uses window comparison, False uses traditional high-threshold comparison. |
queue |
int |
positional or keyword | No | Optional comparator queue count. Use 1, 2, or 4. |
bool True when threshold and config registers are written.
ads1115.disable_comparator() -> bool
ads1115.disable_comparator() -> boolDisable the ADS1115 comparator.
bool True when the comparator queue-disable bits are written.
ads1115.reset() -> bool
ads1115.reset() -> boolRestore the ADS1115 module defaults.
bool True when thresholds and the default config register are written.
ads1115.info() -> dict
ads1115.info() -> dictReturn ADS1115 module state.
dict Dict with initialization state, I2C settings, gain, full-scale range, data rate, mode, comparator state, and last selected channel or differential pair.