API Reference

ADS7128

CircuitPython driver for the Adafruit ADS7128 8-Channel ADC and GPIO Expander

  • Author(s): Liz Clark

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_ads7128.ads7128.ADS7128(i2c: busio.I2C, address: int = _DEFAULT_ADDR)

Driver for the ADS7128 8-channel 12-bit ADC with GPIOs.

Parameters:
  • i2c (I2C) – The I2C bus the ADS7128 is connected to.

  • address (int) – The I2C address of the device. Defaults to 0x10.

property alert_channels: int

Bitmask of channels that can trigger the ALERT pin (bit 0 = CH0).

property alert_logic: int

0=active low, 1=active high, 2=pulsed low, 3=pulsed high.

Type:

ALERT pin logic

property alert_push_pull: bool

True for push-pull, False for open-drain.

Type:

ALERT pin drive

clear_crc_error() None

Clear the CRC error flag.

clear_event_flags() None

Clear all high and low threshold event flags.

property clock_divider: int

Autonomous-mode sampling clock divider, 0-15.

property crc_enabled: bool

Whether CRC validation of I2C transactions is enabled.

property crc_error: bool

True if a CRC error has been detected on the I2C interface. (read-only)

property dwc_enabled: bool

Whether the digital window comparator is enabled.

property event_flags: int

Combined high/low threshold event flags, one bit per channel. (read-only)

property event_high_flags: int

High threshold event flags, one bit per channel. (read-only)

property event_low_flags: int

Low threshold event flags, one bit per channel. (read-only)

property gpi_value: int

Digital input level bitmask, one bit per channel. (read-only)

property gpio_cfg: int

Per-channel digital direction bitmask (bit set = output, clear = input).

property gpo_drive_cfg: int

Per-channel output drive bitmask (bit set = push-pull, clear = open-drain).

property gpo_value: int

Digital output level bitmask, one bit per channel.

property gpo_zcd_update_en: int

Per-channel zero-crossing-to-GPO update enable bitmask.

property low_power_oscillator: bool

Use the low-power oscillator (True) or high-speed oscillator (False).

property oversampling: int

Oversampling ratio (0-7). See the OSR_* module constants.

property pin_cfg: int

Per-channel analog (bit clear) / digital (bit set) selection bitmask.

read_sequence_result() Tuple[int, int]

Read the next conversion result from the running sequence.

Returns:

A (value, channel) tuple where value is the 12-bit conversion result and channel is the channel it came from.

Return type:

tuple

reset_statistics() None

Clear all recorded statistics and restart recording.

property rms: int

The 16-bit RMS result over the configured number of samples. (read-only)

property rms_channel: int

Analog channel the RMS module monitors, 0-7.

property rms_dc_subtract: bool

Whether the DC component is subtracted before the RMS calculation.

property rms_done: bool

True if the RMS computation is complete. Reading clears the flag. (read-only)

property rms_enabled: bool

Whether the RMS computation module is enabled.

Setting this to True clears any previous result and starts a new computation using samples from autonomous conversion mode.

property rms_samples: int

0=1024, 1=4096, 2=16384, 3=65536 samples.

Type:

RMS sample-count setting

property sequence_channels: int

Bitmask of channels included in the auto-sequence (bit 0 = CH0).

start_sequence() None

Start autonomous auto-sequence conversions on the selected channels.

property statistics_enabled: bool

Whether min/max/recent statistics tracking is enabled.

stop_sequence() None

Stop the auto-sequence.

property zcd_blanking: int

Zero-crossing blanking count, 0-127 (conversions skipped after an event).

property zcd_blanking_multiply: bool

When True, the zero-crossing blanking count is multiplied by 8.

property zcd_channel: int

Analog channel monitored by the zero-crossing detector, 0-7.

adafruit_ads7128.ads7128.OSR_128 = 7

128x oversampling (16-bit result).

adafruit_ads7128.ads7128.OSR_16 = 4

16x oversampling (16-bit result).

adafruit_ads7128.ads7128.OSR_2 = 1

2x oversampling (13-bit result).

adafruit_ads7128.ads7128.OSR_32 = 5

32x oversampling (16-bit result).

