first commit

This commit is contained in:
Jérôme Delacotte
2025-03-06 11:15:32 +01:00
commit 7b30d6e298
5276 changed files with 2108927 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 270 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 KiB

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 Wolfgang (Wolle) Ewald
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,37 @@
# ADS1115_WE
An Arduino library for the 16-bit, 4-channel ADS1115 and the 12-Bit, 4-channel ADS1015 ADC with gain and alert functions.
I have have tried to optimize the library for convenience to use. If you try the examples I recommend to start with `Single_Shot.ino`.
You can find more details here:
https://wolles-elektronikkiste.de/ads1115 (German)
https://wolles-elektronikkiste.de/en/ads1115-a-d-converter-with-amplifier (English)
All features of the ADS1115 and ADS1015 are implemented, including alert functions.
The examples are written for the ADS1115 with one exception, which is Continuous_ADS1015.ino. This shows how to "translate" the sketches
for the ADS1015. Most enum values like ADS1115_RANGE_6144 and ADS1015_RANGE_6144 are even identical. The exceptions are the enum values for
the conversion rate.
In version 1.4.1 I have implemented the option to use TinyWireM instead of Wire. Therefore the library can be used, for example, on
an ATtiny85.
Since version 1.3.0 I have added a feature to the continuous mode, which ensures that you can change channels safely without risking that the
first data read is still from the former channel. If you experienced this issue, you might have solved it with a delay. If this applies to
you, you can delete the delays.
If you like the library it would be cool if you can give it a star. If you find bugs, please inform me.
<h2>Beware of fake modules</h2>
There are ADS1115 modules which use ADS1015 ICs and also there are ADS1015 modules which are based on ADS1115 ICs. In theory you should
recognize the IC by its label which is "BRPI" for the ADS1015 and "BOGI" for the ADS1115. But I have even found ADS1115 ICs labeled with
"BRPI" which is definitely a fake. The difference between the ADS1115 and the ADS1015 is a) the 16-bit vs. 12-bit resolution an b) the speed.
If you want to find out what you really have on on your module, then try the example sketch "Who_Am_I.ino". Do not change anything apart from
the I2C address if necessary.

View File

