Skip to content

Commit 608121c

Browse files
committed
Rename Example01. Add Example02 and setConversionMode
1 parent 4c4d596 commit 608121c

File tree

4 files changed

+89
-0
lines changed

4 files changed

+89
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
}

src/SparkFun_ADS1219.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ bool SfeADS1219Driver::begin()
3030
if (!reset())
3131
return false;
3232

33+
delay(1); // Wait >100us (tRSSTA)
34+
3335
sfe_ads1219_reg_cfg_t config;
3436
bool result = (_theBus->readRegisterByte(kSfeADS1219RegConfigRead, config.byte) == kSTkErrOk);
3537
return (result && (config.byte == 0));
@@ -56,6 +58,17 @@ bool SfeADS1219Driver::powerDown()
5658
return (_theBus->writeByte(kSfeADS1219CommandPowerDown) == kSTkErrOk);
5759
}
5860

61+
/// @brief Configure the conversion mode.
62+
/// @return True if successful, false otherwise.
63+
bool SfeADS1219Driver::setConversionMode(const ads1219_conversion_mode_config_t mode)
64+
{
65+
sfe_ads1219_reg_cfg_t config;
66+
if (_theBus->readRegisterByte(kSfeADS1219RegConfigRead, config.byte) != kSTkErrOk) // Read the config register
67+
return false;
68+
config.cm = (uint8_t)mode; // Update (only) the conversion mode
69+
return (_theBus->writeRegisterByte(kSfeADS1219RegConfigWrite, config.byte) == kSTkErrOk); // Write the config register
70+
}
71+
5972
/// @brief Reads the ADC conversion data, converts it to a usable form, and
6073
/// saves it to the internal result variable.
6174
/// @return true if successful, false otherwise.

src/SparkFun_ADS1219.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ class SfeADS1219Driver
178178
/// @return True if successful, false otherwise.
179179
bool setInputMultiplexer(const ads1219_input_multiplexer_config_t config = ADS1219_CONFIG_MUX_DIFF_P0_N1);
180180

181+
/// @brief Configure the conversion mode.
182+
/// @return True if successful, false otherwise.
183+
bool setConversionMode(const ads1219_conversion_mode_config_t mode = ADS1219_CONVERSION_SINGLE_SHOT);
184+
181185
/// @brief Return the conversion result which was read by readConversion.
182186
/// Convert it to mV using referenceVoltageMillivolts and the _adcGain.
183187
/// @param referenceVoltageMillivolts Usually the internal 2.048V reference voltage.

0 commit comments

Comments
 (0)