adafruit_ads7128.ads7128.OSR_4 = 2

4x oversampling (14-bit result).

adafruit_ads7128.ads7128.OSR_64 = 6

64x oversampling (16-bit result).

adafruit_ads7128.ads7128.OSR_8 = 3

8x oversampling (15-bit result).

adafruit_ads7128.ads7128.OSR_NONE = 0

No oversampling (12-bit result).

AnalogIn

AnalogIn for ADC readings.

  • Author(s): Liz Clark

class adafruit_ads7128.analog_in.AnalogIn(adc: ADS7128, pin: int)

AnalogIn-compatible wrapper for ADS7128 single-ended readings.

Provides a value property scaled to a 16-bit unsigned range [0, 65535] and a voltage property in volts, matching the CircuitPython analogio.AnalogIn API.

Parameters:
  • adc (ADS7128) – The ADS7128 driver instance.

  • pin (int) – Channel number (0-7).

property event_count: int

Consecutive samples before an alert triggers, 0-15 (alert after count + 1).

property event_region: bool

True for in-band, False for out-of-window.

Type:

Comparator event region

property high_threshold: int

Window-comparator high threshold for this channel, in 12-bit counts (0-4095).

property hysteresis: int

Window-comparator hysteresis for this channel, 0-15.

property low_threshold: int

Window-comparator low threshold for this channel, in 12-bit counts (0-4095).

property max: int

Maximum value recorded on this channel, in 12-bit counts. (read-only)

Requires ADS7128.statistics_enabled to be True.

property min: int

Minimum value recorded on this channel, in 12-bit counts. (read-only)

Requires ADS7128.statistics_enabled to be True.

property recent: int

Most recent conversion recorded on this channel, in 12-bit counts. (read-only)

Requires ADS7128.statistics_enabled to be True.

property value: int

ADC reading as an unsigned 16-bit integer in the range [0, 65535].

The 12-bit conversion result is scaled to 16 bits to match the analogio.AnalogIn API.

voltage(reference_voltage: float = 5.0) float

Read the channel and convert the result to volts.

Parameters:

reference_voltage (float) – ADC reference voltage in volts. Defaults to 5.0 to match the device’s default reference.

Returns:

The measured voltage in volts.

Return type:

float

DigitalInOut

Digital input/output of the ADS7128.

  • Author(s): Liz Clark

class adafruit_ads7128.digital_inout.DigitalInOut(adc: ADS7128, pin: int)

Digital input/output of the ADS7128. The interface is the same as the digitalio.DigitalInOut class, however:

  • the ADS7128 does not support pull-up or pull-down resistors;

  • a channel used here is taken out of analog mode.

Open-drain outputs are supported through drive_mode. A ValueError is raised when attempting to set an unsupported pull configuration.

Parameters:
  • adc (ADS7128) – The ADS7128 driver instance.

  • pin (int) – Channel number (0-7).

property direction: digitalio.Direction

The direction of the pin, either digitalio.Direction.INPUT or digitalio.Direction.OUTPUT.

property drive_mode: digitalio.DriveMode

The output drive mode, either digitalio.DriveMode.PUSH_PULL or digitalio.DriveMode.OPEN_DRAIN.

switch_to_input(pull: digitalio.Pull = None, **kwargs) None

Switch the pin to a digital input.

Parameters:

pull (Pull) – Must be None; pull resistors are not supported and any other value raises ValueError.

switch_to_output(value: bool = False, drive_mode: digitalio.DriveMode = digitalio.DriveMode.PUSH_PULL, **kwargs) None

Switch the pin to a digital output with the given starting value and drive mode (push-pull by default).

Parameters:
  • value (bool) – Initial output level. Defaults to False (low).

  • drive_mode (DriveMode) – Output drive mode.

property value: bool

The value of the pin, either True for high or False for low.

Configure the pin as an output or input before writing or reading this.

property zcd_output: int

Zero-crossing-detector output mode mapped onto this GPO pin.

0=low, 1=high, 2=ZCD signal, 3=inverted ZCD. Use with zcd_output_enabled.

property zcd_output_enabled: bool

Whether the zero-crossing detector drives this GPO pin.