Qwiic 12-Bit ADC Hookup Guide
Arduino Library
Note: This example assumes you are using the latest version of the Arduino IDE on your desktop. If this is your first time using Arduino, please review our tutorial on installing the Arduino IDE. If you have not previously installed an Arduino library, please check out our installation guide.
We've written a library to easily get setup and take readings from the Qwiic 12-bit ADC. However, before we jump into getting data from the sensor, let's take a closer look at the available functions in the library. You can install this library through the Arduino Library Manager. Search for SparkFun ADS1015 Arduino Library and you should be able to install the latest version. If you prefer manually downloading the libraries from the GitHub repository, you can grab them here:
Let's get started by looking at the functions that set up the Qwiic 12-bit ADC.
Setup and Settings
.begin()
or .begin(i2caddr, Wire)
Creates a connection to an I2C device over the I2C bus using the default or specified I2C address.
True- Connected to I2C device on the default (or specified) address.
False- No device found or connected.
.isConnected()
Checks to see if a device over the I2C bus is connected. Returns boolean true or false depending on if the slave device has correctly ack'd to an I2C request.
True- Device present on the default (or specified) address.
False- No device found or connected.
.setMode(uint16_t mode)
Set the read mode of the sensor (continuous or single-shot).
0 - Continuous.
1 - Single-shot.
.getMode()
Returns which read mode you are currently in: continuous (0) or single-shot (1).
0 - Continuous.
1 - Single-shot.
.setGain(uint16_t gain)
Sets the gain of the programmable gain amplifier (PGA) inside the ADS1015. Note, this gain amplifier is located just before the ADC converter, so it greatly effects your readings and can cause your readings to "max out". Pass in one of the following #define "variables"
from the library to easily set the gain.
ADS1015_CONFIG_PGA_TWOTHIRDS : ± 6.144V
ADS1015_CONFIG_PGA_1 : ± 4.096V
ADS1015_CONFIG_PGA_2 : ± 2.048V (default)
ADS1015_CONFIG_PGA_4 : ± 1.024V
ADS1015_CONFIG_PGA_8 : ± 0.512V
ADS1015_CONFIG_PGA_16 : ± 0.256V
.getGain()
Returns the gain of the programmable gain amplifier (PGA) inside the ADS1015. This returns a 16-bit hex value. The values and their corresponding gains and voltage ranges are as follows.
0x0000 - gain:2/3, input range:± 6.144V
0X0200 - gain:1, input range: ± 4.096V
0X0400 - gain:2, input range: ± 2.048V
0X0600 - gain:4, input range: ± 1.024V
0X0800 - gain:8, input range: ± 0.512V
0X0A00 - gain:16, input range: ± 0.256V
.setSampleRate(uint16_t sampleRate)
Sets the sample rate of the ADS1015. Use the following #define variables.
ADS1015_CONFIG_RATE_128HZ
ADS1015_CONFIG_RATE_250HZ
ADS1015_CONFIG_RATE_490HZ
ADS1015_CONFIG_RATE_920HZ
ADS1015_CONFIG_RATE_1600HZ (default)
ADS1015_CONFIG_RATE_2400HZ
ADS1015_CONFIG_RATE_3300HZ
.setComparatorSingleEnded(uint8_t channel, int16_t threshold)
Sets up a single ended comparator that will effect the ALERT pin on the ADS1015 (active LOW by default) when a reading above the threshold is read. Note, you must call .getLastConversionResults() for this to reset. See Example5_Alert.ino in the library for more info.
Unassigned 8-bit integer. Available values are 0, 1, 2, and 3 (for the corresponding A0, A1, A2, and A3).
Input: thresholdSigned 16-bit integer. Possible values are decimal 0-2047. 1000 is about 3V.
.getSampleRate()
Returns the sample rate of the ADS1015 as an unassigned 16-bit integer value. The values and their corresponding sample rates are as follows.
0x0000 : 128HZ
0X0020 : 250HZ
0X0040 : 490HZ
0X0060 : 920HZ
0X0080 : 1600HZ
0X00A0 : 2400HZ
0X00C0 : 3300HZ
These functions are used primarily for use with the Qwiic Flex Glove Controller (which uses the same Arduino library). Please see the Qwiic Flex Glove Controller hookup guide for more information.
.getAnalogData()
.getScaledAnalogData()
.calibrate()
.setCalibration()
.getCalibration()
.resetCalibration()
Readings
.getSingleEnded(uint8_t channel);
Returns the single ended analog value from the sensor on the specified channel.
This return values from decimal 0 - 2047 (or HEX 0x0000 - 0x07FF). Note, this is only 11 bits of precision on a single-ended input. 12-bit resolution is only available on differential inputs.
.getDifferential()
or .getDifferential(uint8_t channel)
Returns a signed differential analog value from the sensor on the specified pairs of channels. If no argument is passed, then it will use the default pair of channels (A0 and A1).
ADS1015_CONFIG_MUX_DIFF_P0_N3
ADS1015_CONFIG_MUX_DIFF_P1_N3
ADS1015_CONFIG_MUX_DIFF_P2_N3
This return signed values from decimal -2047 up to +2047.