@@ -0,0 +1,153 @@
/***************************************************************************
* Example sketch for the ADS1115_WE library
*
* This sketch shows how you can use the alert pin to compare with limits. I
* have chosen the window mode. You can also try the max limit (traditional)
* mode. You can change the mode with the function setAlertModeAndLimit_V
*
* Further information can be found on:
* https://wolles-elektronikkiste.de/ads1115 (German)
* https://wolles-elektronikkiste.de/en/ads1115-a-d-converter-with-amplifier (English)
*
***************************************************************************/
#include<ADS1115_WE.h>
#include<Wire.h>
#define I2C_ADDRESS 0x48
volatile int interruptPin = 2;
int ledPin = 10;
volatile bool outOfLimit = false;
/* There are several ways to create your ADS1115_WE object:
* ADS1115_WE adc = ADS1115_WE(); -> uses Wire / I2C Address = 0x48
* ADS1115_WE adc = ADS1115_WE(I2C_ADDRESS); -> uses Wire / I2C_ADDRESS
* ADS1115_WE adc = ADS1115_WE(&Wire); -> you can pass any TwoWire object / I2C Address = 0x48
* ADS1115_WE adc = ADS1115_WE(&Wire, I2C_ADDRESS); -> all together
*/
ADS1115_WE adc = ADS1115_WE(I2C_ADDRESS);
void setup() {
Wire.begin();
Serial.begin(9600);
pinMode(interruptPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
if(!adc.init()){
Serial.println("ADS1115 not connected!");
}
/* Set the voltage range of the ADC to adjust the gain
* Please note that you must not apply more than VDD + 0.3V to the input pins!
*
* ADS1115_RANGE_6144 -> +/- 6144 mV
* ADS1115_RANGE_4096 -> +/- 4096 mV
* ADS1115_RANGE_2048 -> +/- 2048 mV (default)
* ADS1115_RANGE_1024 -> +/- 1024 mV
* ADS1115_RANGE_0512 -> +/- 512 mV
* ADS1115_RANGE_0256 -> +/- 256 mV
*/
adc.setVoltageRange_mV(ADS1115_RANGE_6144); //comment line/change parameter to change range
/* Set the inputs to be compared
*
* ADS1115_COMP_0_1 -> compares 0 with 1 (default)
* ADS1115_COMP_0_3 -> compares 0 with 3
* ADS1115_COMP_1_3 -> compares 1 with 3
* ADS1115_COMP_2_3 -> compares 2 with 3
* ADS1115_COMP_0_GND -> compares 0 with GND
* ADS1115_COMP_1_GND -> compares 1 with GND
* ADS1115_COMP_2_GND -> compares 2 with GND
* ADS1115_COMP_3_GND -> compares 3 with GND
*/
adc.setCompareChannels(ADS1115_COMP_0_GND); //comment line/change parameter to change range
/* Set number of conversions out of limit after which alert pin asserts
* - or you can disable the alert (including conversion ready alert)
*
* ADS1115_ASSERT_AFTER_1 -> after 1 conversion
* ADS1115_ASSERT_AFTER_2 -> after 2 conversions
* ADS1115_ASSERT_AFTER_4 -> after 4 conversions
* ADS1115_DISABLE_ALERT -> disable comparator / alert pin (default)
*/
adc.setAlertPinMode(ADS1115_ASSERT_AFTER_1); // alternative: ...AFTER_2 or 4. If you disable this sketch does not work
/* Set the conversion rate in SPS (samples per second)
* Options should be self-explaining:
*
* ADS1115_8_SPS
* ADS1115_16_SPS
* ADS1115_32_SPS
* ADS1115_64_SPS
* ADS1115_128_SPS (default)
* ADS1115_250_SPS
* ADS1115_475_SPS
* ADS1115_860_SPS
*/
//adc.setConvRate(ADS1115_8_SPS); //uncomment if you want to change the default
/* Set continuous or single shot mode:
*
* ADS1115_CONTINUOUS -> continuous mode
* ADS1115_SINGLE -> single shot mode (default)
*/
adc.setMeasureMode(ADS1115_CONTINUOUS); //comment or change you want to change to single shot
/* Choose maximum limit or maximum and minimum alert limit (window) in volts - alert pin will
* assert when measured values are beyond the maximum limit or outside the window
* Upper limit first: setAlertLimit_V(MODE, maximum, minimum)
* In max limit mode the minimum value is the limit where the alert pin assertion is cleared
* again (if not latched!)
*
* ADS1115_MAX_LIMIT
* ADS1115_WINDOW
*
*/
adc.setAlertModeAndLimit_V(ADS1115_WINDOW, 3.0, 1.5); //you can change modes / limits
/* Enable or disable latch. If latch is enabled the alert pin will assert until the
* conversion register is read (getResult functions). If disabled the alert pin assertion
* will be cleared with next value within limits.
*
* ADS1115_LATCH_DISABLED (default)
* ADS1115_LATCH_ENABLED
*/
//adc.setAlertLatch(ADS1115_LATCH_ENABLED); //uncomment if you want to change the default
/* Sets the alert pin polarity if active:
*
* ADS1115_ACT_LOW -> active low (default)
* ADS1115_ACT_HIGH -> active high
*/
//adc.setAlertPol(ADS1115_ACT_LOW); //uncomment if you want to change the default
/* With this function the alert pin will assert, when a conversion is ready.
* In order to deactivate, use the setAlertLimit_V function
*/
//adc.setAlertPinToConversionReady(); //uncomment if you want to change the default
Serial.println("ADS1115 Example Sketch - uses the Alert Pin / Window Mode");
Serial.println();
Serial.println("Waiting for Value out of Limit");
attachInterrupt(digitalPinToInterrupt(interruptPin), outOfLimitAlert, FALLING);
}
void loop() {
float voltage = 0.0;
if(outOfLimit){
voltage = adc.getResult_V();
Serial.print("Voltage [V]: ");
Serial.println(voltage);
digitalWrite(ledPin,HIGH);
delay(1000);
digitalWrite(ledPin,LOW);
outOfLimit = false;
attachInterrupt(digitalPinToInterrupt(interruptPin), outOfLimitAlert, FALLING);
}
}
void outOfLimitAlert(){
detachInterrupt(interruptPin);
outOfLimit = true;
}

View File

@@ -0,0 +1,156 @@
/***************************************************************************
* Example sketch for the ADS1115_WE library
*
* This sketch shows how you can use the alert pin with the latch function. The
* only difference to Alert_Window_Mode.ino is that latch is enabled (line 113)
* and that the alert needs to be cleared (line 144). Try and see the difference.
* As an alternative to the unlatchAlertPin function you can use getResult_V.
* Internally clearAlert just performs a read of the conversion register.
*
* Further information can be found on:
* https://wolles-elektronikkiste.de/ads1115 (German)
* https://wolles-elektronikkiste.de/en/ads1115-a-d-converter-with-amplifier (English)
*
***************************************************************************/
#include<ADS1115_WE.h>
#include<Wire.h>
#define I2C_ADDRESS 0x48
volatile int interruptPin = 2;
int ledPin = 10;
volatile bool outOfLimit = false;
/* There are several ways to create your ADS1115_WE object:
* ADS1115_WE adc = ADS1115_WE(); -> uses Wire / I2C Address = 0x48
* ADS1115_WE adc = ADS1115_WE(I2C_ADDRESS); -> uses Wire / I2C_ADDRESS
* ADS1115_WE adc = ADS1115_WE(&Wire); -> you can pass any TwoWire object / I2C Address = 0x48
* ADS1115_WE adc = ADS1115_WE(&Wire, I2C_ADDRESS); -> all together
*/
ADS1115_WE adc = ADS1115_WE(I2C_ADDRESS);
void setup() {
Wire.begin();
Serial.begin(9600);
pinMode(interruptPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
if(!adc.init()){
Serial.println("ADS1115 not connected!");
}
/* Set the voltage range of the ADC to adjust the gain
* Please note that you must not apply more than VDD + 0.3V to the input pins!
*
* ADS1115_RANGE_6144 -> +/- 6144 mV
* ADS1115_RANGE_4096 -> +/- 4096 mV
* ADS1115_RANGE_2048 -> +/- 2048 mV (default)
* ADS1115_RANGE_1024 -> +/- 1024 mV
* ADS1115_RANGE_0512 -> +/- 512 mV
* ADS1115_RANGE_0256 -> +/- 256 mV
*/
adc.setVoltageRange_mV(ADS1115_RANGE_6144); //comment line/change parameter to change range
/* Set the inputs to be compared
*
* ADS1115_COMP_0_1 -> compares 0 with 1 (default)
* ADS1115_COMP_0_3 -> compares 0 with 3
* ADS1115_COMP_1_3 -> compares 1 with 3
* ADS1115_COMP_2_3 -> compares 2 with 3
* ADS1115_COMP_0_GND -> compares 0 with GND
* ADS1115_COMP_1_GND -> compares 1 with GND
* ADS1115_COMP_2_GND -> compares 2 with GND
* ADS1115_COMP_3_GND -> compares 3 with GND
*/
adc.setCompareChannels(ADS1115_COMP_0_GND); //uncomment if you want to change the default
/* Set number of conversions out of limit after which the alert pin will assert
* - or you can disable the alert (including conversion ready alert)
*
* ADS1115_ASSERT_AFTER_1 -> after 1 conversion
* ADS1115_ASSERT_AFTER_2 -> after 2 conversions
* ADS1115_ASSERT_AFTER_4 -> after 4 conversions
* ADS1115_DISABLE_ALERT -> disable comparator / alert pin (default)
*/
adc.setAlertPinMode(ADS1115_ASSERT_AFTER_1); // you can also choose ...AFTER_2 or 4 for this sketch
/* Set the conversion rate in SPS (samples per second)
* Options should be self-explaining:
*
* ADS1115_8_SPS
* ADS1115_16_SPS
* ADS1115_32_SPS
* ADS1115_64_SPS
* ADS1115_128_SPS (default)
* ADS1115_250_SPS
* ADS1115_475_SPS
* ADS1115_860_SPS
*/
//adc.setConvRate(ADS1115_8_SPS); //uncomment if you want to change the default
/* Set continuous or single shot mode:
*
* ADS1115_CONTINUOUS -> continuous mode
* ADS1115_SINGLE -> single shot mode (default)
*/
adc.setMeasureMode(ADS1115_CONTINUOUS); //comment or change if you want to change single shot
/* Choose maximum limit or maximum and minimum alert limit (window) in volts - alert pin will
* assert when measured values are beyond the maximum limit or outside the window
* Upper limit first: setAlertLimit_V(MODE, maximum, minimum)
* In max limit mode the minimum value is the limit where the alert pin assertion will be cleared
* again (if not latched!)
*
* ADS1115_MAX_LIMIT
* ADS1115_WINDOW
*
*/
adc.setAlertModeAndLimit_V(ADS1115_WINDOW, 3.0, 1.5); //uncomment if you want to change the default
/* Enable or disable latch. If latch is enabled the alert pin will be active until the
* conversion register is read (getResult functions). If disabled the alert pin assertion
* will be cleared with next value within limits.
*
* ADS1115_LATCH_DISABLED (default)
* ADS1115_LATCH_ENABLED
*/
adc.setAlertLatch(ADS1115_LATCH_ENABLED); //uncomment if you want to change the default
/* Sets the alert pin polarity if active:
*
* ADS1115_ACT_LOW -> active low (default)
* ADS1115_ACT_HIGH -> active high
*/
//adc.setAlertPol(ADS1115_ACT_LOW); //uncomment if you want to change the default
/* With this function the alert pin will assert, when a conversion is ready.
* In order to deactivate, use the setAlertLimit_V function
*/
//adc.setAlertPinToConversionReady(); //uncomment if you want to change the default
Serial.println("ADS1115 Example Sketch - uses the Alert Pin / Window Mode / Latch enabled");
Serial.println();
Serial.println("Waiting for Value out of Limit");
attachInterrupt(digitalPinToInterrupt(interruptPin), outOfLimitAlert, FALLING);
}
void loop() {
float voltage = 0.0;
if(outOfLimit){
voltage = adc.getResult_V();
Serial.print("Voltage [V]: ");
Serial.println(voltage);
digitalWrite(ledPin,HIGH);
delay(1000);
digitalWrite(ledPin,LOW);
outOfLimit = false;
attachInterrupt(digitalPinToInterrupt(interruptPin), outOfLimitAlert, FALLING);
adc.clearAlert(); // unlatches the alert Pin (alternatively use getResult_V)
}
}
void outOfLimitAlert(){
detachInterrupt(interruptPin);
outOfLimit = true;
}

View File

@@ -0,0 +1,194 @@
/***************************************************************************
* Example sketch for the ADS1115_WE library
*
* This sketch shows how to use the Auto Range function of the AD1115_WE library.
*
* Further information can be found on:
* https://wolles-elektronikkiste.de/ads1115 (German)
* https://wolles-elektronikkiste.de/en/ads1115-a-d-converter-with-amplifier (English)
*
***************************************************************************/
#include<ADS1115_WE.h>
#include<Wire.h>
#define I2C_ADDRESS 0x48
/* There are several ways to create your ADS1115_WE object:
* ADS1115_WE adc = ADS1115_WE(); -> uses Wire / I2C Address = 0x48
* ADS1115_WE adc = ADS1115_WE(I2C_ADDRESS); -> uses Wire / I2C_ADDRESS
* ADS1115_WE adc = ADS1115_WE(&Wire); -> you can pass any TwoWire object / I2C Address = 0x48
* ADS1115_WE adc = ADS1115_WE(&Wire, I2C_ADDRESS); -> all together
*/
ADS1115_WE adc = ADS1115_WE(I2C_ADDRESS);
void setup() {
Wire.begin();
Serial.begin(9600);
if(!adc.init()){
Serial.println("ADS1115 not connected!");
}
/* Set the voltage range of the ADC to adjust the gain
* Please note that you must not apply more than VDD + 0.3V to the input pins!
*
* ADS1115_RANGE_6144 -> +/- 6144 mV
* ADS1115_RANGE_4096 -> +/- 4096 mV
* ADS1115_RANGE_2048 -> +/- 2048 mV (default)
* ADS1115_RANGE_1024 -> +/- 1024 mV
* ADS1115_RANGE_0512 -> +/- 512 mV
* ADS1115_RANGE_0256 -> +/- 256 mV
*/
adc.setVoltageRange_mV(ADS1115_RANGE_6144); //comment line/change parameter to change range
/* Set the inputs to be compared
*
* ADS1115_COMP_0_1 -> compares 0 with 1 (default)
* ADS1115_COMP_0_3 -> compares 0 with 3
* ADS1115_COMP_1_3 -> compares 1 with 3
* ADS1115_COMP_2_3 -> compares 2 with 3
* ADS1115_COMP_0_GND -> compares 0 with GND
* ADS1115_COMP_1_GND -> compares 1 with GND
* ADS1115_COMP_2_GND -> compares 2 with GND
* ADS1115_COMP_3_GND -> compares 3 with GND
*/
adc.setCompareChannels(ADS1115_COMP_0_GND); //comment line/change parameter to change channel
/* Set number of conversions after which the alert pin asserts
* - or you can disable the alert
*
* ADS1115_ASSERT_AFTER_1 -> after 1 conversion
* ADS1115_ASSERT_AFTER_2 -> after 2 conversions
* ADS1115_ASSERT_AFTER_4 -> after 4 conversions
* ADS1115_DISABLE_ALERT -> disable comparator / alert pin (default)
*/
//adc.setAlertPinMode(ADS1115_ASSERT_AFTER_1); //uncomment if you want to change the default
/* Set the conversion rate in SPS (samples per second)
* Options should be self-explaining:
*
* ADS1115_8_SPS
* ADS1115_16_SPS
* ADS1115_32_SPS
* ADS1115_64_SPS
* ADS1115_128_SPS (default)
* ADS1115_250_SPS
* ADS1115_475_SPS
* ADS1115_860_SPS
*/
adc.setConvRate(ADS1115_64_SPS); //uncomment if you want to change the default
/* Set continuous or single shot mode:
*
* ADS1115_CONTINUOUS -> continuous mode
* ADS1115_SINGLE -> single shot mode (default)
*/
adc.setMeasureMode(ADS1115_CONTINUOUS); //comment line/change parameter to change mode
/* Choose maximum limit or maximum and minimum alert limit (window) in Volt - alert pin will
* assert when measured values are beyond the maximum limit or outside the window
* Upper limit first: setAlertLimit_V(MODE, maximum, minimum)
* In max limit mode the minimum value is the limit where the alert pin assertion will be
* cleared (if not latched)
*
* ADS1115_MAX_LIMIT
* ADS1115_WINDOW
*
*/
//adc.setAlertModeAndLimit_V(ADS1115_MAX_LIMIT, 3.0, 1.5); //uncomment if you want to change the default
/* Enable or disable latch. If latch is enabled the alert pin will assert until the
* conversion register is read (getResult functions). If disabled the alert pin assertion will be
* cleared with next value within limits.
*
* ADS1115_LATCH_DISABLED (default)
* ADS1115_LATCH_ENABLED
*/
//adc.setAlertLatch(ADS1115_LATCH_ENABLED); //uncomment if you want to change the default
/* Sets the alert pin polarity if active:
*
* ADS1115_ACT_LOW -> active low (default)
* ADS1115_ACT_HIGH -> active high
*/
//adc.setAlertPol(ADS1115_ACT_LOW); //uncomment if you want to change the default
/* With this function the alert pin will assert, when a conversion is ready.
* In order to deactivate, use the setAlertLimit_V function
*/
//adc.setAlertPinToConversionReady(); //uncomment if you want to change the default
/* Enable or disable permanent automatic range selection mode. If enabled, the range will
* change if the measured values are outside of 30-80% of the maximum value of the current
* range.
* !!! Use EITHER this function once OR setAutoRange() whenever needed (see below) !!!
*/
adc.setPermanentAutoRangeMode(true);
Serial.println("ADS1115 Example Sketch - Continuous Mode with Auto Range");
Serial.println();
}
void loop() {
Serial.print("Channel 0 - ");
readChannel(ADS1115_COMP_0_GND);
Serial.print("Channel 1 - ");
readChannel(ADS1115_COMP_1_GND);
Serial.print("Channel 2 - ");
readChannel(ADS1115_COMP_2_GND);
Serial.print("Channel 3 - ");
readChannel(ADS1115_COMP_3_GND);
Serial.println("-------------------------------");
delay(1000);
}
void readChannel(ADS1115_MUX channel) {
float voltage = 0.0;
adc.setCompareChannels(channel);
/* setAutoRange() switches to the highest range (+/- 6144 mV), measures the current
* voltage and then switches to the lowest range where the current value is still
* below 80% of the maximum value of the range. The function is only suitable if you
* expect stable or slowly changing voltages. setAutoRange needs roughly the time you
* would need for three conversions.
* If the ADS115 is in single shot mode, setAutoRange() will switch into continuous
* mode to measure a value and switch back again.
* !!! Use EITHER this function whenever needed OR setPermanentAutoRangeMode(true) once !!!
*/
//adc.setAutoRange(); //use either this or setPermanentAutoRangeMode(true)
voltage = adc.getResult_V(); // alternative: getResult_mV for Millivolt
printVoltageRange(); // this is just to show that the range is changing with changing voltages
Serial.println(voltage);
}
void printVoltageRange(){
unsigned int voltageRange = adc.getVoltageRange_mV();
Serial.print("Range: ");
switch(voltageRange){
case 6144:
Serial.print("+/- 6144 mV, Voltage [V]: ");
break;
case 4096:
Serial.print("+/- 4096 mV, Voltage [V]: ");
break;
case 2048:
Serial.print("+/- 2048 mV, Voltage [V]: ");
break;
case 1024:
Serial.print("+/- 1024 mV, Voltage [V]: ");
break;
case 512:
Serial.print("+/- 512 mV, Voltage [V]: ");
break;
case 256:
Serial.print("+/- 256 mV, Voltage [V]: ");
break;
default:
Serial.println("Something went wrong");
}
}

View File

@@ -0,0 +1,162 @@
/***************************************************************************
* Example sketch for the ADS1115_WE library
*
* This sketch shows how to use the ADS1115 in continuous mode.
*
* Further information can be found on:
* https://wolles-elektronikkiste.de/ads1115 (German)
* https://wolles-elektronikkiste.de/en/ads1115-a-d-converter-with-amplifier (English)
*
***************************************************************************/
#include<ADS1115_WE.h>
#include<Wire.h>
#define I2C_ADDRESS 0x48
/* There are several ways to create your ADS1115_WE object:
* ADS1115_WE adc = ADS1115_WE(); -> uses Wire / I2C Address = 0x48
* ADS1115_WE adc = ADS1115_WE(I2C_ADDRESS); -> uses Wire / I2C_ADDRESS
* ADS1115_WE adc = ADS1115_WE(&Wire); -> you can pass any TwoWire object / I2C Address = 0x48
* ADS1115_WE adc = ADS1115_WE(&Wire, I2C_ADDRESS); -> all together
*/
ADS1115_WE adc = ADS1115_WE(I2C_ADDRESS);
void setup() {
Wire.begin();
Serial.begin(9600);
if(!adc.init()){
Serial.println("ADS1115 not connected!");
}
/* Set the voltage range of the ADC to adjust the gain
* Please note that you must not apply more than VDD + 0.3V to the input pins!
*
* ADS1115_RANGE_6144 -> +/- 6144 mV
* ADS1115_RANGE_4096 -> +/- 4096 mV
* ADS1115_RANGE_2048 -> +/- 2048 mV (default)
* ADS1115_RANGE_1024 -> +/- 1024 mV
* ADS1115_RANGE_0512 -> +/- 512 mV
* ADS1115_RANGE_0256 -> +/- 256 mV
*/
adc.setVoltageRange_mV(ADS1115_RANGE_6144); //comment line/change parameter to change range
/* Set the inputs to be compared
*
* ADS1115_COMP_0_1 -> compares 0 with 1 (default)
* ADS1115_COMP_0_3 -> compares 0 with 3
* ADS1115_COMP_1_3 -> compares 1 with 3
* ADS1115_COMP_2_3 -> compares 2 with 3
* ADS1115_COMP_0_GND -> compares 0 with GND
* ADS1115_COMP_1_GND -> compares 1 with GND
* ADS1115_COMP_2_GND -> compares 2 with GND
* ADS1115_COMP_3_GND -> compares 3 with GND
*/
adc.setCompareChannels(ADS1115_COMP_0_GND); //comment line/change parameter to change channel
/* Set number of conversions after which the alert pin asserts
* - or you can disable the alert
*
* ADS1115_ASSERT_AFTER_1 -> after 1 conversion
* ADS1115_ASSERT_AFTER_2 -> after 2 conversions
* ADS1115_ASSERT_AFTER_4 -> after 4 conversions
* ADS1115_DISABLE_ALERT -> disable comparator / alert pin (default)
*/
//adc.setAlertPinMode(ADS1115_ASSERT_AFTER_1); //uncomment if you want to change the default
/* Set the conversion rate in SPS (samples per second)
* Options should be self-explaining:
*
* ADS1115_8_SPS
* ADS1115_16_SPS
* ADS1115_32_SPS
* ADS1115_64_SPS
* ADS1115_128_SPS (default)
* ADS1115_250_SPS
* ADS1115_475_SPS
* ADS1115_860_SPS
*/
// adc.setConvRate(ADS1115_8_SPS); //uncomment if you want to change the default
/* Set continuous or single shot mode:
*
* ADS1115_CONTINUOUS -> continuous mode
* ADS1115_SINGLE -> single shot mode (default)
*/
adc.setMeasureMode(ADS1115_CONTINUOUS); //comment line/change parameter to change mode
/* Choose maximum limit or maximum and minimum alert limit (window) in Volt - alert pin will
* assert when measured values are beyond the maximum limit or outside the window
* Upper limit first: setAlertLimit_V(MODE, maximum, minimum)
* In max limit mode the minimum value is the limit where the alert pin assertion will be
* cleared (if not latched)
*
* ADS1115_MAX_LIMIT
* ADS1115_WINDOW
*
*/
//adc.setAlertModeAndLimit_V(ADS1115_MAX_LIMIT, 3.0, 1.5); //uncomment if you want to change the default
/* Enable or disable latch. If latch is enabled the alert pin will assert until the
* conversion register is read (getResult functions). If disabled the alert pin assertion will be
* cleared with next value within limits.
*
* ADS1115_LATCH_DISABLED (default)
* ADS1115_LATCH_ENABLED
*/
//adc.setAlertLatch(ADS1115_LATCH_ENABLED); //uncomment if you want to change the default
/* Sets the alert pin polarity if active:
*
* ADS1115_ACT_LOW -> active low (default)
* ADS1115_ACT_HIGH -> active high
*/
//adc.setAlertPol(ADS1115_ACT_LOW); //uncomment if you want to change the default
/* With this function the alert pin will assert, when a conversion is ready.
* In order to deactivate, use the setAlertLimit_V function
*/
//adc.setAlertPinToConversionReady(); //uncomment if you want to change the default
Serial.println("ADS1115 Example Sketch - Continuous Mode");
Serial.println("All values in volts");
Serial.println();
}
/* If you change the compare channels you can immediately read values from the conversion
* register, although they might belong to the former channel if no precautions are taken.
* It takes about the time needed for two conversions to get the correct data. In single
* shot mode you can use the isBusy() function to wait for data from the new channel. This
* does not work in continuous mode.
* To solve this issue the library adds a delay after change of channels if you are in contunuous
* mode. The length of the delay is adjusted to the conversion rate. But be aware that the output
* rate will be much lower that the conversion rate if you change channels frequently.
*/
void loop() {
float voltage = 0.0;
Serial.print("0: ");
voltage = readChannel(ADS1115_COMP_0_GND);
Serial.print(voltage);
Serial.print(", 1: ");
voltage = readChannel(ADS1115_COMP_1_GND);
Serial.print(voltage);
Serial.print(", 2: ");
voltage = readChannel(ADS1115_COMP_2_GND);
Serial.print(voltage);
Serial.print(", 3: ");
voltage = readChannel(ADS1115_COMP_3_GND);
Serial.println(voltage);
delay(1000);
}
float readChannel(ADS1115_MUX channel) {
float voltage = 0.0;
adc.setCompareChannels(channel);
voltage = adc.getResult_V(); // alternative: getResult_mV for Millivolt
return voltage;
}

View File

@@ -0,0 +1,162 @@
/***************************************************************************
* Example sketch for the ADS1015_WE library
*
* This sketch shows how to use the ADS1015 in continuous mode.
*
* Further information can be found on:
* https://wolles-elektronikkiste.de/ads1115 (German)
* https://wolles-elektronikkiste.de/en/ads1115-a-d-converter-with-amplifier (English)
*
***************************************************************************/
#include<ADS1015_WE.h>
#include<Wire.h>
#define I2C_ADDRESS 0x48
/* There are several ways to create your ADS1015_WE object:
* ADS1015_WE adc = ADS1015_WE(); -> uses Wire / I2C Address = 0x48
* ADS1015_WE adc = ADS1015_WE(I2C_ADDRESS); -> uses Wire / I2C_ADDRESS
* ADS1015_WE adc = ADS1015_WE(&Wire); -> you can pass any TwoWire object / I2C Address = 0x48
* ADS1015_WE adc = ADS1015_WE(&Wire, I2C_ADDRESS); -> all together
*/
ADS1015_WE adc = ADS1015_WE(I2C_ADDRESS);
void setup() {
bool useADS1015 = true;
Wire.begin();
Serial.begin(9600);
if(!adc.init(useADS1015)){ // passing true will tell the lib that an ADS1015 is used
Serial.println("ADS1015 not connected!");
}
/* Set the voltage range of the ADC to adjust the gain
* Please note that you must not apply more than VDD + 0.3V to the input pins!
*
* ADS1015_RANGE_6144 -> +/- 6144 mV
* ADS1015_RANGE_4096 -> +/- 4096 mV
* ADS1015_RANGE_2048 -> +/- 2048 mV (default)
* ADS1015_RANGE_1024 -> +/- 1024 mV
* ADS1015_RANGE_0512 -> +/- 512 mV
* ADS1015_RANGE_0256 -> +/- 256 mV
*/
adc.setVoltageRange_mV(ADS1015_RANGE_6144); //comment line/change parameter to change range
/* Set the inputs to be compared
*
* ADS1015_COMP_0_1 -> compares 0 with 1 (default)
* ADS1015_COMP_0_3 -> compares 0 with 3
* ADS1015_COMP_1_3 -> compares 1 with 3
* ADS1015_COMP_2_3 -> compares 2 with 3
* ADS1015_COMP_0_GND -> compares 0 with GND
* ADS1015_COMP_1_GND -> compares 1 with GND
* ADS1015_COMP_2_GND -> compares 2 with GND
* ADS1015_COMP_3_GND -> compares 3 with GND
*/
adc.setCompareChannels(ADS1015_COMP_0_GND); //comment line/change parameter to change channel
/* Set number of conversions after which the alert pin asserts
* - or you can disable the alert
*
* ADS1015_ASSERT_AFTER_1 -> after 1 conversion
* ADS1015_ASSERT_AFTER_2 -> after 2 conversions
* ADS1015_ASSERT_AFTER_4 -> after 4 conversions
* ADS1015_DISABLE_ALERT -> disable comparator / alert pin (default)
*/
//adc.setAlertPinMode(ADS1015_ASSERT_AFTER_1); //uncomment if you want to change the default
/* Set the conversion rate in SPS (samples per second)
* Options should be self-explaining:
*
* ADS1015_128_SPS
* ADS1015_250_SPS
* ADS1015_490_SPS
* ADS1015_920_SPS
* ADS1015_1600_SPS (default)
* ADS1015_2400_SPS
* ADS1015_3300_SPS
*/
//adc.setConvRate(ADS1015_3300_SPS); //uncomment if you want to change the default
/* Set continuous or single shot mode:
*
* ADS1015_CONTINUOUS -> continuous mode
* ADS1015_SINGLE -> single shot mode (default)
*/
adc.setMeasureMode(ADS1015_CONTINUOUS); //comment line/change parameter to change mode
/* Choose maximum limit or maximum and minimum alert limit (window) in Volt - alert pin will
* assert when measured values are beyond the maximum limit or outside the window
* Upper limit first: setAlertLimit_V(MODE, maximum, minimum)
* In max limit mode the minimum value is the limit where the alert pin assertion will be
* cleared (if not latched)
*
* ADS1015_MAX_LIMIT
* ADS1015_WINDOW
*
*/
//adc.setAlertModeAndLimit_V(ADS1015_MAX_LIMIT, 3.0, 1.5); //uncomment if you want to change the default
/* Enable or disable latch. If latch is enabled the alert pin will assert until the
* conversion register is read (getResult functions). If disabled the alert pin assertion will be
* cleared with next value within limits.
*
* ADS1015_LATCH_DISABLED (default)
* ADS1015_LATCH_ENABLED
*/
//adc.setAlertLatch(ADS1015_LATCH_ENABLED); //uncomment if you want to change the default
/* Sets the alert pin polarity if active:
*
* ADS1015_ACT_LOW -> active low (default)
* ADS1015_ACT_HIGH -> active high
*/
//adc.setAlertPol(ADS1015_ACT_LOW); //uncomment if you want to change the default
/* With this function the alert pin will assert, when a conversion is ready.
* In order to deactivate, use the setAlertLimit_V function
*/
//adc.setAlertPinToConversionReady(); //uncomment if you want to change the default
Serial.println("ADS1015 Example Sketch - Continuous Mode");
Serial.println("All values in volts");
Serial.println();
}
/* If you change the compare channels you can immediately read values from the conversion
* register, although they might belong to the former channel if no precautions are taken.
* It takes about the time needed for two conversions to get the correct data. In single
* shot mode you can use the isBusy() function to wait for data from the new channel. This
* does not work in continuous mode.
* To solve this issue the library adds a delay after change of channels if you are in contunuous
* mode. The length of the delay is adjusted to the conversion rate. But be aware that the output
* rate will be much lower that the conversion rate if you change channels frequently.
*/
void loop() {
float voltage = 0.0;
Serial.print("0: ");
voltage = readChannel(ADS1015_COMP_0_GND);
Serial.print(voltage);
Serial.print(", 1: ");
voltage = readChannel(ADS1015_COMP_1_GND);
Serial.print(voltage);
Serial.print(", 2: ");
voltage = readChannel(ADS1015_COMP_2_GND);
Serial.print(voltage);
Serial.print(", 3: ");
voltage = readChannel(ADS1015_COMP_3_GND);
Serial.println(voltage);
delay(1000);
}
float readChannel(ADS1015_MUX channel) {
float voltage = 0.0;
adc.setCompareChannels(channel);
voltage = adc.getResult_V(); // alternative: getResult_mV for Millivolt
return voltage;
}

View File

@@ -0,0 +1,183 @@
/***************************************************************************
* Example sketch for the ADS1115_WE library
*
* This sketch shows how to use the ADS1115 module with the TinyWireM library:
* https://github.com/adafruit/TinyWireM
* This allows you to run the ADS1115_WE library on an ATtiny85, for example.
*
* For this specific sketch you also need library Tiny4KOLED to display the
* measured values on a SSD1306 OLED display:
* https://github.com/datacute/Tiny4kOLED
*
* Further information can be found on:
* https://wolles-elektronikkiste.de/ads1115 (German)
* https://wolles-elektronikkiste.de/en/ads1115-a-d-converter-with-amplifier (English)
*
***************************************************************************/
/* !!!! IN ORDER TO USE TinyWireM YOU NEED TO UNCOMMENT #define USE_TINY_WIRE_M_ !!!!
* !!!! IN ADS1115_config.h WHICH YOU FIND IN THE libraries/ADS1115_WE/src FOLDER !!!! !!!!
*/
#include <TinyWireM.h>
#include <Tiny4kOLED.h>
#include<ADS1115_WE.h>
#define ADS1115_I2C_ADDR 0x48
uint8_t width = 128;
uint8_t height = 64;
/* There are two ways to create your ADS1115_WE object:
* ADS1115_WE adc = ADS1115_WE() -> uses Wire / I2C Address = 0x48
* ADS1115_WE adc = ADS1115_WE(I2C_ADDRESS) -> uses Wire / I2C_ADDRESS
*/
ADS1115_WE adc = ADS1115_WE(ADS1115_I2C_ADDR);
void setup() {
TinyWireM.begin();
oled.begin(width, height, sizeof(tiny4koled_init_128x64br), tiny4koled_init_128x64br);
oled.clear();
oled.setFont(FONT6X8);
oled.on();
if(!adc.init()){
oled.print("ADS1115 not connected");
while(1){}
}
else{
oled.print("ADS1115 connected");
delay(1000);
oled.clear();
}
/* Set the voltage range of the ADC to adjust the gain
* Please note that you must not apply more than VDD + 0.3V to the input pins!
*
* ADS1115_RANGE_6144 -> +/- 6144 mV
* ADS1115_RANGE_4096 -> +/- 4096 mV
* ADS1115_RANGE_2048 -> +/- 2048 mV (default)
* ADS1115_RANGE_1024 -> +/- 1024 mV
* ADS1115_RANGE_0512 -> +/- 512 mV
* ADS1115_RANGE_0256 -> +/- 256 mV
*/
adc.setVoltageRange_mV(ADS1115_RANGE_6144); //comment line/change parameter to change range
/* Set the inputs to be compared
*
* ADS1115_COMP_0_1 -> compares 0 with 1 (default)
* ADS1115_COMP_0_3 -> compares 0 with 3
* ADS1115_COMP_1_3 -> compares 1 with 3
* ADS1115_COMP_2_3 -> compares 2 with 3
* ADS1115_COMP_0_GND -> compares 0 with GND
* ADS1115_COMP_1_GND -> compares 1 with GND
* ADS1115_COMP_2_GND -> compares 2 with GND
* ADS1115_COMP_3_GND -> compares 3 with GND
*/
adc.setCompareChannels(ADS1115_COMP_0_GND); //comment line/change parameter to change channel
/* Set number of conversions after which the alert pin asserts
* - or you can disable the alert
*
* ADS1115_ASSERT_AFTER_1 -> after 1 conversion
* ADS1115_ASSERT_AFTER_2 -> after 2 conversions
* ADS1115_ASSERT_AFTER_4 -> after 4 conversions
* ADS1115_DISABLE_ALERT -> disable comparator / alert pin (default)
*/
//adc.setAlertPinMode(ADS1115_ASSERT_AFTER_1); //uncomment if you want to change the default
/* Set the conversion rate in SPS (samples per second)
* Options should be self-explaining:
*
* ADS1115_8_SPS
* ADS1115_16_SPS
* ADS1115_32_SPS
* ADS1115_64_SPS
* ADS1115_128_SPS (default)
* ADS1115_250_SPS
* ADS1115_475_SPS
* ADS1115_860_SPS
*/
// adc.setConvRate(ADS1115_8_SPS); //uncomment if you want to change the default
/* Set continuous or single shot mode:
*
* ADS1115_CONTINUOUS -> continuous mode
* ADS1115_SINGLE -> single shot mode (default)
*/
adc.setMeasureMode(ADS1115_CONTINUOUS); //comment line/change parameter to change mode
/* Choose maximum limit or maximum and minimum alert limit (window) in Volt - alert pin will
* assert when measured values are beyond the maximum limit or outside the window
* Upper limit first: setAlertLimit_V(MODE, maximum, minimum)
* In max limit mode the minimum value is the limit where the alert pin assertion will be
* cleared (if not latched)
*
* ADS1115_MAX_LIMIT
* ADS1115_WINDOW
*
*/
//adc.setAlertModeAndLimit_V(ADS1115_MAX_LIMIT, 3.0, 1.5); //uncomment if you want to change the default
/* Enable or disable latch. If latch is enabled the alert pin will assert until the
* conversion register is read (getResult functions). If disabled the alert pin assertion will be
* cleared with next value within limits.
*
* ADS1115_LATCH_DISABLED (default)
* ADS1115_LATCH_ENABLED
*/
//adc.setAlertLatch(ADS1115_LATCH_ENABLED); //uncomment if you want to change the default
/* Sets the alert pin polarity if active:
*
* ADS1115_ACT_LOW -> active low (default)
* ADS1115_ACT_HIGH -> active high
*/
//adc.setAlertPol(ADS1115_ACT_LOW); //uncomment if you want to change the default
/* With this function the alert pin will assert, when a conversion is ready.
* In order to deactivate, use the setAlertLimit_V function
*/
//adc.setAlertPinToConversionReady(); //uncomment if you want to change the default
}
/* If you change the compare channels you can immediately read values from the conversion
* register, although they might belong to the former channel if no precautions are taken.
* It takes about the time needed for two conversions to get the correct data. In single
* shot mode you can use the isBusy() function to wait for data from the new channel. This
* does not work in continuous mode.
* To solve this issue the library adds a delay after change of channels if you are in contunuous
* mode. The length of the delay is adjusted to the conversion rate. But be aware that the output
* rate will be much lower that the conversion rate if you change channels frequently.
*/
void loop() {
float voltage = 0.0;
adc.setCompareChannels(ADS1115_COMP_0_GND);
voltage = adc.getResult_V();
oled.setCursor(0,0);
oled.print("Channel 0 [V]: ");
oled.print(voltage);
oled.clearToEOL();
adc.setCompareChannels(ADS1115_COMP_1_GND);
voltage = adc.getResult_V();
oled.setCursor(0,2);
oled.print("Channel 1 [V]: ");
oled.print(voltage);
oled.clearToEOL();
adc.setCompareChannels(ADS1115_COMP_2_GND);
voltage = adc.getResult_V();
oled.setCursor(0,4);
oled.print("Channel 2 [V]: ");
oled.print(voltage);
oled.clearToEOL();
adc.setCompareChannels(ADS1115_COMP_3_GND);
voltage = adc.getResult_V();
oled.setCursor(0,6);
oled.print("Channel 3 [V]: ");
oled.print(voltage);
oled.clearToEOL();
delay(2000);
}

View File

@@ -0,0 +1,155 @@
/***************************************************************************
* Example sketch for the ADS1115_WE library
*
* This sketch shows how you can use the alert pin as conversion ready alert pin.
* It works in continuous mode as well as in single shot mode.
* Please note that you need to enable the alert pin with setAlertPinMode. Choose any
* parameter except ADS1115_DISABLE_ALERT.
*
* Further information can be found on:
* https://wolles-elektronikkiste.de/ads1115 (German)
* https://wolles-elektronikkiste.de/en/ads1115-a-d-converter-with-amplifier (English)
*
***************************************************************************/
#include<ADS1115_WE.h>
#include<Wire.h>
#define I2C_ADDRESS 0x48
int interruptPin = 2;
volatile bool convReady = false;
/* There are several ways to create your ADS1115_WE object:
* ADS1115_WE adc = ADS1115_WE(); -> uses Wire / I2C Address = 0x48
* ADS1115_WE adc = ADS1115_WE(I2C_ADDRESS); -> uses Wire / I2C_ADDRESS
* ADS1115_WE adc = ADS1115_WE(&Wire); -> you can pass any TwoWire object / I2C Address = 0x48
* ADS1115_WE adc = ADS1115_WE(&Wire, I2C_ADDRESS); -> all together
*/
ADS1115_WE adc = ADS1115_WE(I2C_ADDRESS);
void setup() {
Wire.begin();
Serial.begin(9600);
pinMode(interruptPin, INPUT_PULLUP);
if(!adc.init()){
Serial.println("ADS1115 not connected!");
}
/* Set the voltage range of the ADC to adjust the gain
* Please note that you must not apply more than VDD + 0.3V to the input pins!
*
* ADS1115_RANGE_6144 -> +/- 6144 mV
* ADS1115_RANGE_4096 -> +/- 4096 mV
* ADS1115_RANGE_2048 -> +/- 2048 mV (default)
* ADS1115_RANGE_1024 -> +/- 1024 mV
* ADS1115_RANGE_0512 -> +/- 512 mV
* ADS1115_RANGE_0256 -> +/- 256 mV
*/
adc.setVoltageRange_mV(ADS1115_RANGE_6144); //comment line/change parameter to change range
/* Set the inputs to be compared
*
* ADS1115_COMP_0_1 -> compares 0 with 1 (default)
* ADS1115_COMP_0_3 -> compares 0 with 3
* ADS1115_COMP_1_3 -> compares 1 with 3
* ADS1115_COMP_2_3 -> compares 2 with 3
* ADS1115_COMP_0_GND -> compares 0 with GND
* ADS1115_COMP_1_GND -> compares 1 with GND
* ADS1115_COMP_2_GND -> compares 2 with GND
* ADS1115_COMP_3_GND -> compares 3 with GND
*/
adc.setCompareChannels(ADS1115_COMP_0_GND); //comment line/change parameter to change channels
/* Set number of conversions out of limit after which the alert pin will assert
* - or you can disable the alert (including conversion ready alert)
*
* ADS1115_ASSERT_AFTER_1 -> after 1 conversion
* ADS1115_ASSERT_AFTER_2 -> after 2 conversions
* ADS1115_ASSERT_AFTER_4 -> after 4 conversions
* ADS1115_DISABLE_ALERT -> disable comparator / alert pin (default)
*/
adc.setAlertPinMode(ADS1115_ASSERT_AFTER_1); //needed in this sketch to enable alert pin (doesn't matter if you choose after 1,2 or 4)
/* Set the conversion rate in SPS (samples per second)
* Options should be self-explaining:
*
* ADS1115_8_SPS
* ADS1115_16_SPS
* ADS1115_32_SPS
* ADS1115_64_SPS
* ADS1115_128_SPS (default)
* ADS1115_250_SPS
* ADS1115_475_SPS
* ADS1115_860_SPS
*/
adc.setConvRate(ADS1115_8_SPS); //comment line/change parameter to change SPS
/* Set continuous or single shot mode:
*
* ADS1115_CONTINUOUS -> continuous mode
* ADS1115_SINGLE -> single shot mode (default)
*/
//adc.setMeasureMode(ADS1115_CONTINUOUS); // the conversion ready alert pin also works in continuous mode
/* Choose maximum limit or maximum and minimum alert limit (window) in volts - alert pin will
* assert when measured values are beyond the maximum limit or outside the window
* Upper limit first: setAlertLimit_V(MODE, maximum, minimum)
* In max limit mode the minimum value is the limit where the alert pin assertion will be cleared
* (if not latched)
*
* ADS1115_MAX_LIMIT
* ADS1115_WINDOW
*
*/
//adc.setAlertModeAndLimit_V(ADS1115_MAX_LIMIT, 3.0, 1.5); //uncomment if you want to change the default
/* Enable or disable latch. If latch is enabled the alert pin will assert until the
* conversion register is read (getResult functions). If disabled the alert pin assertion
* will be cleared with next value within limits.
*
* ADS1115_LATCH_DISABLED (default)
* ADS1115_LATCH_ENABLED
*/
//adc.setAlertLatch(ADS1115_LATCH_ENABLED); //uncomment if you want to change the default
/* Sets the alert pin polarity if active:
*
* ADS1115_ACT_LOW -> active low (default)
* ADS1115_ACT_HIGH -> active high
*/
//adc.setAlertPol(ADS1115_ACT_LOW); //uncomment if you want to change the default
/* With this function the alert pin assert, when a conversion is ready.
* In order to deactivate, use the setAlertLimit_V function
*/
adc.setAlertPinToConversionReady(); //needed for this sketch
Serial.println("ADS1115 Example Sketch - Single Shot, Conversion Ready Alert Pin controlled");
Serial.println();
attachInterrupt(digitalPinToInterrupt(interruptPin), convReadyAlert, FALLING);
adc.startSingleMeasurement();
}
/* In this example I measure 32 times before the result is output. This is only to slow down
* the output rate. I want to show that the output rate is controlled by the conversion ready
* signals and not by a delay.
*/
void loop() {
float voltage = 0.0;
static int counter = 0;
if(convReady){
counter++;
convReady = false;
if(counter==32){ // counter is 32, conversion rate is 8 SPS --> 4s
voltage = adc.getResult_V(); // alternative: getResult_mV for Millivolt
Serial.print("Channel 0 vs GND [V]: ");
Serial.println(voltage);
Serial.println("-------------------------------");
counter = 0;
}
adc.startSingleMeasurement();
}
}
void convReadyAlert(){
convReady = true;
}

View File

@@ -0,0 +1,94 @@
/***************************************************************************
* Example sketch for the ADS1115_WE library
*
* This sketch shows how to obtain results using different scales / formats.
*
* Further information can be found on:
* https://wolles-elektronikkiste.de/ads1115 (German)
* https://wolles-elektronikkiste.de/en/ads1115-a-d-converter-with-amplifier (English)
*
***************************************************************************/
#include <ADS1115_WE.h>
#include <Wire.h>
#define I2C_ADDRESS 0x48
/* There are several ways to create your ADS1115_WE object:
* ADS1115_WE adc = ADS1115_WE(); -> uses Wire / I2C Address = 0x48
* ADS1115_WE adc = ADS1115_WE(I2C_ADDRESS); -> uses Wire / I2C_ADDRESS
* ADS1115_WE adc = ADS1115_WE(&Wire); -> you can pass any TwoWire object / I2C Address = 0x48
* ADS1115_WE adc = ADS1115_WE(&Wire, I2C_ADDRESS); -> all together
*/
ADS1115_WE adc = ADS1115_WE(I2C_ADDRESS);
void setup() {
Wire.begin();
Serial.begin(9600);
if(!adc.init()){
Serial.println("ADS1115 not connected!");
}
adc.setVoltageRange_mV(ADS1115_RANGE_6144); //comment line/change parameter to change range
adc.setCompareChannels(ADS1115_COMP_0_1); //comment line/change parameter to change channel
adc.setMeasureMode(ADS1115_CONTINUOUS); //comment line/change parameter to change mode
Serial.println("ADS1115 Example Sketch - Results in different scales / formats");
Serial.println("All results are for channel 0 vs. GND");
Serial.println();
}
void loop() {
/* Output in Volt or in Millivolt */
float voltageInMillivolt = adc.getResult_mV();
Serial.print("Result in Millivolt [mV]: ");
Serial.println(voltageInMillivolt);
float voltageInVolt = adc.getResult_V();
Serial.print("Result in Volt [V]: ");
Serial.println(voltageInVolt);
/* Get the raw result from the conversion register. The conversion register
* contains the conversion result of the amplified (!) voltage. This means the
* value depends on the voltage as well as on the voltage range. E.g. if the
* voltage range is 6144 mV (ADS1115_RANGE_6144), +32768 is 6144 mV; if the
* range is 4096 mV, +32768 is 4096 mV, and so on. To be exact: +32768 would
* the range value, but the register max.value is 32767.
*/
int rawResult = adc.getRawResult();
Serial.print("Raw Result : ");
Serial.println(rawResult);
/* Scaling of the result to a different range:
* The results in the conversion register are in a range of -32768 to +32767
* You might want to receive the result in a different scale, e.g. -1024 to 1023.
* For -1024 to 1023, and if you have chosen e.g. ADS1115_RANGE_4096, 0 Volt would
* give 0 as result and 4096 * (32767/32768) mV would give 1023. -4096 mV would
* give -1024.
*/
int scaledResult = adc.getResultWithRange(-1024, 1023);
Serial.print("Scaled result : ");
Serial.println(scaledResult);
/* Scaling of the result to a different range plus scaling to a voltage range:
* You can use this variant if you also want to scale to a voltage range. E.g. in
* in order to get results equivalent to an Arduino UNO (10 bit, 5000 mV range), you
* would choose getResultWithRange(-1024, 1023, 5000). A difference to the Arduino
* UNO is that you can measure negative voltages.
* You have to ensure that the voltage range you scale to is smaller than the
* measuring voltage range. For this example only ADS1115_RANGE_6144 would cover the
* scale up to 5000 mV.
*/
int scaledResultWithMaxVoltage = adc.getResultWithRange(-1024, 1023, 5000);
Serial.print("Scaled result with voltage scale : ");
Serial.println(scaledResultWithMaxVoltage);
/* This function returns the voltage range ADS1115_RANGE_XXXX in Millivolt */
unsigned int voltRange = adc.getVoltageRange_mV();
Serial.print("Voltage Range of ADS1115 [mV]: ");
Serial.println(voltRange);
Serial.println("-------------------------------");
delay(2000);
}

View File

@@ -0,0 +1,154 @@
/***************************************************************************
* Example sketch for the ADS1115_WE library
*
* This sketch shows how to use the ADS1115 in single shot mode.
*
* Further information can be found on:
* https://wolles-elektronikkiste.de/ads1115 (German)
* https://wolles-elektronikkiste.de/en/ads1115-a-d-converter-with-amplifier (English)
*
***************************************************************************/
#include<ADS1115_WE.h>
#include<Wire.h>
#define I2C_ADDRESS 0x48
/* There are several ways to create your ADS1115_WE object:
* ADS1115_WE adc = ADS1115_WE(); -> uses Wire / I2C Address = 0x48
* ADS1115_WE adc = ADS1115_WE(I2C_ADDRESS); -> uses Wire / I2C_ADDRESS
* ADS1115_WE adc = ADS1115_WE(&Wire); -> you can pass any TwoWire object / I2C Address = 0x48
* ADS1115_WE adc = ADS1115_WE(&Wire, I2C_ADDRESS); -> all together
*/
ADS1115_WE adc = ADS1115_WE(I2C_ADDRESS);
void setup() {
Wire.begin();
Serial.begin(9600);
if(!adc.init()){
Serial.println("ADS1115 not connected!");
}
/* Set the voltage range of the ADC to adjust the gain
* Please note that you must not apply more than VDD + 0.3V to the input pins!
*
* ADS1115_RANGE_6144 -> +/- 6144 mV
* ADS1115_RANGE_4096 -> +/- 4096 mV
* ADS1115_RANGE_2048 -> +/- 2048 mV (default)
* ADS1115_RANGE_1024 -> +/- 1024 mV
* ADS1115_RANGE_0512 -> +/- 512 mV
* ADS1115_RANGE_0256 -> +/- 256 mV
*/
adc.setVoltageRange_mV(ADS1115_RANGE_6144); //comment line/change parameter to change range
/* Set the inputs to be compared
*
* ADS1115_COMP_0_1 -> compares 0 with 1 (default)
* ADS1115_COMP_0_3 -> compares 0 with 3
* ADS1115_COMP_1_3 -> compares 1 with 3
* ADS1115_COMP_2_3 -> compares 2 with 3
* ADS1115_COMP_0_GND -> compares 0 with GND
* ADS1115_COMP_1_GND -> compares 1 with GND
* ADS1115_COMP_2_GND -> compares 2 with GND
* ADS1115_COMP_3_GND -> compares 3 with GND
*/
//adc.setCompareChannels(ADS1115_COMP_0_GND); //uncomment if you want to change the default
/* Set number of conversions after which the alert pin will assert
* - or you can disable the alert
*
* ADS1115_ASSERT_AFTER_1 -> after 1 conversion
* ADS1115_ASSERT_AFTER_2 -> after 2 conversions
* ADS1115_ASSERT_AFTER_4 -> after 4 conversions
* ADS1115_DISABLE_ALERT -> disable comparator / alert pin (default)
*/
//adc.setAlertPinMode(ADS1115_ASSERT_AFTER_1); //uncomment if you want to change the default
/* Set the conversion rate in SPS (samples per second)
* Options should be self-explaining:
*
* ADS1115_8_SPS
* ADS1115_16_SPS
* ADS1115_32_SPS
* ADS1115_64_SPS
* ADS1115_128_SPS (default)
* ADS1115_250_SPS
* ADS1115_475_SPS
* ADS1115_860_SPS
*/
//adc.setConvRate(ADS1115_128_SPS); //uncomment if you want to change the default
/* Set continuous or single shot mode:
*
* ADS1115_CONTINUOUS -> continuous mode
* ADS1115_SINGLE -> single shot mode (default)
*/
//adc.setMeasureMode(ADS1115_CONTINUOUS); //uncomment if you want to change the default
/* Choose maximum limit or maximum and minimum alert limit (window) in volts - alert pin will
* assert when measured values are beyond the maximum limit or outside the window
* Upper limit first: setAlertLimit_V(MODE, maximum, minimum)
* In max limit mode the minimum value is the limit where the alert pin assertion will be
* be cleared (if not latched)
*
* ADS1115_MAX_LIMIT
* ADS1115_WINDOW
*
*/
//adc.setAlertModeAndLimit_V(ADS1115_MAX_LIMIT, 3.0, 1.5); //uncomment if you want to change the default
/* Enable or disable latch. If latch is enabled the alert pin will assert until the
* conversion register is read (getResult functions). If disabled the alert pin assertion
* will be cleared with next value within limits.
*
* ADS1115_LATCH_DISABLED (default)
* ADS1115_LATCH_ENABLED
*/
//adc.setAlertLatch(ADS1115_LATCH_ENABLED); //uncomment if you want to change the default
/* Sets the alert pin polarity if active:
*
* ADS1115_ACT_LOW -> active low (default)
* ADS1115_ACT_HIGH -> active high
*/
//adc.setAlertPol(ADS1115_ACT_LOW); //uncomment if you want to change the default
/* With this function the alert pin will assert, when a conversion is ready.
* In order to deactivate, use the setAlertLimit_V function
*/
//adc.setAlertPinToConversionReady(); //uncomment if you want to change the default
Serial.println("ADS1115 Example Sketch - Single Shot Mode");
Serial.println("Channel / Voltage [V]: ");
Serial.println();
}
void loop() {
float voltage = 0.0;
Serial.print("0: ");
voltage = readChannel(ADS1115_COMP_0_GND);
Serial.print(voltage);
Serial.print(", 1: ");
voltage = readChannel(ADS1115_COMP_1_GND);
Serial.print(voltage);
Serial.print(", 2: ");
voltage = readChannel(ADS1115_COMP_2_GND);
Serial.print(voltage);
Serial.print(", 3: ");
voltage = readChannel(ADS1115_COMP_3_GND);
Serial.println(voltage);
delay(1000);
}
float readChannel(ADS1115_MUX channel) {
float voltage = 0.0;
adc.setCompareChannels(channel);
adc.startSingleMeasurement();
while(adc.isBusy()){}
voltage = adc.getResult_V(); // alternative: getResult_mV for Millivolt
return voltage;
}

View File

@@ -0,0 +1,139 @@
/***************************************************************************
* Example sketch for the ADS1115_WE library
*
* This sketch shows how you can use the conversion ready bit with the isBusy function.
* This does not work in the continuous mode.
*
* Further information can be found on:
* https://wolles-elektronikkiste.de/ads1115 (German)
* https://wolles-elektronikkiste.de/en/ads1115-a-d-converter-with-amplifier (English)
*
***************************************************************************/
#include<ADS1115_WE.h>
#include<Wire.h>
#define I2C_ADDRESS 0x48
/* There are several ways to create your ADS1115_WE object:
* ADS1115_WE adc = ADS1115_WE(); -> uses Wire / I2C Address = 0x48
* ADS1115_WE adc = ADS1115_WE(I2C_ADDRESS); -> uses Wire / I2C_ADDRESS
* ADS1115_WE adc = ADS1115_WE(&Wire); -> you can pass any TwoWire object / I2C Address = 0x48
* ADS1115_WE adc = ADS1115_WE(&Wire, I2C_ADDRESS); -> all together
*/
ADS1115_WE adc = ADS1115_WE(I2C_ADDRESS);
void setup() {
Wire.begin();
Serial.begin(9600);
if(!adc.init()){
Serial.println("ADS1115 not connected!");
}
/* Set the voltage range of the ADC to adjust the gain
* Please note that you must not apply more than VDD + 0.3V to the input pins!
*
* ADS1115_RANGE_6144 -> +/- 6144 mV
* ADS1115_RANGE_4096 -> +/- 4096 mV
* ADS1115_RANGE_2048 -> +/- 2048 mV (default)
* ADS1115_RANGE_1024 -> +/- 1024 mV
* ADS1115_RANGE_0512 -> +/- 512 mV
* ADS1115_RANGE_0256 -> +/- 256 mV
*/
adc.setVoltageRange_mV(ADS1115_RANGE_6144); //comment line/change parameter to change range
/* Set the inputs to be compared
*
* ADS1115_COMP_0_1 -> compares 0 with 1 (default)
* ADS1115_COMP_0_3 -> compares 0 with 3
* ADS1115_COMP_1_3 -> compares 1 with 3
* ADS1115_COMP_2_3 -> compares 2 with 3
* ADS1115_COMP_0_GND -> compares 0 with GND
* ADS1115_COMP_1_GND -> compares 1 with GND
* ADS1115_COMP_2_GND -> compares 2 with GND
* ADS1115_COMP_3_GND -> compares 3 with GND
*/
adc.setCompareChannels(ADS1115_COMP_0_GND); //comment line/change parameter to change channels
/* Set number of conversions after which the alert pin will assert
* - or you can disable the alert
*
* ADS1115_ASSERT_AFTER_1 -> after 1 conversion
* ADS1115_ASSERT_AFTER_2 -> after 2 conversions
* ADS1115_ASSERT_AFTER_3 -> after 3 conversions
* ADS1115_DISABLE_ALERT -> disable comparator / alert pin (default)
*/
//adc.setAlertPinMode(ADS1115_ASSERT_AFTER_1); //uncomment if you want to change the default
/* Set the conversion rate in SPS (samples per second)
* Options should be self-explaining:
*
* ADS1115_8_SPS
* ADS1115_16_SPS
* ADS1115_32_SPS
* ADS1115_64_SPS
* ADS1115_128_SPS (default)
* ADS1115_250_SPS
* ADS1115_475_SPS
* ADS1115_860_SPS
*/
adc.setConvRate(ADS1115_8_SPS); //comment line/change parameter to change SPS
/* Set continuous or single shot mode:
*
* ADS1115_CONTINUOUS -> continuous mode
* ADS1115_SINGLE -> single shot mode (default)
*
* Continuous mode does not work with conversion ready (isBusy), but it works with the
* conversion ready alert pin. Confusing, but that's a property of the ADS1115 and not
* a property of the library.
*/
// adc.setMeasureMode(ADS1115_CONTINUOUS); // continuous mode does not work with conversion ready (isBusy)
/* Choose maximum limit or maximum and minimum alert limit (window) in volts - alert pin will
* assert when measured values are beyond the maximum limit or outside the window
* Upper limit first: setAlertLimit_V(MODE, maximum, minimum)
* In max limit mode the minimum value is the limit where the alert pin assertion will be cleared (if
* not latched)
*
* ADS1115_MAX_LIMIT
* ADS1115_WINDOW
*
*/
//adc.setAlertModeAndLimit_V(ADS1115_MAX_LIMIT, 3.0, 1.5); //uncomment if you want to change the default
/* Enable or disable latch. If latch is enabled the alert pin will assert until the
* conversion register is read (getResult functions). If disabled the alert pin assertion will be
* cleared with next value within limits.
*
* ADS1115_LATCH_DISABLED (default)
* ADS1115_LATCH_ENABLED
*/
//adc.setAlertLatch(ADS1115_LATCH_ENABLED); //uncomment if you want to change the default
/* Sets the alert pin polarity if active:
*
* ADS1115_ACT_LOW -> active low (default)
* ADS1115_ACT_HIGH -> active high
*/
//adc.setAlertPol(ADS1115_ACT_LOW); //uncomment if you want to change the default
/* With this function the alert pin will assert, when a conversion is ready.
* In order to deactivate, use the setAlertLimit_V function
*/
//adc.setAlertPinToConversionReady(); //uncomment if you want to change the default
Serial.println("ADS1115 Example Sketch - Single Shot, Conversion Ready (isBusy) controlled");
Serial.println();
}
void loop() {
float voltage = 0.0;
for(int i=0; i<32; i++){ // counter is 32, conversion rate is 8 SPS --> 4s
adc.startSingleMeasurement();
while(adc.isBusy()){}
}
voltage = adc.getResult_V(); // alternative: getResult_mV for Millivolt
Serial.print("Channel 0 vs GND [V]: ");
Serial.println(voltage);
Serial.println("-------------------------------");
}

View File

@@ -0,0 +1,71 @@
/***************************************************************************
* Example sketch for the ADS1115_WE library
*
* This sketch shows how to use two ADS1115 modules. In order to set the address,
* connect the address pin to:
*
* GND -> 0x48 (or leave unconnected)
* VCC -> 0x49
* SDA -> 0x4A
* SCL -> 0x4B
*
* When you have understood how it works you can easily add two additional ADS1115.
* Of course there is potential to shorten the code, e.g. by setting up the ADCs
* as array.
*
* If you need up to eight ADS1115 modules you can use an ESP32 with its two I2C
* interfaces:
* https://wolles-elektronikkiste.de/en/how-to-use-the-i2c-interfaces-of-the-esp32
*
* If you need up to 32 ADS1115 modules you can use a multiplexer like the TSCA9548A:
* https://wolles-elektronikkiste.de/en/tca9548a-i2c-multiplexer
*
* Or you combine both and control up to 64 ADS1115 modules.
*
* Further information about the ADS1115 can be found on:
* https://wolles-elektronikkiste.de/ads1115 (German)
* https://wolles-elektronikkiste.de/en/ads1115-a-d-converter-with-amplifier (English)
*
***************************************************************************/
#include<ADS1115_WE.h>
#include<Wire.h>
#define I2C_ADDRESS_1 0x48
#define I2C_ADDRESS_2 0x49
ADS1115_WE adc_1 = ADS1115_WE(I2C_ADDRESS_1);
ADS1115_WE adc_2 = ADS1115_WE(I2C_ADDRESS_2);
void setup() {
Wire.begin();
Serial.begin(9600);
if(!adc_1.init()){
Serial.print("ADS1115 No 1 not connected!");
}
adc_1.setVoltageRange_mV(ADS1115_RANGE_6144);
adc_1.setMeasureMode(ADS1115_CONTINUOUS);
adc_1.setCompareChannels(ADS1115_COMP_0_GND);
if(!adc_2.init()){
Serial.print("ADS1115 No 2 not connected!");
}
adc_2.setVoltageRange_mV(ADS1115_RANGE_6144);
adc_2.setMeasureMode(ADS1115_CONTINUOUS);
adc_2.setCompareChannels(ADS1115_COMP_0_GND);
}
void loop() {
float voltage = 0.0;
voltage = adc_1.getResult_V();
Serial.println("Voltage [V], ADS1115 No 1: ");
Serial.println(voltage);
voltage = adc_2.getResult_V();
Serial.println("Voltage [V], ADS1115 No 2: ");
Serial.println(voltage);
Serial.println("****************************");
delay(1000);
}

View File

@@ -0,0 +1,66 @@
/***************************************************************************
* Example sketch for the ADS1115_WE library
*
* This sketch checks whether you have an ADS1115 or ADS1015 module. The last
* four bits of raw values obtained from an ADS1015 should be zero. Connect A0
* to a voltage different from GND. The sketch also checks how much time is
* needed to perform ten measurements at lowest data rate, which is 128 SPS for
* the ADS1015 and 8 SPS for the ADS1115.
*
* Further information can be found on:
* https://wolles-elektronikkiste.de/ads1115 (German)
* https://wolles-elektronikkiste.de/en/ads1115-a-d-converter-with-amplifier (English)
*
***************************************************************************/
#include<ADS1115_WE.h>
#include<Wire.h>
#define I2C_ADDRESS 0x48
ADS1115_WE adc = ADS1115_WE(I2C_ADDRESS);
void setup() {
Wire.begin();
Serial.begin(9600);
if(!adc.init()){
Serial.println("ADS1115 not connected!");
}
adc.setVoltageRange_mV(ADS1115_RANGE_6144);
adc.setCompareChannels(ADS1115_COMP_0_GND);
Serial.println("ADS1115/ADS1015 Example Sketch - Who am I");
Serial.println("Performing 10 single ended conversions A0 vs. GND:");
uint16_t checkSum = 0;
for(int i=0; i<10; i++){
adc.startSingleMeasurement();
while(adc.isBusy()){}
int16_t raw = adc.getRawResult();
Serial.println(raw, BIN);
checkSum += raw & 0xF;
}
Serial.println();
Serial.print("Check Sum (Sum of the last 4 bits): ");
Serial.println(checkSum);
adc.setConvRate(ADS1115_8_SPS); // = ADS1015_128_SPS = 0x0000
unsigned long startingTime = millis();
for(int i=0; i<10; i++){
adc.startSingleMeasurement();
while(adc.isBusy()){}
}
unsigned long duration = millis() - startingTime;
Serial.print("Time needed for 10 conversions at slowest sample rate [ms]: ");
Serial.println(duration);
Serial.println();
if(checkSum && duration > 1000){
Serial.println("I am an ADS1115!");
}
else if (!checkSum && duration < 1000){
Serial.println("I am an ADS1015!");
}
else {
Serial.println("Sorry, don't know who I am!");
}
}
void loop() {}

View File

@@ -0,0 +1,136 @@
#######################################
# Syntax Coloring Map For ADS1115_WE
#######################################
#######################################
# Datatypes (KEYWORD1)
#######################################
ADS1115_WE KEYWORD1
ADS1015_WE KEYWORD1
# ENUM TYPES
ADS1115_COMP_QUE KEYWORD1
ADS1115_LATCH KEYWORD1
ADS1115_ALERT_POL KEYWORD1
ADS1115_COMP_MODE KEYWORD1
ADS1115_CONV_RATE KEYWORD1
ADS1115_MEASURE_MODE KEYWORD1
ADS1115_RANGE KEYWORD1
ADS1115_MUX KEYWORD1
ADS1015_MUX KEYWORD1
ADS1115_STATUS_OR_START KEYWORD1
#######################################
# Methods and Functions (KEYWORD2)
#######################################
reset KEYWORD2
init KEYWORD2
setAlertPinMode KEYWORD2
setAlertLatch KEYWORD2
setAlertPol KEYWORD2
setAlertModeAndLimit_V KEYWORD2
setConvRate KEYWORD2
getConvRate KEYWORD2
setMeasureMode KEYWORD2
setVoltageRange_mV KEYWORD2
setAutoRange KEYWORD2
setCompareChannels KEYWORD2
setCompareChannels_nonblock KEYWORD2
isBusy KEYWORD2
startSingleMeasurement KEYWORD2
getResult_V KEYWORD2
getResult_mV KEYWORD2
getRawResult KEYWORD2
getResultWithRange KEYWORD2
getVoltageRange_mV KEYWORD2
setAlertPinToConversionReady KEYWORD2
clearAlert KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################
ADS1115_CONV_REG LITERAL1
ADS1115_CONFIG_REG LITERAL1
ADS1115_LO_THRESH_REG LITERAL1
ADS1115_HI_THRESH_REG LITERAL1
ADS1115_REG_FACTOR LITERAL1
ADS1115_REG_RESET_VAL LITERAL1
# ENUM VALUES
ADS1115_ASSERT_AFTER_1 LITERAL1
ADS1115_ASSERT_AFTER_2 LITERAL1
ADS1115_ASSERT_AFTER_4 LITERAL1
ADS1115_DISABLE_ALERT LITERAL1
ADS1115_LATCH_DISABLED LITERAL1
ADS1115_LATCH_ENABLED LITERAL1
ADS1115_ACT_LOW LITERAL1
ADS1115_ACT_HIGH LITERAL1
ADS1115_MAX_LIMIT LITERAL1
ADS1115_WINDOW LITERAL1
ADS1115_8_SPS LITERAL1
ADS1115_16_SPS LITERAL1
ADS1115_32_SPS LITERAL1
ADS1115_64_SPS LITERAL1
ADS1115_128_SPS LITERAL1
ADS1115_250_SPS LITERAL1
ADS1115_475_SPS LITERAL1
ADS1115_860_SPS LITERAL1
ADS1115_CONTINUOUS LITERAL1
ADS1115_CONTINOUS LITERAL1
ADS1115_SINGLE LITERAL1
ADS1115_RANGE_6144 LITERAL1
ADS1115_RANGE_4096 LITERAL1
ADS1115_RANGE_2048 LITERAL1
ADS1115_RANGE_1024 LITERAL1
ADS1115_RANGE_0512 LITERAL1
ADS1115_RANGE_0256 LITERAL1
ADS1115_COMP_0_1 LITERAL1
ADS1115_COMP_0_3 LITERAL1
ADS1115_COMP_1_3 LITERAL1
ADS1115_COMP_2_3 LITERAL1
ADS1115_COMP_0_GND LITERAL1
ADS1115_COMP_1_GND LITERAL1
ADS1115_COMP_2_GND LITERAL1
ADS1115_COMP_3_GND LITERAL1
ADS1115_BUSY LITERAL1
ADS1015_START_ISREADY LITERAL1
ADS1015_ASSERT_AFTER_1 LITERAL1
ADS1015_ASSERT_AFTER_2 LITERAL1
ADS1015_ASSERT_AFTER_4 LITERAL1
ADS1015_DISABLE_ALERT LITERAL1
ADS1015_LATCH_DISABLED LITERAL1
ADS1015_LATCH_ENABLED LITERAL1
ADS1015_ACT_LOW LITERAL1
ADS1015_ACT_HIGH LITERAL1
ADS1015_MAX_LIMIT LITERAL1
ADS1015_WINDOW LITERAL1
ADS1015_8_SPS LITERAL1
ADS1015_16_SPS LITERAL1
ADS1015_32_SPS LITERAL1
ADS1015_64_SPS LITERAL1
ADS1015_128_SPS LITERAL1
ADS1015_250_SPS LITERAL1
ADS1015_475_SPS LITERAL1
ADS1015_860_SPS LITERAL1
ADS1015_CONTINUOUS LITERAL1
ADS1015_CONTINOUS LITERAL1
ADS1015_SINGLE LITERAL1
ADS1015_RANGE_6144 LITERAL1
ADS1015_RANGE_4096 LITERAL1
ADS1015_RANGE_2048 LITERAL1
ADS1015_RANGE_1024 LITERAL1
ADS1015_RANGE_0512 LITERAL1
ADS1015_RANGE_0256 LITERAL1
ADS1015_COMP_0_1 LITERAL1
ADS1015_COMP_0_3 LITERAL1
ADS1015_COMP_1_3 LITERAL1
ADS1015_COMP_2_3 LITERAL1
ADS1015_COMP_0_GND LITERAL1
ADS1015_COMP_1_GND LITERAL1
ADS1015_COMP_2_GND LITERAL1
ADS1015_COMP_3_GND LITERAL1
ADS1015_BUSY LITERAL1
ADS1015_START_ISREADY LITERAL1

View File

@@ -0,0 +1,10 @@
name=ADS1115_WE
version=1.5.0
author=Wolfgang Ewald <wolfgang.ewald@wolles-elektronikkiste.de>
maintainer=Wolfgang Ewald <wolfgang.ewald@wolles-elektronikkiste.de>
sentence=A library for the ADS1115 and the ADS1015 ADC
paragraph=An Arduino library for the 16-bit, 4-channel ADS1115 and the 12-Bit, 4-channel ADS1015 ADC, convenient to use. All features of the ADS1115 are implemented, including alert functions.
category=Signal Input/Output
url=https://github.com/wollewald/ADS1115_WE
architectures=*
includes=ADS1115_WE.h

View File

@@ -0,0 +1,34 @@
/******************************************************************************
*
* This is a library for the ADS1115 and ADS1015 A/D Converter
*
* You'll find several example sketches which should enable you to use the library.
*
* You are free to use it, change it or build on it. In case you like it, it would
* be cool if you give it a star.
*
* If you find bugs, please inform me!
*
* Written by Wolfgang (Wolle) Ewald
* https://wolles-elektronikkiste.de/en/ads1115-a-d-converter-with-amplifier (English)
* https://wolles-elektronikkiste.de/ads1115 (German)
*
*
******************************************************************************/
#ifndef ADS1015_WE_H
#define ADS1015_WE_H
#include <ADS1115_WE.h>
#if ARDUINO < 100
#include <WProgram.h>
#else
#include <Arduino.h>
#endif
class ADS1015_WE : public ADS1115_WE {
public:
using ADS1115_WE::ADS1115_WE;
};
#endif

View File

@@ -0,0 +1,405 @@
/*****************************************
* This is a library for the ADS1115 and ADS1015 A/D Converter
*
* You'll find an example which should enable you to use the library.
*
* You are free to use it, change it or build on it. In case you like
* it, it would be cool if you give it a star.
*
* If you find bugs, please inform me!
*
* Written by Wolfgang (Wolle) Ewald
* https://wolles-elektronikkiste.de/en/ads1115-a-d-converter-with-amplifier (English)
* https://wolles-elektronikkiste.de/ads1115 (German)
*
*******************************************/
#include "ADS1115_WE.h"
void ADS1115_WE::reset(){
#ifndef USE_TINY_WIRE_M_
_wire->beginTransmission(0);
_wire->write(0x06);
_wire->endTransmission();
#else
TinyWireM.beginTransmission(0);
TinyWireM.send(0x06);
TinyWireM.endTransmission();
#endif
}
bool ADS1115_WE::init(bool ads1015){
useADS1015 = ads1015;
#ifndef USE_TINY_WIRE_M_
_wire->beginTransmission(i2cAddress);
uint8_t success = _wire->endTransmission();
#else
TinyWireM.beginTransmission(i2cAddress);
uint8_t success = TinyWireM.endTransmission();
#endif
if(success){
return 0;
}
writeRegister(ADS1115_CONFIG_REG, ADS1115_REG_RESET_VAL);
setVoltageRange_mV(ADS1115_RANGE_2048);
writeRegister(ADS1115_LO_THRESH_REG, 0x8000);
writeRegister(ADS1115_HI_THRESH_REG, 0x7FFF);
deviceMeasureMode = ADS1115_SINGLE;
autoRangeMode = false;
return 1;
}
void ADS1115_WE::setAlertPinMode(ADS1115_COMP_QUE mode){
uint16_t currentConfReg = readRegister(ADS1115_CONFIG_REG);
currentConfReg &= ~(0x8003);
currentConfReg |= mode;
writeRegister(ADS1115_CONFIG_REG, currentConfReg);
}
void ADS1115_WE::setAlertLatch(ADS1115_LATCH latch){
uint16_t currentConfReg = readRegister(ADS1115_CONFIG_REG);
currentConfReg &= ~(0x8004);
currentConfReg |= latch;
writeRegister(ADS1115_CONFIG_REG, currentConfReg);
}
void ADS1115_WE::setAlertPol(ADS1115_ALERT_POL polarity){
uint16_t currentConfReg = readRegister(ADS1115_CONFIG_REG);
currentConfReg &= ~(0x8008);
currentConfReg |= polarity;
writeRegister(ADS1115_CONFIG_REG, currentConfReg);
}
void ADS1115_WE::setAlertModeAndLimit_V(ADS1115_COMP_MODE mode, float hiThres, float loThres){
uint16_t currentConfReg = readRegister(ADS1115_CONFIG_REG);
currentConfReg &= ~(0x8010);
currentConfReg |= mode;
writeRegister(ADS1115_CONFIG_REG, currentConfReg);
int16_t alertLimit = calcLimit(hiThres);
writeRegister(ADS1115_HI_THRESH_REG, alertLimit);
alertLimit = calcLimit(loThres);
writeRegister(ADS1115_LO_THRESH_REG, alertLimit);
}
void ADS1115_WE::setConvRate(ADS1115_CONV_RATE rate){
uint16_t currentConfReg = readRegister(ADS1115_CONFIG_REG);
currentConfReg &= ~(0x80E0);
currentConfReg |= rate;
writeRegister(ADS1115_CONFIG_REG, currentConfReg);
}
convRate ADS1115_WE::getConvRate(){
uint16_t currentConfReg = readRegister(ADS1115_CONFIG_REG);
return (convRate)(currentConfReg & 0xE0);
}
void ADS1115_WE::setMeasureMode(ADS1115_MEASURE_MODE mode){
uint16_t currentConfReg = readRegister(ADS1115_CONFIG_REG);
deviceMeasureMode = mode;
currentConfReg &= ~(0x8100);
currentConfReg |= mode;
writeRegister(ADS1115_CONFIG_REG, currentConfReg);
}
void ADS1115_WE::setVoltageRange_mV(ADS1115_RANGE range){
uint16_t currentVoltageRange = voltageRange;
uint16_t currentConfReg = readRegister(ADS1115_CONFIG_REG);
uint16_t currentRange = (currentConfReg >> 9) & 7;
uint16_t currentAlertPinMode = currentConfReg & 3;
setMeasureMode(ADS1115_SINGLE);
switch(range){
case ADS1115_RANGE_6144:
voltageRange = 6144;
break;
case ADS1115_RANGE_4096:
voltageRange = 4096;
break;
case ADS1115_RANGE_2048:
voltageRange = 2048;
break;
case ADS1115_RANGE_1024:
voltageRange = 1024;
break;
case ADS1115_RANGE_0512:
voltageRange = 512;
break;
case ADS1115_RANGE_0256:
voltageRange = 256;
break;
}
if ((currentRange != range) && (currentAlertPinMode != ADS1115_DISABLE_ALERT)){
int16_t alertLimit = readRegister(ADS1115_HI_THRESH_REG);
alertLimit = alertLimit * (currentVoltageRange * 1.0 / voltageRange);
writeRegister(ADS1115_HI_THRESH_REG, alertLimit);
alertLimit = readRegister(ADS1115_LO_THRESH_REG);
alertLimit = alertLimit * (currentVoltageRange * 1.0 / voltageRange);
writeRegister(ADS1115_LO_THRESH_REG, alertLimit);
}
currentConfReg &= ~(0x8E00);
currentConfReg |= range;
writeRegister(ADS1115_CONFIG_REG, currentConfReg);
convRate rate = getConvRate();
delayAccToRate(rate);
}
void ADS1115_WE::setAutoRange(){
uint16_t currentConfReg = readRegister(ADS1115_CONFIG_REG);
setVoltageRange_mV(ADS1115_RANGE_6144);
if(deviceMeasureMode == ADS1115_SINGLE){
setMeasureMode(ADS1115_CONTINUOUS);
convRate rate = getConvRate();
delayAccToRate(rate);
}
int16_t rawResult = abs(readRegister(ADS1115_CONV_REG));
int16_t rawResultCopy = rawResult;
if(rawResultCopy == -32768){
rawResultCopy++;
}
rawResultCopy = abs(rawResultCopy);
range optRange = ADS1115_RANGE_6144;
if(rawResultCopy < 1093){
optRange = ADS1115_RANGE_0256;
}
else if(rawResultCopy < 2185){
optRange = ADS1115_RANGE_0512;
}
else if(rawResultCopy < 4370){
optRange = ADS1115_RANGE_1024;
}
else if(rawResultCopy < 8738){
optRange = ADS1115_RANGE_2048;
}
else if(rawResultCopy < 17476){
optRange = ADS1115_RANGE_4096;
}
writeRegister(ADS1115_CONFIG_REG, currentConfReg);
setVoltageRange_mV(optRange);
}
void ADS1115_WE::setPermanentAutoRangeMode(bool autoMode){
if(autoMode){
autoRangeMode = true;
}
else{
autoRangeMode = false;
}
}
void ADS1115_WE::delayAccToRate(convRate cr){
if(!useADS1015){
switch(cr){
case ADS1115_8_SPS:
delay(130);
break;
case ADS1115_16_SPS:
delay(65);
break;
case ADS1115_32_SPS:
delay(32);
break;
case ADS1115_64_SPS:
delay(16);
break;
case ADS1115_128_SPS:
delay(8);
break;
case ADS1115_250_SPS:
delay(4);
break;
case ADS1115_475_SPS:
delay(3);
break;
case ADS1115_860_SPS:
delay(2);
break;
}
}
else{
switch(cr){
case ADS1015_128_SPS:
delay(8);
break;
case ADS1015_250_SPS:
delay(5);
break;
case ADS1015_490_SPS:
delay(2);
break;
case ADS1015_920_SPS:
delay(1);
break;
case ADS1015_1600_SPS:
delayMicroseconds(675);
break;
case ADS1015_2400_SPS:
delayMicroseconds(450);
break;
case ADS1015_3300_SPS:
delayMicroseconds(330);
break;
case ADS1015_3300_SPS_2:
delayMicroseconds(330);
break;
}
}
}
void ADS1115_WE::setCompareChannels(ADS1115_MUX mux){
uint16_t currentConfReg = readRegister(ADS1115_CONFIG_REG);
currentConfReg &= ~(0xF000);
currentConfReg |= (mux);
writeRegister(ADS1115_CONFIG_REG, currentConfReg);
if(!(currentConfReg & 0x0100)){ // => if not single shot mode
convRate rate = getConvRate();
delayAccToRate(rate);
delayAccToRate(rate);
}
}
void ADS1115_WE::setCompareChannels_nonblock(ADS1115_MUX mux){
uint16_t currentConfReg = readRegister(ADS1115_CONFIG_REG);
currentConfReg &= ~(0xF000);
currentConfReg |= (mux);
writeRegister(ADS1115_CONFIG_REG, currentConfReg);
}
void ADS1115_WE::setSingleChannel(size_t channel) {
if (channel >= 4)
return;
setCompareChannels((ADS1115_MUX)(ADS1115_COMP_0_GND + ADS1115_COMP_INC*channel));
}
bool ADS1115_WE::isBusy(){
uint16_t currentConfReg = readRegister(ADS1115_CONFIG_REG);
return (!(currentConfReg>>15) & 1);
}
void ADS1115_WE::startSingleMeasurement(){
uint16_t currentConfReg = readRegister(ADS1115_CONFIG_REG);
currentConfReg |= (1 << 15);
writeRegister(ADS1115_CONFIG_REG, currentConfReg);
}
float ADS1115_WE::getResult_V(){
float result = getResult_mV();
result /= 1000;
return result;
}
float ADS1115_WE::getResult_mV(){
int16_t rawResult = getRawResult();
float result = (rawResult * 1.0 / ADS1115_REG_FACTOR) * voltageRange;
return result;
}
int16_t ADS1115_WE::getRawResult(){
int16_t rawResult = readRegister(ADS1115_CONV_REG);
if(autoRangeMode){
int16_t rawResultCopy = rawResult;
if(rawResultCopy == -32768){
rawResultCopy++;
}
rawResultCopy = abs(rawResultCopy);
if((rawResultCopy > 26214) && (voltageRange != 6144)){ // 80%
setAutoRange();
rawResult = readRegister(ADS1115_CONV_REG);
}
else if((rawResultCopy < 9800) && (voltageRange != 256)){ //30%
setAutoRange();
rawResult = readRegister(ADS1115_CONV_REG);
}
}
return rawResult;
}
int16_t ADS1115_WE::getResultWithRange(int16_t min, int16_t max){
int16_t rawResult = getRawResult();
int16_t result = map(rawResult, -32768, 32767, min, max);
return result;
}
int16_t ADS1115_WE::getResultWithRange(int16_t min, int16_t max, int16_t maxMillivolt){
int16_t result = getResultWithRange(min, max);
result = static_cast<int16_t>((1.0 * result * voltageRange / maxMillivolt) + 0.5);
return result;
}
uint16_t ADS1115_WE::getVoltageRange_mV(){
return voltageRange;
}
void ADS1115_WE::setAlertPinToConversionReady(){
writeRegister(ADS1115_LO_THRESH_REG, (0<<15));
writeRegister(ADS1115_HI_THRESH_REG, (1<<15));
}
void ADS1115_WE::clearAlert(){
readRegister(ADS1115_CONV_REG);
}
/************************************************
private functions
*************************************************/
int16_t ADS1115_WE::calcLimit(float rawLimit){
int16_t limit = static_cast<int16_t>((rawLimit * ADS1115_REG_FACTOR / voltageRange)*1000);
return limit;
}
uint8_t ADS1115_WE::writeRegister(uint8_t reg, uint16_t val){
uint8_t lVal = val & 255;
uint8_t hVal = val >> 8;
#ifndef USE_TINY_WIRE_M_
_wire->beginTransmission(i2cAddress);
_wire->write(reg);
_wire->write(hVal);
_wire->write(lVal);
return _wire->endTransmission();
#else
TinyWireM.beginTransmission(i2cAddress);
TinyWireM.send(reg);
TinyWireM.send(hVal);
TinyWireM.send(lVal);
return TinyWireM.endTransmission();
#endif
}
uint16_t ADS1115_WE::readRegister(uint8_t reg){
uint8_t MSByte = 0, LSByte = 0;
uint16_t regValue = 0;
#ifndef USE_TINY_WIRE_M_
_wire->beginTransmission(i2cAddress);
_wire->write(reg);
_wire->endTransmission(false);
_wire->requestFrom(i2cAddress,static_cast<uint8_t>(2));
if(_wire->available()){
MSByte = _wire->read();
LSByte = _wire->read();
}
#else
TinyWireM.beginTransmission(i2cAddress);
TinyWireM.send(reg);
TinyWireM.endTransmission();
TinyWireM.requestFrom(i2cAddress,static_cast<uint8_t>(2));
MSByte = TinyWireM.receive();
LSByte = TinyWireM.receive();
#endif
regValue = (MSByte<<8) + LSByte;
return regValue;
}

View File

@@ -0,0 +1,334 @@
/******************************************************************************
*
* This is a library for the ADS1115 and ADS1015 A/D Converter
*
* You'll find several example sketches which should enable you to use the library.
*
* You are free to use it, change it or build on it. In case you like it, it would
* be cool if you give it a star.
*
* If you find bugs, please inform me!
*
* Written by Wolfgang (Wolle) Ewald
* https://wolles-elektronikkiste.de/en/ads1115-a-d-converter-with-amplifier (English)
* https://wolles-elektronikkiste.de/ads1115 (German)
*
*
******************************************************************************/
#ifndef ADS1115_WE_H_
#define ADS1115_WE_H_
#if (ARDUINO >= 100)
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include "ADS1115_config.h"
#ifdef USE_TINY_WIRE_M_
#include <TinyWireM.h>
#endif
#ifndef USE_TINY_WIRE_M_
#include <Wire.h>
#endif
typedef enum ADS1115_COMP_QUE {
ADS1115_ASSERT_AFTER_1 = 0x0000,
ADS1115_ASSERT_AFTER_2 = 0x0001,
ADS1115_ASSERT_AFTER_4 = 0x0002,
ADS1115_DISABLE_ALERT = 0x0003,
ADS1015_ASSERT_AFTER_1 = ADS1115_ASSERT_AFTER_1,
ADS1015_ASSERT_AFTER_2 = ADS1115_ASSERT_AFTER_2,
ADS1015_ASSERT_AFTER_4 = ADS1115_ASSERT_AFTER_4,
ADS1015_DISABLE_ALERT = ADS1115_DISABLE_ALERT
} compQue;
typedef enum ADS1115_LATCH {
ADS1115_LATCH_DISABLED = 0x0000,
ADS1115_LATCH_ENABLED = 0x0004,
ADS1015_LATCH_DISABLED = ADS1115_LATCH_DISABLED,
ADS1015_LATCH_ENABLED = ADS1115_LATCH_ENABLED
} latch;
typedef enum ADS1115_ALERT_POL {
ADS1115_ACT_LOW = 0x0000,
ADS1115_ACT_HIGH = 0x0008,
ADS1015_ACT_LOW = ADS1115_ACT_LOW,
ADS1015_ACT_HIGH = ADS1115_ACT_HIGH
} alertPol;
typedef enum ADS1115_COMP_MODE{
ADS1115_MAX_LIMIT = 0x0000,
ADS1115_WINDOW = 0x0010,
ADS1015_MAX_LIMIT = ADS1115_MAX_LIMIT,
ADS1015_WINDOW = ADS1115_WINDOW
} compMode;
typedef enum ADS1115_CONV_RATE{
ADS1115_8_SPS = 0x0000,
ADS1115_16_SPS = 0x0020,
ADS1115_32_SPS = 0x0040,
ADS1115_64_SPS = 0x0060,
ADS1115_128_SPS = 0x0080,
ADS1115_250_SPS = 0x00A0,
ADS1115_475_SPS = 0x00C0,
ADS1115_860_SPS = 0x00E0,
ADS1015_128_SPS = ADS1115_8_SPS,
ADS1015_250_SPS = ADS1115_16_SPS,
ADS1015_490_SPS = ADS1115_32_SPS,
ADS1015_920_SPS = ADS1115_64_SPS,
ADS1015_1600_SPS = ADS1115_128_SPS,
ADS1015_2400_SPS = ADS1115_250_SPS,
ADS1015_3300_SPS = ADS1115_475_SPS,
ADS1015_3300_SPS_2 = ADS1115_860_SPS
} convRate;
typedef enum ADS1115_MEASURE_MODE{
ADS1115_CONTINUOUS = 0x0000,
ADS1115_SINGLE = 0x0100,
ADS1015_CONTINUOUS = ADS1115_CONTINUOUS,
ADS1015_SINGLE = ADS1115_SINGLE
} measureMode;
typedef enum ADS1115_RANGE{
ADS1115_RANGE_6144 = 0x0000,
ADS1115_RANGE_4096 = 0x0200,
ADS1115_RANGE_2048 = 0x0400,
ADS1115_RANGE_1024 = 0x0600,
ADS1115_RANGE_0512 = 0x0800,
ADS1115_RANGE_0256 = 0x0A00,
ADS1015_RANGE_6144 = ADS1115_RANGE_6144,
ADS1015_RANGE_4096 = ADS1115_RANGE_4096,
ADS1015_RANGE_2048 = ADS1115_RANGE_2048,
ADS1015_RANGE_1024 = ADS1115_RANGE_1024,
ADS1015_RANGE_0512 = ADS1115_RANGE_0512,
ADS1015_RANGE_0256 = ADS1115_RANGE_0256
} range;
typedef enum ADS1115_MUX{
ADS1115_COMP_0_1 = 0x0000,
ADS1115_COMP_0_3 = 0x1000,
ADS1115_COMP_1_3 = 0x2000,
ADS1115_COMP_2_3 = 0x3000,
ADS1115_COMP_0_GND = 0x4000,
ADS1115_COMP_1_GND = 0x5000,
ADS1115_COMP_2_GND = 0x6000,
ADS1115_COMP_3_GND = 0x7000,
ADS1015_COMP_0_1 = ADS1115_COMP_0_1,
ADS1015_COMP_0_3 = ADS1115_COMP_0_3,
ADS1015_COMP_1_3 = ADS1115_COMP_1_3,
ADS1015_COMP_2_3 = ADS1115_COMP_2_3,
ADS1015_COMP_0_GND = ADS1115_COMP_0_GND,
ADS1015_COMP_1_GND = ADS1115_COMP_1_GND,
ADS1015_COMP_2_GND = ADS1115_COMP_2_GND,
ADS1015_COMP_3_GND = ADS1115_COMP_3_GND
} mux;
#define ADS1115_COMP_INC 0x1000 // increment to next channel
#define ADS1015_MUX ADS1115_MUX
typedef enum ADS1115_STATUS_OR_START{
ADS1115_BUSY = 0x0000,
ADS1115_START_ISREADY = 0x8000,
ADS1015_BUSY = ADS1115_BUSY,
ADS1015_START_ISREADY = ADS1115_START_ISREADY
} statusOrStart;
class ADS1115_WE
{
public:
/* registers */
static constexpr uint8_t ADS1115_CONV_REG {0x00}; // Conversion Register
static constexpr uint8_t ADS1115_CONFIG_REG {0x01}; // Configuration Register
static constexpr uint8_t ADS1115_LO_THRESH_REG {0x02}; // Low Threshold Register
static constexpr uint8_t ADS1115_HI_THRESH_REG {0x03}; // High Threshold Register
/* other */
static constexpr uint16_t ADS1115_REG_FACTOR {32768};
static constexpr uint16_t ADS1115_REG_RESET_VAL {0x8583};
#ifndef USE_TINY_WIRE_M_
ADS1115_WE(const uint8_t addr = 0x48) : _wire{&Wire}, i2cAddress{addr} {}
ADS1115_WE(TwoWire *w, const uint8_t addr = 0x48) : _wire{w}, i2cAddress{addr} {}
#else
ADS1115_WE(const uint8_t addr = 0x48) : i2cAddress{addr} {}
#endif
void reset();
bool init(bool ads1015 = false);
/* Set number of conversions after which the alert pin will be active
* - or you can disable the alert
*
* ADS1115_ASSERT_AFTER_1 -> after 1 conversion
* ADS1115_ASSERT_AFTER_2 -> after 2 conversions
* ADS1115_ASSERT_AFTER_4 -> after 4 conversions
* ADS1115_DISABLE_ALERT -> disable comparator // alert pin (default)
*/
void setAlertPinMode(ADS1115_COMP_QUE mode);
/* Enable or disable latch. If latch is enabled the alarm pin will be active until the
* conversion register is read (getResult functions). If disabled the alarm pin will be
* deactivated with next value within limits.
*
* ADS1115_LATCH_DISABLED (default)
* ADS1115_LATCH_ENABLED
*/
void setAlertLatch(ADS1115_LATCH latch);
/* Sets the alert pin polarity if active:
*
* Enable or disable latch. If latch is enabled the alarm pin will be active until the
* conversion register is read (getResult functions). If disabled the alarm pin will be
* deactivated with next value within limits.
*
* ADS1115_ACT_LOW -> active low (default)
* ADS1115_ACT_HIGH -> active high
*/
void setAlertPol(ADS1115_ALERT_POL polarity);
/* Choose maximum limit or maximum and minimum alert limit (window)in Volt - alert pin will
* be active when measured values are beyond the maximum limit or outside the window
* Upper limit first: setAlertLimit_V(MODE, maximum, minimum)
* In max limit mode the minimum value is the limit where the alert pin will be deactivated (if
* not latched)
*
* ADS1115_MAX_LIMIT
* ADS1115_WINDOW
*/
void setAlertModeAndLimit_V(ADS1115_COMP_MODE mode, float hithres, float lothres);
/* Set the conversion rate in SPS (samples per second)
* Options should be self-explaining:
*
* ADS1115_8_SPS
* ADS1115_16_SPS
* ADS1115_32_SPS
* ADS1115_64_SPS
* ADS1115_128_SPS (default)
* ADS1115_250_SPS
* ADS1115_475_SPS
* ADS1115_860_SPS
*/
void setConvRate(ADS1115_CONV_RATE rate);
/* returns the conversion rate */
convRate getConvRate();
/* Set continuous or single shot mode:
*
* ADS1115_CONTINUOUS -> continuous mode
* ADS1115_SINGLE -> single shot mode (default)
*/
void setMeasureMode(ADS1115_MEASURE_MODE mode);
/* Set the voltage range of the ADC to adjust the gain:
* Please note that you must not apply more than VDD + 0.3V to the input pins!
*
* ADS1115_RANGE_6144 -> +/- 6144 mV
* ADS1115_RANGE_4096 -> +/- 4096 mV
* ADS1115_RANGE_2048 -> +/- 2048 mV (default)
* ADS1115_RANGE_1024 -> +/- 1024 mV
* ADS1115_RANGE_0512 -> +/- 512 mV
* ADS1115_RANGE_0256 -> +/- 256 mV
*/
void setVoltageRange_mV(ADS1115_RANGE range);
/* Set the voltage range automatically
* 1) changes into maximum range and continuous mode
* 2) measures the voltage
* 3) chooses the smallest range in which the measured voltage is <80%
* of the range's maximum
* 4) switches back to single shot mode if it was in this mode before
*
* Please be aware that the procedure takes the the time needed for several conversions.
* You should ony use it in case you expect stable or slowly changing voltages.
*/
void setAutoRange();
/* Set the automatic voltage range permanantly, but the range will only be changed if the
* measured value is outside 30 - 80% of the maximum value of the current range.
* Therefore this method is faster than setAutoRange().
*/
void setPermanentAutoRangeMode(bool autoMode);
/* Set the inputs to be compared
*
* ADS1115_COMP_0_1 -> compares 0 with 1 (default)
* ADS1115_COMP_0_3 -> compares 0 with 3
* ADS1115_COMP_1_3 -> compares 1 with 3
* ADS1115_COMP_2_3 -> compares 2 with 3
* ADS1115_COMP_0_GND -> compares 0 with GND
* ADS1115_COMP_1_GND -> compares 1 with GND
* ADS1115_COMP_2_GND -> compares 2 with GND
* ADS1115_COMP_3_GND -> compares 3 with GND
*/
void setCompareChannels(ADS1115_MUX mux);
/* Set to channel (0-3) in single ended mode in a non blocking way without delay
*/
void setCompareChannels_nonblock(ADS1115_MUX mux);
/* Set to channel (0-3) in single ended mode
*/
void setSingleChannel(size_t channel);
bool isBusy();
void startSingleMeasurement();
float getResult_V();
float getResult_mV();
/* Get the raw result from the conversion register:
* The conversion register contains the conversion result of the amplified (!)
* voltage. This means the value depends on the voltage as well as on the
* voltage range. E.g. if the voltage range is 6144 mV (ADS1115_RANGE_6144),
* +32767 is 6144 mV; if the range is 4096 mV, +32767 is 4096 mV, and so on.
*/
int16_t getRawResult();
/* Scaling of the result to a different range:
* The results in the conversion register are in a range of -32767 to +32767
* You might want to receive the result in a different scale, e.g. -1023 to 1023.
* For -1023 to 1023, and if you have chosen e.g. ADS1115_RANGE_4096, 0 Volt would
* give 0 as result and 4096 mV would give 1023. -4096 mV would give -1023.
*/
int16_t getResultWithRange(int16_t min, int16_t max);
/* Scaling of the result to a different range plus scaling to a voltage range:
* You can use this variant if you also want to scale to a voltage range. E.g. in
* in order to get results equivalent to an Arduino UNO (10 bit, 5000 mV range), you
* would choose getResultWithRange(-1023, 1023, 5000). A difference to the Arduino
* UNO is that you can measure negative voltages.
* You have to ensure that the voltage range you scale to is smaller than the
* measuring voltage range.
*/
int16_t getResultWithRange(int16_t min, int16_t max, int16_t maxVoltage);
/* This function returns the voltage range ADS1115_RANGE_XXXX in Millivolt */
uint16_t getVoltageRange_mV();
/* With this function the alert pin will be active, when a conversion is ready.
* In order to deactivate, use the setAlertLimit_V function
*/
void setAlertPinToConversionReady();
void clearAlert();
protected:
#ifndef USE_TINY_WIRE_M_
TwoWire *_wire;
#endif
bool useADS1015;
uint16_t voltageRange;
ADS1115_MEASURE_MODE deviceMeasureMode;
uint8_t i2cAddress;
bool autoRangeMode;
void delayAccToRate(convRate cr);
int16_t calcLimit(float rawLimit);
uint8_t writeRegister(uint8_t reg, uint16_t val);
uint16_t readRegister(uint8_t reg);
};
#endif

View File

@@ -0,0 +1,5 @@
#ifndef ADS1115_CONFIG_H_
#define ADS1115_CONFIG_H_
/* Uncomment the following line to use TinyWireM instead of Wire */
//#define USE_TINY_WIRE_M_
#endif