### Write to Setup Register for Calibration Source: https://context7.com/kerrydwong/ad770x/llms.txt Writes the AD770X setup register directly to perform custom calibration workflows. Allows manual triggering of system calibration modes. ```cpp #include AD770X adc(2.5); void setup() { Serial.begin(9600); adc.reset(); adc.init(AD770X::CHN_AIN1); // default self-cal // Manually trigger a full-scale system calibration on AIN1 adc.setNextOperation(AD770X::REG_SETUP, AD770X::CHN_AIN1, /*write=*/0); adc.writeSetupRegister( AD770X::MODE_FULL_SCALE_CAL, // full-scale calibration AD770X::GAIN_1, // 1× gain AD770X::BIPOLAR, // bipolar mode /*buffered=*/0, /*fsync=*/0 ); // Wait for calibration to complete while (!adc.dataReady(AD770X::CHN_AIN1)) {} } ``` -------------------------------- ### writeSetupRegister(byte operationMode, byte gain, byte unipolar, byte buffered, byte fsync) Source: https://context7.com/kerrydwong/ad770x/llms.txt Writes the AD770X setup register directly for custom calibration workflows. Allows configuration of operation mode, gain, polarity, input buffer, and filter synchronization. ```APIDOC ## `writeSetupRegister(byte operationMode, byte gain, byte unipolar, byte buffered, byte fsync)` ### Description Writes the AD770X setup register directly. `operationMode` can be `MODE_NORMAL`, `MODE_SELF_CAL`, `MODE_ZERO_SCALE_CAL`, or `MODE_FULL_SCALE_CAL`. `gain` selects amplification (GAIN_1–GAIN_128), `unipolar` sets polarity (0 = bipolar, 1 = unipolar), `buffered` enables the input buffer, and `fsync` controls filter synchronization. Called internally by `init()` but accessible for custom calibration workflows. ### Parameters * **operationMode** (byte) - The operating mode (e.g., `AD770X::MODE_FULL_SCALE_CAL`). * **gain** (byte) - The gain setting (e.g., `AD770X::GAIN_1`). * **unipolar** (byte) - Polarity setting (0 for bipolar, 1 for unipolar). * **buffered** (byte) - Input buffer enable flag (0 or 1). * **fsync** (byte) - Filter synchronization control (0 or 1). ``` -------------------------------- ### reset() Source: https://context7.com/kerrydwong/ad770x/llms.txt Resets the AD7705/AD7706 by clocking 32 or more `0xFF` bytes over SPI, forcing the device's serial interface back to its default state. This should be called first in `setup()` to ensure a known starting condition. ```APIDOC ## `reset()` ### Description Resets the AD7705/AD7706 by clocking 32 or more `0xFF` bytes over SPI, forcing the device's serial interface back to its default state. This should always be called first in `setup()` before any other initialization to ensure a known starting condition, especially after power-up or an interrupted SPI transaction. ### Usage Example ```cpp #include AD770X adc(2.5); void setup() { Serial.begin(9600); adc.reset(); // Always reset before init to clear any partial serial state } ``` ``` -------------------------------- ### Reset AD770X Device Source: https://context7.com/kerrydwong/ad770x/llms.txt Resets the AD7705/AD7706 by clocking 32 or more 0xFF bytes over SPI. This ensures a known starting state and should be called first in setup() before any other initialization. ```cpp #include AD770X adc(2.5); void setup() { Serial.begin(9600); adc.reset(); // Always reset before init to clear any partial serial state } ``` -------------------------------- ### init(byte channel) Source: https://context7.com/kerrydwong/ad770x/llms.txt Initializes a given input channel using default settings: clock divider 1, bipolar mode, gain of 1×, and an output update rate of 25 Hz. It configures registers, triggers self-calibration, and waits for completion. ```APIDOC ## `init(byte channel)` ### Description Initializes a given input channel using default settings: clock divider 1, bipolar mode, gain of 1×, and an output update rate of 25 Hz. It writes the clock and setup registers, triggers a self-calibration, and blocks until calibration is complete (DRDY goes low). For AD7705, use `CHN_AIN1` and `CHN_AIN2`; AD7706 additionally supports `CHN_AIN3`. ### Parameters #### Path Parameters - **channel** (byte) - Required - The input channel to initialize (e.g., `AD770X::CHN_AIN1`). ### Usage Example ```cpp #include AD770X adc(2.5); void setup() { Serial.begin(9600); adc.reset(); adc.init(AD770X::CHN_AIN1); // Initialize channel AIN1 with defaults adc.init(AD770X::CHN_AIN2); // Initialize channel AIN2 with defaults // For AD7706 only: // adc.init(AD770X::CHN_AIN3); } ``` ``` -------------------------------- ### init(byte channel, byte clkDivider, byte polarity, byte gain, byte updRate) Source: https://context7.com/kerrydwong/ad770x/llms.txt Provides full-parameter channel initialization for explicit control over ADC settings. Configures clock divider, polarity, gain, and update rate, then performs self-calibration. ```APIDOC ## `init(byte channel, byte clkDivider, byte polarity, byte gain, byte updRate)` ### Description Full-parameter channel initialization, giving explicit control over all key ADC settings. `clkDivider` is `CLK_DIV_1` or `CLK_DIV_2`; `polarity` is `UNIPOLAR` or `BIPOLAR`; `gain` ranges from `GAIN_1` to `GAIN_128`; `updRate` selects the output update rate from 20 Hz to 500 Hz. After configuration, self-calibration runs and the method blocks until it completes. ### Parameters #### Path Parameters - **channel** (byte) - Required - The input channel to initialize (e.g., `AD770X::CHN_AIN1`). - **clkDivider** (byte) - Required - Clock divider setting (`AD770X::CLK_DIV_1` or `AD770X::CLK_DIV_2`). - **polarity** (byte) - Required - Polarity setting (`AD770X::UNIPOLAR` or `AD770X::BIPOLAR`). - **gain** (byte) - Required - Gain setting (e.g., `AD770X::GAIN_1`, `AD770X::GAIN_32`). - **updRate** (byte) - Required - Output update rate setting (e.g., `AD770X::UPDATE_RATE_50`). ### Usage Example ```cpp #include AD770X adc(2.5); void setup() { Serial.begin(9600); adc.reset(); // AIN1: CLK/1, unipolar (0–2.5V), 32× gain, 50 Hz update rate adc.init(AD770X::CHN_AIN1, AD770X::CLK_DIV_1, AD770X::UNIPOLAR, AD770X::GAIN_32, AD770X::UPDATE_RATE_50); // AIN2: CLK/2, bipolar (±2.5V), 1× gain, 10 Hz update rate adc.init(AD770X::CHN_AIN2, AD770X::CLK_DIV_2, AD770X::BIPOLAR, AD770X::GAIN_1, AD770X::UPDATE_RATE_25); } ``` ``` -------------------------------- ### Initialize AD770X Channel with Defaults Source: https://context7.com/kerrydwong/ad770x/llms.txt Initializes a specified input channel using default settings: clock divider 1, bipolar mode, gain of 1×, and an output update rate of 25 Hz. It configures registers, triggers self-calibration, and waits for completion. ```cpp #include AD770X adc(2.5); void setup() { Serial.begin(9600); adc.reset(); adc.init(AD770X::CHN_AIN1); // Initialize channel AIN1 with defaults adc.init(AD770X::CHN_AIN2); // Initialize channel AIN2 with defaults // For AD7706 only: // adc.init(AD770X::CHN_AIN3); } ``` -------------------------------- ### Initialize AD770X with Reference Voltage Source: https://context7.com/kerrydwong/ad770x/llms.txt Creates an AD770X instance and initializes the SPI bus. The reference voltage is crucial for scaling raw ADC counts to voltage values. SPI is configured in Mode 3 at a reduced clock rate. ```cpp #include // Create instance with 2.5V reference voltage (e.g., ADR02 or REF02 reference) AD770X adc(2.5); void setup() { Serial.begin(9600); // SPI pins configured automatically: // Pin 10 -> CS, Pin 11 -> MOSI, Pin 12 -> MISO, Pin 13 -> SCK } ``` -------------------------------- ### Initialize AD770X Channel with Full Parameters Source: https://context7.com/kerrydwong/ad770x/llms.txt Provides explicit control over ADC settings including clock divider, polarity, gain, and update rate. After configuration, self-calibration is performed and the method blocks until completion. ```cpp #include AD770X adc(2.5); void setup() { Serial.begin(9600); adc.reset(); // AIN1: CLK/1, unipolar (0–2.5V), 32× gain, 50 Hz update rate adc.init(AD770X::CHN_AIN1, AD770X::CLK_DIV_1, AD770X::UNIPOLAR, AD770X::GAIN_32, AD770X::UPDATE_RATE_50); // AIN2: CLK/2, bipolar (±2.5V), 1× gain, 10 Hz update rate adc.init(AD770X::CHN_AIN2, AD770X::CLK_DIV_2, AD770X::BIPOLAR, AD770X::GAIN_1, AD770X::UPDATE_RATE_25); } ``` -------------------------------- ### Constructor: AD770X(double vref) Source: https://context7.com/kerrydwong/ad770x/llms.txt Creates an AD770X instance and initializes the SPI bus. The vref parameter sets the reference voltage for scaling ADC counts to voltage values. SPI is configured in Mode 3. ```APIDOC ## Constructor: `AD770X(double vref)` ### Description Creates an AD770X instance and initializes the SPI bus (pins 10–13 on Arduino). The `vref` parameter sets the reference voltage used to scale raw ADC counts into real-world voltage values. SPI is configured in Mode 3 (CPOL=1, CPHA=1) at a reduced clock rate suitable for the AD770X family. ### Usage Example ```cpp #include // Create instance with 2.5V reference voltage (e.g., ADR02 or REF02 reference) AD770X adc(2.5); void setup() { Serial.begin(9600); // SPI pins configured automatically: // Pin 10 -> CS, Pin 11 -> MOSI, Pin 12 -> MISO, Pin 13 -> SCK } ``` ``` -------------------------------- ### setNextOperation(byte reg, byte channel, byte readWrite) Source: https://context7.com/kerrydwong/ad770x/llms.txt Writes directly to the AD770X communication register to select the next register to be accessed, the target channel, and the direction. This is a low-level method for advanced users accessing registers not exposed by higher-level methods. ```APIDOC ## `setNextOperation(byte reg, byte channel, byte readWrite)` ### Description Writes directly to the AD770X communication register to select the next register to be accessed, the target channel, and the direction (read = 1, write = 0). This is a low-level method used internally by the library but available for advanced users who need to access registers (e.g., offset register `REG_OFFSET`, gain register `REG_GAIN`) not exposed by higher-level methods. ### Parameters * **reg** (byte) - The register to access (e.g., `AD770X::REG_DATA`, `AD770X::REG_SETUP`). * **channel** (byte) - The target ADC channel. * **readWrite** (byte) - `1` for read, `0` for write. ``` -------------------------------- ### writeClockRegister(byte CLKDIS, byte CLKDIV, byte outputUpdateRate) Source: https://context7.com/kerrydwong/ad770x/llms.txt Directly writes the AD770X clock register to reconfigure sampling speed at runtime. Parameters control master clock disable, clock division, and output update rate. ```APIDOC ## `writeClockRegister(byte CLKDIS, byte CLKDIV, byte outputUpdateRate)` ### Description Directly writes the AD770X clock register. `CLKDIS` (1 = disable master clock), `CLKDIV` (0 = /1, 1 = /2), and `outputUpdateRate` selects the update rate constant (`UPDATE_RATE_20` through `UPDATE_RATE_500`). Called internally by `init()` but available for runtime reconfiguration of sampling speed without full re-initialization. ### Parameters * **CLKDIS** (byte) - Master clock disable flag (1 to disable). * **CLKDIV** (byte) - Clock divider setting (e.g., `AD770X::CLK_DIV_1`). * **outputUpdateRate** (byte) - Desired output update rate constant (e.g., `AD770X::UPDATE_RATE_500`). ``` -------------------------------- ### readADResult(byte channel, float refOffset = 0.0) Source: https://context7.com/kerrydwong/ad770x/llms.txt Reads a fully converted, scaled voltage from the specified channel. It waits for a new conversion, reads the raw result, and scales it to volts using the reference voltage and an optional offset correction. Returns a double in volts. ```APIDOC ## `readADResult(byte channel, float refOffset = 0.0)` ### Description Reads a fully converted, scaled voltage from the specified channel. Internally it polls `dataReady()` until a new conversion is available, then reads the 16-bit raw result and scales it to volts using: `result = (raw / 65536.0) × VRef − refOffset`. The optional `refOffset` corrects for a known zero-offset error. Returns a `double` in volts. ### Parameters #### Path Parameters - **channel** (byte) - Required - The input channel to read from (e.g., `AD770X::CHN_AIN1`). - **refOffset** (float) - Optional - Default: `0.0`. Corrects for a known zero-offset error in volts. ### Returns - **double** - The scaled voltage reading in volts. ### Usage Example ```cpp #include AD770X adc(2.5); void setup() { Serial.begin(9600); adc.reset(); adc.init(AD770X::CHN_AIN1); adc.init(AD770X::CHN_AIN2); } void loop() { double v1 = adc.readADResult(AD770X::CHN_AIN1); // No offset correction double v2 = adc.readADResult(AD770X::CHN_AIN2, 0.0012); // 1.2 mV offset correction Serial.print("AIN1: "); Serial.print(v1, 4); // 4 decimal places, e.g. "1.2341" Serial.print(" V | AIN2: "); Serial.print(v2, 4); Serial.println(" V"); // Example output: // AIN1: 1.2341 V | AIN2: 0.0003 V } ``` ``` -------------------------------- ### Read Scaled Voltage from AD770X Channel Source: https://context7.com/kerrydwong/ad770x/llms.txt Reads a converted and scaled voltage from a specified channel. It polls for data readiness, retrieves the raw result, and scales it to volts using the reference voltage and an optional offset correction. Returns a double in volts. ```cpp #include AD770X adc(2.5); void setup() { Serial.begin(9600); adc.reset(); adc.init(AD770X::CHN_AIN1); adc.init(AD770X::CHN_AIN2); } void loop() { double v1 = adc.readADResult(AD770X::CHN_AIN1); // No offset correction double v2 = adc.readADResult(AD770X::CHN_AIN2, 0.0012); // 1.2 mV offset correction Serial.print("AIN1: "); Serial.print(v1, 4); // 4 decimal places, e.g. "1.2341" Serial.print(" V | AIN2: "); Serial.print(v2, 4); Serial.println(" V"); // Example output: // AIN1: 1.2341 V | AIN2: 0.0003 V } ``` -------------------------------- ### dataReady(byte channel) Source: https://context7.com/kerrydwong/ad770x/llms.txt Polls the communication register of the specified channel and returns true when a new conversion result is available. This allows non-blocking polling patterns. ```APIDOC ## `dataReady(byte channel)` ### Description Polls the communication register of the specified channel and returns `true` when a new conversion result is available (DRDY bit = 0), or `false` if the ADC is still converting. This allows non-blocking polling patterns where the sketch needs to perform other work between ADC reads rather than busy-waiting inside `readADResult`. ### Parameters * **channel** (byte) - The ADC channel to check for data readiness. ### Returns * `bool` - `true` if data is ready, `false` otherwise. ``` -------------------------------- ### Check Data Ready Status Source: https://context7.com/kerrydwong/ad770x/llms.txt Polls the communication register to check if a new conversion result is available without blocking the main loop. Allows other tasks to run while waiting for ADC conversion. ```cpp #include AD770X adc(2.5); unsigned long lastRead = 0; void setup() { Serial.begin(9600); adc.reset(); adc.init(AD770X::CHN_AIN1); } void loop() { // Non-blocking check — do other work while waiting for conversion if (adc.dataReady(AD770X::CHN_AIN1)) { adc.setNextOperation(AD770X::REG_DATA, AD770X::CHN_AIN1, 1); // Read raw result directly after confirming ready unsigned int raw = adc.readADResultRaw(AD770X::CHN_AIN1); Serial.println(raw); } // Other sketch logic here (runs without blocking on ADC) // e.g., update display, handle serial input, etc. } ``` -------------------------------- ### AD770X Library Constants Source: https://context7.com/kerrydwong/ad770x/llms.txt Constants for registers, channels, update rates, gain, polarity, clock dividers, and operating modes. These are used to configure and interact with the AD770X analog-to-digital converter. ```cpp // Registers AD770X::REG_CMM // Communication register (0x0) AD770X::REG_SETUP // Setup register (0x1) AD770X::REG_CLOCK // Clock register (0x2) AD770X::REG_DATA // Data register (0x3) AD770X::REG_OFFSET // Offset register (0x6) AD770X::REG_GAIN // Gain register (0x7) // Channels (AD7705: AIN1+AIN2 only; AD7706: all three) AD770X::CHN_AIN1 // Channel AIN1 AD770X::CHN_AIN2 // Channel AIN2 AD770X::CHN_AIN3 // Channel AIN3 (AD7706 only) AD770X::CHN_COMM // Common channel // Output update rates AD770X::UPDATE_RATE_20 AD770X::UPDATE_RATE_25 AD770X::UPDATE_RATE_50 AD770X::UPDATE_RATE_60 AD770X::UPDATE_RATE_100 AD770X::UPDATE_RATE_200 AD770X::UPDATE_RATE_250 AD770X::UPDATE_RATE_500 // Gain AD770X::GAIN_1 AD770X::GAIN_2 AD770X::GAIN_4 AD770X::GAIN_8 AD770X::GAIN_16 AD770X::GAIN_32 AD770X::GAIN_64 AD770X::GAIN_128 // Polarity AD770X::UNIPOLAR // 0 to VRef AD770X::BIPOLAR // -VRef to +VRef // Clock divider AD770X::CLK_DIV_1 AD770X::CLK_DIV_2 // Operating modes AD770X::MODE_NORMAL AD770X::MODE_SELF_CAL AD770X::MODE_ZERO_SCALE_CAL AD770X::MODE_FULL_SCALE_CAL ``` -------------------------------- ### Write to Clock Register Source: https://context7.com/kerrydwong/ad770x/llms.txt Directly writes to the AD770X clock register to reconfigure sampling speed at runtime without full re-initialization. Allows changing the output update rate. ```cpp #include AD770X adc(2.5); void setup() { Serial.begin(9600); adc.reset(); adc.init(AD770X::CHN_AIN1); // Switch AIN1 to 500 Hz update rate at runtime adc.setNextOperation(AD770X::REG_CLOCK, AD770X::CHN_AIN1, /*write=*/0); adc.writeClockRegister(/*CLKDIS=*/0, /*CLKDIV=*/AD770X::CLK_DIV_1, AD770X::UPDATE_RATE_500); } ``` -------------------------------- ### readADResultRaw(byte channel) Source: https://context7.com/kerrydwong/ad770x/llms.txt Returns the raw unsigned 16-bit integer from the data register after waiting for data ready on the given channel. This is useful for maximum throughput, custom scaling, or logging raw counts for calibration. ```APIDOC ## `readADResultRaw(byte channel)` ### Description Returns the raw unsigned 16-bit integer from the data register (0–65535) after waiting for data ready on the given channel. Useful when you need maximum throughput, want to apply custom scaling, or are logging raw counts for calibration purposes. ### Parameters * **channel** (byte) - The ADC channel to read from. ### Returns * `unsigned int` - The raw 16-bit ADC result. ``` -------------------------------- ### Set Next Register Operation Source: https://context7.com/kerrydwong/ad770x/llms.txt Directly writes to the communication register to select the next register to access, the channel, and read/write direction. Useful for accessing registers not exposed by higher-level methods. ```cpp #include AD770X adc(2.5); void setup() { Serial.begin(9600); adc.reset(); adc.init(AD770X::CHN_AIN1); // Advanced: point to the DATA register on CHN_AIN1 for a manual read adc.setNextOperation(AD770X::REG_DATA, AD770X::CHN_AIN1, /*read=*/1); // Next SPI transaction will read the data register for AIN1 // Point to SETUP register on CHN_AIN2 for a manual write adc.setNextOperation(AD770X::REG_SETUP, AD770X::CHN_AIN2, /*write=*/0); // Next SPI transaction will write the setup register for AIN2 } ``` -------------------------------- ### Read Raw ADC Result Source: https://context7.com/kerrydwong/ad770x/llms.txt Reads the raw unsigned 16-bit integer from the data register. Useful for maximum throughput, custom scaling, or logging raw counts for calibration. ```cpp #include AD770X adc(2.5); void setup() { Serial.begin(9600); adc.reset(); adc.init(AD770X::CHN_AIN1); } void loop() { unsigned int raw = adc.readADResultRaw(AD770X::CHN_AIN1); // Manual scaling example (bipolar, 2.5V ref, gain=1): double voltage = (raw / 65536.0) * 2.5; Serial.print("Raw: "); Serial.print(raw); // e.g. 32768 Serial.print(" -> "); Serial.print(voltage, 4); // e.g. 1.2500 Serial.println(" V"); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.