Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save bboyho/66651966080fc65a7fbd2165640408bb to your computer and use it in GitHub Desktop.

Select an option

Save bboyho/66651966080fc65a7fbd2165640408bb to your computer and use it in GitHub Desktop.
/*
Using the SparkFun Qwiic 12 Bit ADC - 4 Channel ADS1015
Combined Example Written By: Bobby Chan
Original Example Written By: Pete Lewis, Original flex-glove library by: Andy England
SparkFun Electronics
Modified Date: 2/1/2023
License: This code is public domain but you can buy me a beer if you use this and we meet someday (Beerware license).
Feel like supporting our work? Please buy a board from SparkFun!
https://www.sparkfun.com/products/15334
This example shows how to output ADC values on one differential input between A0 and A1.
at default gain setting of 16
Hardware Connections and initial setup:
Plug in your controller board (e.g. IoT RedBoard - ESP32) into your computer with USB cable.
Connect your Qwiic 12 Bit ADC board to your controller board via a qwiic cable.
Connect your MIC+ to A0 (e.. AINpos)
Connect your MIC- to A1(e.g. AINneg)
Select TOOLS>>BOARD>>"SparkFun ESP32 IoT RedBoard "
Select TOOLS>>PORT>> "COM 27" (note, yours may be different)
Click upload, and watch streaming data over serial monitor at 115200.
It will show the voltage difference between A0 and A1 (also showing negative differences (if present).
*/
#include <SparkFun_ADS1015_Arduino_Library.h> //Click here to get the library: http://librarymanager/All#SparkFun_ADS1015
#include <Wire.h>
ADS1015 adcSensor;
void setup() {
Wire.begin();
Serial.begin(115200);
if (adcSensor.begin() == true)
{
Serial.println("Device found. I2C connections are good.");
}
else
{
Serial.println("Device not found. Check wiring.");
while (1); // stall out forever
}
/*
ADS1015_CONFIG_PGA_TWOTHIRDS +/- 6.144v
ADS1015_CONFIG_PGA_1 +/- 4.096v (used in this example)
ADS1015_CONFIG_PGA_2 +/- 2.048v
ADS1015_CONFIG_PGA_4 +/- 1.024v
ADS1015_CONFIG_PGA_8 +/- 0.512v
ADS1015_CONFIG_PGA_16 +/- 0.256v
*/
adcSensor.setGain(ADS1015_CONFIG_PGA_16); // PGA gain set to 16
}
void loop() {
int16_t input = adcSensor.getDifferential(); // default (i.e. no arguments) is A0 and A1
// Optional "commented out" examples below show how to read differential readings between other pins
// int16_t input = adcSensor.getDifferential(ADS1015_CONFIG_MUX_DIFF_P0_N3);
// int16_t input = adcSensor.getDifferential(ADS1015_CONFIG_MUX_DIFF_P1_N3);
// int16_t input = adcSensor.getDifferential(ADS1015_CONFIG_MUX_DIFF_P2_N3);
// False print statements to "lock range" on serial plotter display
// Change rangelimit value to adjust "sensitivity"... not as sophisticated as Pete's example.
//int rangelimit = 750;
//Serial.print(rangelimit * -1);
//Serial.print(",");
//Serial.print("Differential: ");
Serial.println(input); //differential output
//Serial.print(",");
//Serial.println(rangelimit * 1);
delay(5); // avoid bogging up serial monitor
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment