Skip to content

Commit ba297b0

Browse files
committed
Add Example03 and setInputMultiplexer
1 parent 608121c commit ba297b0

File tree

3 files changed

+98
-5
lines changed

3 files changed

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

src/SparkFun_ADS1219.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,18 @@ bool SfeADS1219Driver::setConversionMode(const ads1219_conversion_mode_config_t
6565
sfe_ads1219_reg_cfg_t config;
6666
if (_theBus->readRegisterByte(kSfeADS1219RegConfigRead, config.byte) != kSTkErrOk) // Read the config register
6767
return false;
68-
config.cm = (uint8_t)mode; // Update (only) the conversion mode
68+
config.cm = (uint8_t)mode; // Modify (only) the conversion mode
69+
return (_theBus->writeRegisterByte(kSfeADS1219RegConfigWrite, config.byte) == kSTkErrOk); // Write the config register
70+
}
71+
72+
/// @brief Configure the input multiplexer.
73+
/// @return True if successful, false otherwise.
74+
bool SfeADS1219Driver::setInputMultiplexer(const ads1219_input_multiplexer_config_t mux)
75+
{
76+
sfe_ads1219_reg_cfg_t config;
77+
if (_theBus->readRegisterByte(kSfeADS1219RegConfigRead, config.byte) != kSTkErrOk) // Read the config register
78+
return false;
79+
config.mux = (uint8_t)mux; // Modify (only) the input multiplexer
6980
return (_theBus->writeRegisterByte(kSfeADS1219RegConfigWrite, config.byte) == kSTkErrOk); // Write the config register
7081
}
7182

src/SparkFun_ADS1219.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,14 @@ class SfeADS1219Driver
174174
/// @return true if successful, false otherwise.
175175
bool readConversion(void);
176176

177-
/// @brief Configure the input multiplexer.
178-
/// @return True if successful, false otherwise.
179-
bool setInputMultiplexer(const ads1219_input_multiplexer_config_t config = ADS1219_CONFIG_MUX_DIFF_P0_N1);
180-
181177
/// @brief Configure the conversion mode.
182178
/// @return True if successful, false otherwise.
183179
bool setConversionMode(const ads1219_conversion_mode_config_t mode = ADS1219_CONVERSION_SINGLE_SHOT);
184180

181+
/// @brief Configure the input multiplexer.
182+
/// @return True if successful, false otherwise.
183+
bool setInputMultiplexer(const ads1219_input_multiplexer_config_t config = ADS1219_CONFIG_MUX_DIFF_P0_N1);
184+
185185
/// @brief Return the conversion result which was read by readConversion.
186186
/// Convert it to mV using referenceVoltageMillivolts and the _adcGain.
187187
/// @param referenceVoltageMillivolts Usually the internal 2.048V reference voltage.

0 commit comments

Comments
 (0)