Arduino library for the Texas Instruments ADS7128 8-channel, 12-bit analog-to-digital converter with integrated GPIO and programmable window comparator.
- 8 Analog Input Channels: 12-bit resolution (0-4095) ADC
- Dual Operating Modes: Manual or autonomous conversion
- Configurable GPIO: Each pin can be analog input, digital input, or digital output
- Window Comparator: Programmable high/low thresholds with hysteresis
- Alert System: Trigger GPIO pins based on analog threshold events
- I2C Interface: Flexible addressing (0x10-0x17)x
- Chip: Texas Instruments ADS7128
- Resolution: 12-bit (4096 levels)
- Channels: 8 analog inputs (can be configured as GPIO)
- Interface: I2C (up to 400 kHz)
- Supply Voltage: 2.7V to 5.5V
- Reference Voltage: Internal or external (up to AVDD)
#include <Wire.h>
#include "ADS7128.h"
// Enable debug output (Must Serial.begin() before adc.begin())
#define ADS7128_DEBUG 1
ADS7128 adc(0x10);
void setup() {
Serial.begin(115200);
Wire.begin();
adc.begin();
// Configure pin 7 as a digital input
adc.setPinMode(7, PIN_MODE_DIGITAL_INPUT);
}
void loop() {
bool state = adc.digitalRead(7);
Serial.print("Pin 7: ");
Serial.println(state ? "HIGH" : "LOW");
delay(500);
}#include <Wire.h>
#include "ADS7128.h"
// Enable debug output (Must Serial.begin() before adc.begin())
#define ADS7128_DEBUG 1
// Create ADS7128 instance (default I2C address: 0x10)
ADS7128 adc();
void setup() {
Serial.begin(115200);
Wire.begin();
// Initialize the ADC
if (!adc.begin()) {
Serial.println("ADS7128 not found!");
while(1);
}
// Configure pin 0 as analog input
adc.setPinMode(0, PIN_MODE_ANALOG_INPUT);
adc.adc.enableManualMode();
}
void loop() {
// Read analog value on pin 0(0-4095)
uint16_t value = adc.analogRead(0);
// Read voltage on pin 0 (assuming 3.3V reference)
float voltage = adc.analogReadVoltage(0, 3.3);
Serial.print("Value: ");
Serial.print(value);
Serial.print(" | Voltage: ");
Serial.print(voltage);
Serial.println(" V");
delay(1000);
}-
1: This library currently uses a less efficient register update method. The ADS7128 includes the ability to set or clear individual bits of a register through specific register commands. This allows for less I2C commands to be issued, as the typical read-set-write register operations do not need to be performed.
-
2: The continuous register block read and write are also not implemented, meaning each result must be read individually.
-
3: Additional features of the ADS7128 are missing: RMS, CRC, sample rate selection, I2C mode, OSR and some aspects of the zero crossing module.
-
4: Scale analogRead delay with the configured OSR ratio, or poll conversion done register.
- 1: The analogRead function while in Manual mode uses a fixed delay (delayMicroseconds(10)), this means if conversion is not complete before reading, the data will be stale.
Constructor. Creates an ADS7128 instance.
- i2cAddr: I2C address (default: 0x10, range: 0x10-0x17)
Initialize the device. Returns true if successful.
- wirePort: I2C bus to use (default: Wire)
Configure a pin's operating mode.
- pin: Pin number (0-7)
- mode:
PIN_MODE_ANALOG_INPUT,PIN_MODE_DIGITAL_INPUT, orPIN_MODE_DIGITAL_OUTPUT
Get the current pin mode.
Set output drive mode (for output pins only).
- mode:
DRIVE_MODE_OPEN_DRAINorDRIVE_MODE_PUSH_PULL
Read analog value from a channel (0-4095).
- channel: Channel number (0-7)
Read analog value as voltage.
- channel: Channel number (0-7)
- vref: Reference voltage in volts
Enable manual conversion mode. Conversions triggered on-demand.
- channels: Bit mask of channels to enable (e.g.,
0x03for channels 0 and 1)
Enable autonomous conversion mode. Continuous background conversions.
- channels: Bit mask of channels to enable
Write a digital value to an output pin.
- pin: Pin number (0-7)
- value:
true(HIGH) orfalse(LOW)
Read a digital value from an input pin. Returns true (HIGH) or false (LOW).
Enable or disable window comparator functionality.
bool setChannelWindow(uint8_t channel, float windowMax, float windowMin, uint8_t eventCount, float Vref = 3.3)
Configure window comparator thresholds for a channel.
- channel: Channel number (0-7)
- windowMax: Upper threshold voltage
- windowMin: Lower threshold voltage
- eventCount: Number of consecutive events before triggering (0-15)
- Vref: Reference voltage
Set hysteresis voltage to prevent threshold oscillation.
Define alert region (inside or outside window).
- regions: 0x00 for outside window, 0xFF for inside window
Configure alert pin behavior.
- drive: Drive mode (0 = open-drain, 1 = push-pull)
- logic: Logic configuration (0-3)
Select which channels can trigger alerts.
- channels: Bit mask of channels
Enable GPIO pins to be triggered by alerts.
- pins: Bit mask of pins
Map alert sources to a specific GPIO pin.
- pin: GPIO pin number (0-7)
- alerts: Bit mask of alert sources
Set the output value when a pin is triggered.
- pin: Pin number (0-7)
- state: Value to set on trigger
Get device status. Returns a SystemStatus struct with:
bool sequenceActive: Conversion sequence activebool highSpeedI2C: High-speed I2C modebool osrDone: Oversampling completebool crcError: CRC error detectedbool powerOnReset: Power-on reset occurreduint8_t rawValue: Raw status register value
Check if device is ready for operation.
Clear the power-on reset flag.
Perform a software reset.
Write to a register directly.
Read from a register directly.
See examples/ManualReadings/ManualReadings.ino
See examples/ManualReadings/ManualReadings.ino
See examples/ManualReadings/ManualReadings.ino
The ADS7128 I2C address is determined by the ADDR pin:
| ADDR Pin | I2C Address |
|---|---|
| Floating | 0x10 |
| AVDD/8 | 0x11 |
| 2×AVDD/8 | 0x12 |
| 3×AVDD/8 | 0x13 |
| 4×AVDD/8 | 0x14 |
| 5×AVDD/8 | 0x15 |
| 6×AVDD/8 | 0x16 |
| 7×AVDD/8 | 0x17 |
- Wire: Arduino I2C library (included with Arduino core)
This project is licensed under the MIT License - see the LICENSE file for details.