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

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() {}