Simple test

Ensure your device works with this simple test.

examples/ads7128_simpletest.py
 1# SPDX-FileCopyrightText: 2026 Liz Clark for Adafruit Industries
 2#
 3# SPDX-License-Identifier: MIT
 4
 5"""Simple analog read example for the ADS7128.
 6
 7Reads a single channel and prints the 16-bit value and the voltage.
 8"""
 9
10import time
11
12import board
13
14from adafruit_ads7128.ads7128 import ADS7128
15from adafruit_ads7128.analog_in import AnalogIn
16
17# Reference voltage
18REFERENCE_VOLTAGE = 3.3
19
20i2c = board.I2C()
21adc = ADS7128(i2c)
22
23# analog input on channel 0
24channel = AnalogIn(adc, 0)
25
26while True:
27    print(f"value: {channel.value}  voltage: {channel.voltage(REFERENCE_VOLTAGE):.3f} V")
28    time.sleep(1.0)

Digital in/out test

Test digital input and output

examples/ads7128_digital_in_out.py
 1# SPDX-FileCopyrightText: 2026 Liz Clark for Adafruit Industries
 2#
 3# SPDX-License-Identifier: MIT
 4
 5"""Digital I/O example for the ADS7128: a button controls an LED.
 6
 7Wiring:
 8  * Channel 0 -> a button (digital input)
 9  * Channel 1 -> an LED (digital output)
10
11The ADS7128 has no internal pull resistors, so the button needs an external
12one. This example assumes an external pull-UP resistor on the button, so the
13input reads ``False`` (low) while the button is pressed and ``True`` when it
14is released.
15"""
16
17import time
18
19import board
20
21from adafruit_ads7128.ads7128 import ADS7128
22from adafruit_ads7128.digital_inout import DigitalInOut
23
24BUTTON_PIN = 0
25LED_PIN = 1
26
27i2c = board.I2C()
28adc = ADS7128(i2c)
29
30# Channel 0 as a digital input. pull must be None; the ADS7128 has no
31# internal pull resistors, so use an external pull-down on the button.
32button = DigitalInOut(adc, BUTTON_PIN)
33button.switch_to_input()
34
35# Channel 1 as a digital output, starting low (LED off).
36led = DigitalInOut(adc, LED_PIN)
37led.switch_to_output(value=False)
38
39while True:
40    if not button.value:
41        led.value = True  # LED on while the button is pressed
42    else:
43        led.value = False
44    time.sleep(0.01)