Quick Start
In this Quick Start guide we'll go over how to assemble the SparkFun Qwiic 24 Bit ADC - 4 Channel (ADS1219) in a Qwiic circuit to measure the output voltage of a flex sensor assembled to function as a voltage divider.
This guide assumes users have a basic understanding of using Qwiic breakout and development boards, through-hole soldering, breadboard prototyping as well as how to use the Arduino IDE. If you're not familiar with all of these concepts, read on through the rest of this Hookup Guide for detailed information on how to use this breakout board with the Arduino IDE.
Flex Sensor Demo Assembly
Since we're doing some prototype testing with this board, we opted to solder male headers to the Qwiic ADC - AS1219's PTH pads to easily connect jumper wires to the board.
Connect the flex sensor to the Qwiic ADC - AS1219 with the following steps:
- Plug the flex sensor into the breadboard.
- Connect one leg of a 10kΩ resistor to one of the flex sensor's pins and the other to a free row on the breadboard.
- Take one jumper wire (white wire in the photo below) and connect AIN0 on the Qwiic ADC to same row on the breadboard as the Flex Sensor pin connected to the 10kΩ resistor.
- Next, use a second jumper wire (red wire in the photo below) to connect the flex sensor's other pin to the Qwiic ADC's VDDA pin (this label is on the bottom of the board).
- Now use the third jumper wire (black wire in the photo below) and connect the other or "free" end of the 10kΩ resistor to one of the ground pins on the Qwiic ADC.
Your circuit should look similar to the photo below:
Now that we've finished assembling our flex sensor circuit, it's time to connect the Qwiic ADC - AS1219 to our RedBoard IoT - ESP32. Simply connect the two together with a Qwiic cable plugged into the Qwiic connectors:
Arduino Example
For this example, we'll be using a slightly modified version of Example 01 - Single Shot from the SparkFun AS1219 Arduino Library.
- Open the Arduino IDE.
- Open the Library Manager tool, search for "SparkFun AS1219" and install the latest version. This library was built using the SparkFun Toolkit so if you have not already installed it, search for "SparkFun Toolkit" in the Library Manager to install the dependency.
- Open "Example 01 - Single Shot".
- Add the following code to the
void setup()below this line:Serial.println("ADC initialized");: - Select your Board (SparkFun RedBoard IoT - ESP32 or other board) and Port and click "Upload".
- After the code compiles and finishes uploading, open the serial monitor with the baud set to 115200.
- Now, gently bend the flex sensor and you should see the voltage readings move down like the screenshot below. Continue flexing the sensor and it should drop further or release it and the voltages should jump back up.
Code to Note
The Single Shot example defaults to measure a differential input from the A0 and A1 channels so in the instructions above we modified the code to configure the ADS1219 to just read a single input on A0 using the setInputMultiplexer() function and then perform a serial print informing of the change:
The main loop of this example attempts to start a single-shot conversion and waits for it to complete every 10ms:
if (myADC.startSync()) // Start a single-shot conversion. This will return true on success.
{
while (myADC.dataReady() == false) // Check if the conversion is complete. This will return true if data is ready.
{
delay(10); // The conversion is not complete. Wait a little to avoid pounding the I2C bus.
}
If that single-shot conversion completes, we read the result, convert it to millivolts and print out that value with three decimal points. If it fails, it prints out a failure message and waits one second before attempting again:
myADC.readConversion(); // Read the conversion result from the ADC. Store it internally.
float milliVolts = myADC.getConversionMillivolts(); // Convert to millivolts.
Serial.print("ADC voltage (mV): ");
Serial.println(milliVolts, 3); // Print milliVolts with 3 decimal places
}
else
{
Serial.println("ADC start conversion failed. Please check your wiring! Retrying...");
delay(1000);
}


