Qwiic 12-Bit ADC Hookup Guide

Pages
Contributors: QCPete, santaimpersonator
Favorited Favorite 3

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.

Input: i2caddr
Unassigned 8-bit integer for device address. If not defined, the library will use the default I2C address stored in the I2C library (0x48). Other available addresses are 0x49, 0x4A, 0x4B (set by a 4-way solder jumper on the bottom side of the board).
Input: Wire
Wire port assignment. If not defined, the library will use the default Wire port. Note, this is only available to change on boards that in fact have multiple Wire Ports (like the Teensy).
Output: Boolean

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.

Output: Boolean

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).

Input: Unassigned 16-bit integer

0 - Continuous.
1 - Single-shot.

.getMode()
Returns which read mode you are currently in: continuous (0) or single-shot (1).

Output: Unassigned 16-bit integer

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.

Input: Unassigned 16-bit integer

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.

Output: Unassigned 16-bit integer

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.

Input: Unassigned 16-bit integer

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.

Input: channel

Unassigned 8-bit integer. Available values are 0, 1, 2, and 3 (for the corresponding A0, A1, A2, and A3).

Input: threshold

Signed 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.

Output: Unassigned 16-bit integer

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.

Input: channel
Unasssigned 8-bit integer for channel you'd like to read. Available channels are 0, 1, 2, 3. These correspond to the channels on the board labeled A0, A1, A2, and A3.
Output: Unasssigned 16-bit integer

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).

Input: channel
ADS1015_CONFIG_MUX_DIFF_P0_N1 (default)
ADS1015_CONFIG_MUX_DIFF_P0_N3
ADS1015_CONFIG_MUX_DIFF_P1_N3
ADS1015_CONFIG_MUX_DIFF_P2_N3
Output: Signed 16-bit integer

This return signed values from decimal -2047 up to +2047.