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