Last active
February 16, 2016 05:39
-
-
Save dwblair/edab5373a8470757e232 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
#include <Adafruit_ADS1015.h> // https://github.com/adafruit/Adafruit_ADS1X15 | |
#include <OneWire.h> //http://www.pjrc.com/teensy/td_libs_OneWire.html | |
#include <DallasTemperature.h> //https://github.com/milesburton/Arduino-Temperature-Control-Library | |
Adafruit_ADS1115 ads; /* Use this for the 16-bit version */ | |
//Adafruit_ADS1015 ads; /* Use thi for the 12-bit version */ | |
//1-wire sensor | |
// Data wire is plugged into pin 10 on the Arduino | |
#define ONE_WIRE_BUS 10 | |
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) | |
OneWire oneWire(ONE_WIRE_BUS); | |
DallasTemperature sensors(&oneWire); | |
void setup(void) | |
{ | |
Serial.begin(9600); | |
Serial.println("Hello!"); | |
Serial.println("Getting single-ended readings from AIN0..3"); | |
Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)"); | |
// The ADC input range (or gain) can be changed via the following | |
// functions, but be careful never to exceed VDD +0.3V max, or to | |
// exceed the upper and lower limits if you adjust the input range! | |
// Setting these values incorrectly may destroy your ADC! | |
// ADS1015 ADS1115 | |
// ------- ------- | |
// ads.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 3mV 0.1875mV (default) | |
ads.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV | |
// ads.setGain(GAIN_TWO); // 2x gain +/- 2.048V 1 bit = 1mV 0.0625mV | |
// ads.setGain(GAIN_FOUR); // 4x gain +/- 1.024V 1 bit = 0.5mV 0.03125mV | |
// ads.setGain(GAIN_EIGHT); // 8x gain +/- 0.512V 1 bit = 0.25mV 0.015625mV | |
// ads.setGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.125mV 0.0078125mV | |
ads.begin(); | |
// 1-wire temp sensor | |
sensors.begin(); | |
} | |
void loop(void) | |
{ | |
// get the conductivity voltage | |
int16_t adc0 = ads.readADC_SingleEnded(0); | |
// get the celsius voltage | |
sensors.requestTemperatures(); // Send the command to get temperatures | |
float celsius = sensors.getTempCByIndex(0); | |
Serial.print(adc0); | |
Serial.print(","); | |
Serial.println(celsius); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment