|
| 1 | +/* |
| 2 | + Configuring the ADS1219 ADC input multiplexer. |
| 3 | +
|
| 4 | + The ADS1219 has an input multiplexer which allows it to read: |
| 5 | + single-ended voltages from AIN0/1/2/3; |
| 6 | + differential voltages from AIN0-AIN1, AIN2-AIN3, AIN1-AIN2; |
| 7 | + or the input can be shorted (to AVDD divided by two) for offset measurement. |
| 8 | + This example shows how to configure the multiplexer and then read the voltage. |
| 9 | +
|
| 10 | + By: Paul Clark |
| 11 | + SparkFun Electronics |
| 12 | + Date: 2023/12/11 |
| 13 | + SparkFun code, firmware, and software is released under the MIT License. |
| 14 | + Please see LICENSE.md for further details. |
| 15 | +
|
| 16 | + Hardware Connections: |
| 17 | + IoT RedBoard --> ADS1219 |
| 18 | + QWIIC --> QWIIC |
| 19 | +
|
| 20 | + Open the serial monitor at 115200 baud to see the voltage. |
| 21 | +
|
| 22 | + Feel like supporting our work? Buy a board from SparkFun! |
| 23 | + https://www.sparkfun.com/products/23455 - Qwiic ADS1219 1x1 |
| 24 | +*/ |
| 25 | + |
| 26 | +// You will need the SparkFun Toolkit. Click here to get it: http://librarymanager/All#SparkFun_Toolkit |
| 27 | + |
| 28 | +#include <SparkFun_ADS1219.h> // Click here to get the library: http://librarymanager/All#SparkFun_ADS1219 |
| 29 | + |
| 30 | +SfeADS1219ArdI2C myADC; |
| 31 | + |
| 32 | +void setup() |
| 33 | +{ |
| 34 | + |
| 35 | + delay(1000); // Allow time for the microcontroller to start up |
| 36 | + |
| 37 | + Serial.begin(115200); // Begin the Serial console |
| 38 | + while (!Serial) |
| 39 | + { |
| 40 | + delay(100); // Wait for the user to open the Serial Monitor |
| 41 | + }; |
| 42 | + Serial.println("SparkFun ADS1219 Example"); |
| 43 | + |
| 44 | + Wire.begin(); // Begin the I2C bus |
| 45 | + |
| 46 | + // Initialize ADC - this also performs a soft reset |
| 47 | + while (myADC.begin() == false) |
| 48 | + { |
| 49 | + Serial.println("ADC failed to begin. Please check your wiring! Retrying..."); |
| 50 | + delay(1000); |
| 51 | + } |
| 52 | + |
| 53 | + // Configure the input multiplexer. Options are: |
| 54 | + // ADS1219_CONFIG_MUX_DIFF_P0_N1 (Default) |
| 55 | + // ADS1219_CONFIG_MUX_DIFF_P2_N3 |
| 56 | + // ADS1219_CONFIG_MUX_DIFF_P1_N2 |
| 57 | + // ADS1219_CONFIG_MUX_SINGLE_0 |
| 58 | + // ADS1219_CONFIG_MUX_SINGLE_1 |
| 59 | + // ADS1219_CONFIG_MUX_SINGLE_2 |
| 60 | + // ADS1219_CONFIG_MUX_SINGLE_3 |
| 61 | + // ADS1219_CONFIG_MUX_SHORTED |
| 62 | + myADC.setInputMultiplexer(ADS1219_CONFIG_MUX_SINGLE_0); // Read the voltage between AIN0 and GND |
| 63 | + |
| 64 | + Serial.println("ADC initialized"); |
| 65 | + |
| 66 | + Serial.println("Reading the voltage through the input multiplexer"); |
| 67 | +} |
| 68 | + |
| 69 | +void loop() |
| 70 | +{ |
| 71 | + myADC.startSync(); // Start a single-shot conversion. |
| 72 | + |
| 73 | + while (myADC.dataReady() == false) // Check if the conversion is complete. This will return true if data is ready. |
| 74 | + { |
| 75 | + delay(10); // The conversion is not complete. Wait a little to avoid pounding the I2C bus. |
| 76 | + } |
| 77 | + |
| 78 | + myADC.readConversion(); // Read the conversion result from the ADC. Store it internally. |
| 79 | + float milliVolts = myADC.getConversionMillivolts(); // Convert to millivolts. |
| 80 | + Serial.print("ADC voltage (mV): "); |
| 81 | + Serial.println(milliVolts, 3); // Print milliVolts with 3 decimal places |
| 82 | +} |
0 commit comments