fork from github
This commit is contained in:
119
examples/ADS_async_16_channel/ADS_async_16_channel.ino
Normal file
119
examples/ADS_async_16_channel/ADS_async_16_channel.ino
Normal file
@@ -0,0 +1,119 @@
|
||||
//
|
||||
// FILE: ADS_async_16_channel.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo reading four ADS1115 modules in parallel
|
||||
// DATE: 2021-07-06
|
||||
// URL: https://github.com/RobTillaart/ADS1X15
|
||||
|
||||
|
||||
// Note all IO with the sensors are guarded by an isConnected()
|
||||
// this is max robust, in non critical application one may either
|
||||
// cache the value or only verify it in setup (least robust).
|
||||
// Less robust may cause the application to hang - watchdog reset ?
|
||||
|
||||
|
||||
#include "ADS1X15.h"
|
||||
|
||||
|
||||
ADS1115 ADS[4];
|
||||
uint16_t val[16];
|
||||
int idx = 0;
|
||||
|
||||
uint32_t last = 0, now = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("ADS1X15_LIB_VERSION: ");
|
||||
Serial.println(ADS1X15_LIB_VERSION);
|
||||
|
||||
for (uint8_t i = 0; i < 4; i++)
|
||||
{
|
||||
uint8_t address = 0x48 + i;
|
||||
ADS[i] = ADS1115(address);
|
||||
|
||||
Serial.print(address, HEX);
|
||||
Serial.print(" ");
|
||||
Serial.println(ADS[i].begin() ? "connected" : "not connected");
|
||||
|
||||
ADS[i].setDataRate(4); // 7 is fastest, but more noise
|
||||
}
|
||||
ADS_request_all();
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Serial.println(__FUNCTION__);
|
||||
// wait until all is read...
|
||||
while (ADS_read_all());
|
||||
|
||||
// we have all values
|
||||
ADS_print_all();
|
||||
|
||||
delay(1000); // wait a second.
|
||||
ADS_request_all();
|
||||
}
|
||||
|
||||
|
||||
void ADS_request_all()
|
||||
{
|
||||
// Serial.println(__FUNCTION__);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (ADS[i].isConnected()) ADS[i].requestADC(idx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ADS_read_all()
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (ADS[i].isConnected() && ADS[i].isBusy()) return true;
|
||||
}
|
||||
// Serial.print("IDX:\t");
|
||||
// Serial.println(idx);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (ADS[i].isConnected())
|
||||
{
|
||||
val[i * 4 + idx] = ADS[i].getValue();
|
||||
}
|
||||
}
|
||||
idx++;
|
||||
if (idx < 4)
|
||||
{
|
||||
ADS_request_all();
|
||||
return true;
|
||||
}
|
||||
idx = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void ADS_print_all()
|
||||
{
|
||||
// Serial.println(__FUNCTION__);
|
||||
// TIMESTAMP
|
||||
now = millis();
|
||||
Serial.print(now - last);
|
||||
last = now;
|
||||
Serial.println();
|
||||
|
||||
// PRINT ALL VALUES
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
Serial.print(val[j * 4 + i]);
|
||||
Serial.print("\t");
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
||||
136
examples/ADS_async_8_channel/ADS_async_8_channel.ino
Normal file
136
examples/ADS_async_8_channel/ADS_async_8_channel.ino
Normal file
@@ -0,0 +1,136 @@
|
||||
//
|
||||
// FILE: ADS_async_8_channel.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo reading two ADS1115 modules in parallel
|
||||
// DATE: 2021-07-05
|
||||
// URL: https://github.com/RobTillaart/ADS1X15
|
||||
|
||||
|
||||
// Note all IO with the sensors are guarded by an isConnected()
|
||||
// this is max robust, in non critical application one may either
|
||||
// cache the value or only verify it in setup (least robust).
|
||||
// Less robust may cause the application to hang - watchdog reset ?
|
||||
|
||||
|
||||
#include "ADS1X15.h"
|
||||
|
||||
|
||||
ADS1115 ADS0(0x48);
|
||||
ADS1115 ADS1(0x49);
|
||||
//ADS1115 ADS2(0x4A);
|
||||
//ADS1115 ADS3(0x4B);
|
||||
|
||||
int16_t val0[4] = { 0, 0, 0, 0 };
|
||||
int16_t val1[4] = { 0, 0, 0, 0 };
|
||||
//int16_t val2[4] = { 0, 0, 0, 0 };
|
||||
//int16_t val3[4] = { 0, 0, 0, 0 };
|
||||
int idx = 0;
|
||||
|
||||
uint32_t lastTime = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("ADS1X15_LIB_VERSION: ");
|
||||
Serial.println(ADS1X15_LIB_VERSION);
|
||||
|
||||
ADS0.begin();
|
||||
ADS1.begin();
|
||||
// ADS2.begin();
|
||||
// ADS3.begin();
|
||||
|
||||
Serial.println(ADS0.isConnected());
|
||||
Serial.println(ADS1.isConnected());
|
||||
// Serial.println(ADS2.isConnected());
|
||||
// Serial.println(ADS3.isConnected());
|
||||
|
||||
ADS0.setDataRate(4); // 7 is fastest, but more noise
|
||||
ADS1.setDataRate(4);
|
||||
// ADS2.setDataRate(4);
|
||||
// ADS3.setDataRate(4);
|
||||
|
||||
idx = 0;
|
||||
ADS_request_all();
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// wait until all is read...
|
||||
while (ADS_read_all());
|
||||
|
||||
// we have all 8 values
|
||||
ADS_print_all();
|
||||
|
||||
delay(1000); // wait a second.
|
||||
ADS_request_all();
|
||||
}
|
||||
|
||||
|
||||
void ADS_request_all()
|
||||
{
|
||||
if (ADS0.isConnected()) ADS0.requestADC(idx);
|
||||
if (ADS1.isConnected()) ADS1.requestADC(idx);
|
||||
// if (ADS2.isConnected()) ADS2.requestADC(idx);
|
||||
// if (ADS3.isConnected()) ADS3.requestADC(idx);
|
||||
}
|
||||
|
||||
|
||||
bool ADS_read_all()
|
||||
{
|
||||
if (ADS0.isConnected() && ADS0.isBusy()) return true;
|
||||
if (ADS1.isConnected() && ADS1.isBusy()) return true;
|
||||
// if (ADS2.isConnected() && ADS2.isBusy()) return true;
|
||||
// if (ADS3.isConnected() && ADS3.isBusy()) return true;
|
||||
|
||||
if (ADS0.isConnected()) val0[idx] = ADS0.getValue();
|
||||
if (ADS1.isConnected()) val1[idx] = ADS1.getValue();
|
||||
// if (ADS2.isConnected()) val2[idx] = ADS2.getValue();
|
||||
// if (ADS3.isConnected()) val3[idx] = ADS3.getValue();
|
||||
idx++;
|
||||
if (idx < 4)
|
||||
{
|
||||
ADS_request_all();
|
||||
return true;
|
||||
}
|
||||
idx = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void ADS_print_all()
|
||||
{
|
||||
uint32_t now = millis();
|
||||
Serial.println(now - lastTime);
|
||||
lastTime = now;
|
||||
|
||||
// PRINT ALL VALUES OF ADC0
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Serial.print(val0[i]);
|
||||
Serial.print("\t");
|
||||
}
|
||||
// PRINT ALL VALUES OF ADC1
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Serial.print(val1[i]);
|
||||
Serial.print("\t");
|
||||
}
|
||||
Serial.println();
|
||||
// // PRINT ALL VALUES OF ADC2
|
||||
// for (int i = 0; i < 4; i++)
|
||||
// {
|
||||
// Serial.print(val2[i]);
|
||||
// Serial.print("\t");
|
||||
// }
|
||||
// // PRINT ALL VALUES OF ADC3
|
||||
// for (int i = 0; i < 4; i++)
|
||||
// {
|
||||
// Serial.print(val3[i]);
|
||||
// Serial.print("\t");
|
||||
// }
|
||||
// Serial.println();
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
||||
95
examples/ADS_async_differential/ADS_async_differential.ino
Normal file
95
examples/ADS_async_differential/ADS_async_differential.ino
Normal file
@@ -0,0 +1,95 @@
|
||||
//
|
||||
// FILE: ADS_async_differential.ino
|
||||
// AUTHOR: Rob.Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: read multiple differential continuously
|
||||
//
|
||||
|
||||
// test
|
||||
// connect 4 potmeters
|
||||
//
|
||||
// GND ---[ x ]------ 5V
|
||||
// |
|
||||
//
|
||||
// measure at x - connect to AIN0..4.
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
#include "ADS1X15.h"
|
||||
|
||||
// choose you sensor
|
||||
// ADS1013 ADS(0x48);
|
||||
// ADS1014 ADS(0x48);
|
||||
// ADS1015 ADS(0x48);
|
||||
// ADS1113 ADS(0x48);
|
||||
// ADS1114 ADS(0x48);
|
||||
ADS1115 ADS(0x48);
|
||||
|
||||
|
||||
uint8_t pair = 01;
|
||||
int16_t val_01 = 0;
|
||||
int16_t val_23 = 0;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("ADS1X15_LIB_VERSION: ");
|
||||
Serial.println(ADS1X15_LIB_VERSION);
|
||||
|
||||
ADS.begin();
|
||||
ADS.setGain(0); // 6.144 volt
|
||||
ADS.setDataRate(4); // medium
|
||||
|
||||
// single shot mode
|
||||
ADS.setMode(1);
|
||||
// start with first pair
|
||||
pair = 01;
|
||||
// trigger first read
|
||||
ADS.requestADC_Differential_0_1();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (handleConversion() == true)
|
||||
{
|
||||
Serial.print("COMP:\t");
|
||||
Serial.print(val_01);
|
||||
Serial.print("\t");
|
||||
Serial.print(val_23);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
// do other stuff here
|
||||
delay(10);
|
||||
}
|
||||
|
||||
|
||||
// can be changed to hold other differentials reads too.
|
||||
bool handleConversion()
|
||||
{
|
||||
if (ADS.isReady())
|
||||
{
|
||||
if (pair == 01)
|
||||
{
|
||||
val_01 = ADS.getValue();
|
||||
pair = 23;
|
||||
ADS.requestADC_Differential_2_3();
|
||||
return false; // only one done
|
||||
}
|
||||
|
||||
// last of series to check
|
||||
if (pair == 23)
|
||||
{
|
||||
val_23 = ADS.getValue();
|
||||
pair = 01;
|
||||
ADS.requestADC_Differential_0_1();
|
||||
return true; // both are updated
|
||||
}
|
||||
}
|
||||
return false; // default not all read
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
||||
47
examples/ADS_continuous/ADS_continuous.ino
Normal file
47
examples/ADS_continuous/ADS_continuous.ino
Normal file
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// FILE: ADS_continuous.ino
|
||||
// AUTHOR: Rob.Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// PURPOSE: read analog input
|
||||
//
|
||||
|
||||
// test
|
||||
// connect 1 potmeter
|
||||
//
|
||||
// GND ---[ x ]------ 5V
|
||||
// |
|
||||
//
|
||||
// measure at x (connect to AIN0).
|
||||
|
||||
|
||||
#include "ADS1X15.h"
|
||||
|
||||
// choose you sensor
|
||||
// ADS1013 ADS(0x48);
|
||||
// ADS1014 ADS(0x48);
|
||||
// ADS1015 ADS(0x48);
|
||||
// ADS1113 ADS(0x48);
|
||||
// ADS1114 ADS(0x48);
|
||||
ADS1115 ADS(0x48);
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("ADS1X15_LIB_VERSION: ");
|
||||
Serial.println(ADS1X15_LIB_VERSION);
|
||||
|
||||
ADS.begin();
|
||||
ADS.setGain(0); // 6.144 volt
|
||||
ADS.setDataRate(7); // fast
|
||||
ADS.setMode(0); // continuous mode
|
||||
ADS.readADC(0); // first read to trigger
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println(ADS.getValue());
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
||||
@@ -0,0 +1,94 @@
|
||||
//
|
||||
// FILE: ADS_continuous_4_channel.ino
|
||||
// AUTHOR: Rob.Tillaart
|
||||
// VERSION: 0.1.2
|
||||
// PURPOSE: read multiple analog inputs continuously
|
||||
// interrupt driven to catch all conversions.
|
||||
//
|
||||
|
||||
// test
|
||||
// connect multiple potmeters
|
||||
//
|
||||
// GND ---[ x ]------ 5V
|
||||
// |
|
||||
//
|
||||
// measure at x - connect to AIN0..4.
|
||||
//
|
||||
// for the test it is good to have AIN3 connected to 5V and AIN4 to GND
|
||||
// so one can see these as references in the output.
|
||||
//
|
||||
|
||||
#include "ADS1X15.h"
|
||||
|
||||
// choose you sensor
|
||||
// ADS1013 ADS(0x48);
|
||||
// ADS1014 ADS(0x48);
|
||||
// ADS1015 ADS(0x48);
|
||||
// ADS1113 ADS(0x48);
|
||||
// ADS1114 ADS(0x48);
|
||||
ADS1115 ADS(0x48);
|
||||
|
||||
volatile bool RDY = false;
|
||||
uint8_t channel = 0;
|
||||
int16_t val[4] = { 0, 0, 0, 0 };
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("ADS1X15_LIB_VERSION: ");
|
||||
Serial.println(ADS1X15_LIB_VERSION);
|
||||
|
||||
pinMode(2, INPUT_PULLUP);
|
||||
attachInterrupt(digitalPinToInterrupt(2), adsReady, RISING);
|
||||
|
||||
ADS.begin();
|
||||
ADS.setGain(0); // 6.144 volt
|
||||
ADS.setDataRate(7); // slow
|
||||
|
||||
// SET ALERT RDY PIN
|
||||
ADS.setComparatorThresholdHigh(0x8000);
|
||||
ADS.setComparatorThresholdLow(0x0000);
|
||||
ADS.setComparatorQueConvert(0);
|
||||
|
||||
// SET INTERRUPT HANDLER TO CATCH CONVERSION READY
|
||||
pinMode(2, INPUT_PULLUP);
|
||||
attachInterrupt(digitalPinToInterrupt(2), adsReady, RISING);
|
||||
|
||||
ADS.setMode(0); // continuous mode
|
||||
ADS.readADC(channel); // trigger first read
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
handleConversion();
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Serial.print(val[i]);
|
||||
Serial.print('\t');
|
||||
handleConversion();
|
||||
}
|
||||
Serial.println();
|
||||
delay(100);
|
||||
}
|
||||
|
||||
void adsReady()
|
||||
{
|
||||
RDY = true;
|
||||
}
|
||||
|
||||
void handleConversion()
|
||||
{
|
||||
if (RDY)
|
||||
{
|
||||
// save the value
|
||||
val[channel] = ADS.getValue();
|
||||
// request next channel
|
||||
channel++;
|
||||
if (channel >= 4) channel = 0;
|
||||
ADS.readADC(channel);
|
||||
RDY = false;
|
||||
}
|
||||
}
|
||||
// -- END OF FILE --
|
||||
126
examples/ADS_continuous_8_channel/ADS_continuous_8_channel.ino
Normal file
126
examples/ADS_continuous_8_channel/ADS_continuous_8_channel.ino
Normal file
@@ -0,0 +1,126 @@
|
||||
//
|
||||
// FILE: ADS_continuous_8_channel.ino
|
||||
// AUTHOR: Rob.Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// PURPOSE: read multiple analog inputs continuously
|
||||
// interrupt driven to catch all conversions.
|
||||
//
|
||||
|
||||
// test
|
||||
// connect multiple potmeters to 2 ADS1115
|
||||
//
|
||||
// GND ---[ x ]------ 5V
|
||||
// |
|
||||
//
|
||||
// measure at x - connect to AIN0..4.
|
||||
//
|
||||
// for the test it is good to have AIN3 connected to 5V and AIN4 to GND
|
||||
// so one can see these as references in the output.
|
||||
//
|
||||
|
||||
#include "ADS1X15.h"
|
||||
|
||||
// adjust addresses if needed
|
||||
ADS1115 ADS_1(0x49);
|
||||
ADS1115 ADS_2(0x48);
|
||||
|
||||
volatile bool RDY_1 = false;
|
||||
volatile bool RDY_2 = false;
|
||||
uint8_t channel_1 = 0;
|
||||
uint8_t channel_2 = 0;
|
||||
int16_t val[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("ADS1X15_LIB_VERSION: ");
|
||||
Serial.println(ADS1X15_LIB_VERSION);
|
||||
|
||||
// SETUP FIRST ADS1115
|
||||
ADS_1.begin();
|
||||
ADS_1.setGain(0); // 6.144 volt
|
||||
ADS_1.setDataRate(7);
|
||||
|
||||
// SET ALERT RDY PIN
|
||||
ADS_1.setComparatorThresholdHigh(0x8000);
|
||||
ADS_1.setComparatorThresholdLow(0x0000);
|
||||
ADS_1.setComparatorQueConvert(0);
|
||||
|
||||
// SET INTERRUPT HANDLER TO CATCH CONVERSION READY
|
||||
pinMode(2, INPUT_PULLUP);
|
||||
attachInterrupt(digitalPinToInterrupt(2), adsReady_1, RISING);
|
||||
|
||||
ADS_1.setMode(0); // continuous mode
|
||||
ADS_1.readADC(channel_1); // trigger first read
|
||||
|
||||
|
||||
// SETUP SECOND ADS1115
|
||||
ADS_2.begin();
|
||||
ADS_2.setGain(0); // 6.144 volt
|
||||
ADS_2.setDataRate(7);
|
||||
|
||||
// SET ALERT RDY PIN
|
||||
ADS_2.setComparatorThresholdHigh(0x8000);
|
||||
ADS_2.setComparatorThresholdLow(0x0000);
|
||||
ADS_2.setComparatorQueConvert(0);
|
||||
|
||||
// SET INTERRUPT HANDLER TO CATCH CONVERSION READY
|
||||
pinMode(3, INPUT_PULLUP);
|
||||
attachInterrupt(digitalPinToInterrupt(3), adsReady_2, RISING);
|
||||
|
||||
ADS_2.setMode(0); // continuous mode
|
||||
ADS_2.readADC(channel_2); // trigger first read
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
handleConversion();
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
Serial.print(val[i]);
|
||||
Serial.print('\t');
|
||||
handleConversion();
|
||||
}
|
||||
Serial.println();
|
||||
delay(100);
|
||||
}
|
||||
|
||||
// catch interrupt and set flag
|
||||
void adsReady_1()
|
||||
{
|
||||
RDY_1 = true;
|
||||
}
|
||||
|
||||
void adsReady_2()
|
||||
{
|
||||
RDY_2 = true;
|
||||
}
|
||||
|
||||
// handle conversions that are ready
|
||||
void handleConversion()
|
||||
{
|
||||
if (RDY_1)
|
||||
{
|
||||
// save the last value
|
||||
val[channel_1] = ADS_1.getValue();
|
||||
// request next channel
|
||||
channel_1++;
|
||||
if (channel_1 >= 4) channel_1 = 0;
|
||||
ADS_1.readADC(channel_1);
|
||||
RDY_1 = false;
|
||||
}
|
||||
if (RDY_2)
|
||||
{
|
||||
// save the last value
|
||||
val[4 + channel_2] = ADS_2.getValue();
|
||||
// request next channel
|
||||
channel_2++;
|
||||
if (channel_2 >= 4) channel_2 = 0;
|
||||
ADS_2.readADC(channel_2);
|
||||
RDY_2 = false;
|
||||
}
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
||||
@@ -0,0 +1,123 @@
|
||||
//
|
||||
// FILE: ADS_continuous_differential.ino
|
||||
// AUTHOR: Rob.Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: read multiple differential continuously
|
||||
//
|
||||
|
||||
// test
|
||||
// connect 4 potmeters
|
||||
//
|
||||
// GND ---[ x ]------ 5V
|
||||
// |
|
||||
//
|
||||
// measure at x - connect to AIN0..4.
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
#include "ADS1X15.h"
|
||||
|
||||
// choose you sensor
|
||||
// ADS1013 ADS(0x48);
|
||||
// ADS1014 ADS(0x48);
|
||||
// ADS1015 ADS(0x48);
|
||||
// ADS1113 ADS(0x48);
|
||||
// ADS1114 ADS(0x48);
|
||||
ADS1115 ADS(0x48);
|
||||
|
||||
|
||||
// interrupt flag
|
||||
volatile bool RDY = false;
|
||||
// which pair to use for differential
|
||||
uint8_t pair = 01;
|
||||
// two values to hold differential measurements.
|
||||
int16_t val_01 = 0;
|
||||
int16_t val_23 = 0;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("ADS1X15_LIB_VERSION: ");
|
||||
Serial.println(ADS1X15_LIB_VERSION);
|
||||
|
||||
// SET INTERRUPT HANDLER TO CATCH CONVERSION READY
|
||||
pinMode(2, INPUT_PULLUP);
|
||||
attachInterrupt(digitalPinToInterrupt(2), adsReady, RISING);
|
||||
|
||||
ADS.begin();
|
||||
Serial.print("connected: ");
|
||||
Serial.println(ADS.isConnected());
|
||||
ADS.setGain(0); // 6.144 volt
|
||||
ADS.setDataRate(0); // 0 = slow 4 = medium 7 = fast (7 = fails )
|
||||
// every step is about a factor 2 slower.
|
||||
|
||||
// SET ALERT RDY PIN
|
||||
ADS.setComparatorThresholdHigh(0x8000);
|
||||
ADS.setComparatorThresholdLow(0x0000);
|
||||
ADS.setComparatorQueConvert(0);
|
||||
|
||||
// continuous mode
|
||||
ADS.setMode(0);
|
||||
// start with first pair
|
||||
pair = 01;
|
||||
// trigger first read
|
||||
ADS.requestADC_Differential_0_1();
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
static uint32_t last = 0;
|
||||
if (handleConversion() == true)
|
||||
{
|
||||
uint32_t now = millis();
|
||||
Serial.print(now - last);
|
||||
last = now;
|
||||
Serial.print("\tCOMP:\t");
|
||||
Serial.print(val_01);
|
||||
Serial.print("\t");
|
||||
Serial.print(val_23);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
// do other stuff here
|
||||
// delay(10);
|
||||
}
|
||||
|
||||
// interrupt handler, just sets the RDY flag
|
||||
void adsReady()
|
||||
{
|
||||
RDY = true;
|
||||
}
|
||||
|
||||
// can be changed to hold other differentials or normal reads too.
|
||||
bool handleConversion()
|
||||
{
|
||||
if (RDY)
|
||||
{
|
||||
RDY = false;
|
||||
if (pair == 01)
|
||||
{
|
||||
val_01 = ADS.getValue();
|
||||
pair = 23;
|
||||
ADS.requestADC_Differential_2_3();
|
||||
return false; // only one done
|
||||
}
|
||||
|
||||
// last of series to check
|
||||
if (pair == 23)
|
||||
{
|
||||
val_23 = ADS.getValue();
|
||||
pair = 01;
|
||||
ADS.requestADC_Differential_0_1();
|
||||
return true; // both are updated
|
||||
}
|
||||
}
|
||||
return false; // default not all read
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
64
examples/ADS_differential/ADS_differential.ino
Normal file
64
examples/ADS_differential/ADS_differential.ino
Normal file
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// FILE: ADS_differential.ino
|
||||
// AUTHOR: Rob.Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// PURPOSE: read differential
|
||||
//
|
||||
|
||||
// test 1
|
||||
// connect 2 potmeters in series
|
||||
//
|
||||
// GND ---[ x ]------[ y ]---- 5V
|
||||
// | |
|
||||
//
|
||||
// measure at x and y (connect to AIN0 and AIN1).
|
||||
// x should be lower or equal to y
|
||||
|
||||
// test 2
|
||||
// connect 2 potmeters parallel
|
||||
//
|
||||
// GND ---[ x ]------ 5V
|
||||
// |
|
||||
//
|
||||
// GND ---[ y ]------ 5V
|
||||
// |
|
||||
//
|
||||
// measure at x and y (connect to AIN0 and AIN1).
|
||||
// range from -VDD .. +VDD are possible
|
||||
|
||||
#include <ADS1X15.h>
|
||||
|
||||
ADS1115 ADS(0x48);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("ADS1X15_LIB_VERSION: ");
|
||||
Serial.println(ADS1X15_LIB_VERSION);
|
||||
|
||||
ADS.begin();
|
||||
ADS.setGain(0);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int16_t val_01 = ADS.readADC_Differential_0_1();
|
||||
int16_t val_03 = ADS.readADC_Differential_0_3();
|
||||
int16_t val_13 = ADS.readADC_Differential_1_3();
|
||||
int16_t val_23 = ADS.readADC_Differential_2_3();
|
||||
float volts_01 = ADS.toVoltage(val_01);
|
||||
float volts_03 = ADS.toVoltage(val_03);
|
||||
float volts_13 = ADS.toVoltage(val_13);
|
||||
float volts_23 = ADS.toVoltage(val_23);
|
||||
|
||||
Serial.print("\tval_01: "); Serial.print(val_01); Serial.print("\t"); Serial.println(volts_01, 3);
|
||||
Serial.print("\tval_03: "); Serial.print(val_03); Serial.print("\t"); Serial.println(volts_03, 3);
|
||||
Serial.print("\tval_13: "); Serial.print(val_13); Serial.print("\t"); Serial.println(volts_13, 3);
|
||||
Serial.print("\tval_23: "); Serial.print(val_23); Serial.print("\t"); Serial.println(volts_23, 3);
|
||||
Serial.println();
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
||||
@@ -0,0 +1,124 @@
|
||||
//
|
||||
// FILE: ADS_high_speed_differential.ino.ino
|
||||
// AUTHOR: Rob.Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: read from 2 IC's for high speed differential
|
||||
// interrupt driven to catch all conversions.
|
||||
//
|
||||
|
||||
// test setup (not tested yet)
|
||||
// - connect 2 ADS1x15 to I2C bus
|
||||
// - connect potmeters to all channels
|
||||
// - code reads both at the same frequency
|
||||
// and calculates differential per pair.
|
||||
// as 2 ADC's go in parallel, two ADS1015 should get
|
||||
// 3000+ differential samples / second.
|
||||
//
|
||||
|
||||
|
||||
#include "ADS1X15.h"
|
||||
|
||||
// adjust addresses if needed
|
||||
ADS1115 ADS_1(0x49);
|
||||
ADS1115 ADS_2(0x48);
|
||||
|
||||
volatile bool RDY_1 = false;
|
||||
volatile bool RDY_2 = false;
|
||||
uint8_t channel = 0;
|
||||
int32_t differential[4] = { 0, 0, 0, 0 };
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("ADS1X15_LIB_VERSION: ");
|
||||
Serial.println(ADS1X15_LIB_VERSION);
|
||||
|
||||
// SETUP FIRST ADS1115
|
||||
ADS_1.begin();
|
||||
ADS_1.setGain(0); // 6.144 volt
|
||||
ADS_1.setDataRate(7); // fastest conversion rate.
|
||||
|
||||
// SET ALERT RDY PIN
|
||||
ADS_1.setComparatorThresholdHigh(0x8000);
|
||||
ADS_1.setComparatorThresholdLow(0x0000);
|
||||
ADS_1.setComparatorQueConvert(0);
|
||||
|
||||
// SET INTERRUPT HANDLER TO CATCH CONVERSION READY
|
||||
pinMode(2, INPUT_PULLUP);
|
||||
attachInterrupt(digitalPinToInterrupt(2), adsReady_1, RISING);
|
||||
|
||||
ADS_1.setMode(0); // continuous mode
|
||||
ADS_1.readADC(channel); // trigger first read
|
||||
|
||||
|
||||
// SETUP SECOND ADS1115
|
||||
ADS_2.begin();
|
||||
ADS_2.setGain(0); // 6.144 volt
|
||||
ADS_2.setDataRate(7);
|
||||
|
||||
// SET ALERT RDY PIN
|
||||
ADS_2.setComparatorThresholdHigh(0x8000);
|
||||
ADS_2.setComparatorThresholdLow(0x0000);
|
||||
ADS_2.setComparatorQueConvert(0);
|
||||
|
||||
// SET INTERRUPT HANDLER TO CATCH CONVERSION READY
|
||||
pinMode(3, INPUT_PULLUP);
|
||||
attachInterrupt(digitalPinToInterrupt(3), adsReady_2, RISING);
|
||||
|
||||
ADS_2.setMode(0); // continuous mode
|
||||
ADS_2.readADC(channel); // trigger first read
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (handleConversion() == true)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Serial.print(differential[i]);
|
||||
Serial.print("\t");
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// catch interrupt and set flag
|
||||
void adsReady_1()
|
||||
{
|
||||
RDY_1 = true;
|
||||
}
|
||||
|
||||
void adsReady_2()
|
||||
{
|
||||
RDY_2 = true;
|
||||
}
|
||||
|
||||
|
||||
// handle conversions if both are ready
|
||||
bool handleConversion()
|
||||
{
|
||||
if (RDY_1 == false) return false;
|
||||
if (RDY_2 == false) return false;
|
||||
|
||||
// read the value of both
|
||||
int16_t a = ADS_1.getValue();
|
||||
int16_t b = ADS_2.getValue();
|
||||
differential[channel] = a - b;
|
||||
// request next channel
|
||||
channel++;
|
||||
if (channel >= 4) channel = 0;
|
||||
ADS_1.readADC(channel);
|
||||
ADS_2.readADC(channel);
|
||||
RDY_1 = false;
|
||||
RDY_2 = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
46
examples/ADS_minimum/ADS_minimum.ino
Normal file
46
examples/ADS_minimum/ADS_minimum.ino
Normal file
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// FILE: ADS_minimum.ino
|
||||
// AUTHOR: Rob.Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: read analog input
|
||||
//
|
||||
|
||||
// test
|
||||
// connect 1 potmeter
|
||||
//
|
||||
// GND ---[ x ]------ 5V
|
||||
// |
|
||||
//
|
||||
// measure at x (connect to AIN0).
|
||||
|
||||
// view with Serial Plotter
|
||||
|
||||
#include "ADS1X15.h"
|
||||
|
||||
// choose you sensor
|
||||
// ADS1013 ADS(0x48);
|
||||
// ADS1014 ADS(0x48);
|
||||
// ADS1015 ADS(0x48);
|
||||
// ADS1113 ADS(0x48);
|
||||
// ADS1114 ADS(0x48);
|
||||
ADS1115 ADS(0x48);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("ADS1X15_LIB_VERSION: ");
|
||||
Serial.println(ADS1X15_LIB_VERSION);
|
||||
|
||||
ADS.begin();
|
||||
ADS.setGain(0); // 6.144 volt
|
||||
Serial.println("Voltage");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int16_t raw = ADS.readADC(0);
|
||||
Serial.println(ADS.toVoltage(raw), 3);
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
||||
92
examples/ADS_performance/ADS_performance.ino
Normal file
92
examples/ADS_performance/ADS_performance.ino
Normal file
@@ -0,0 +1,92 @@
|
||||
//
|
||||
// FILE: ADS_performance.ino
|
||||
// AUTHOR: Rob.Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// PURPOSE: read analog input
|
||||
//
|
||||
|
||||
// test
|
||||
// connect 1 potmeter
|
||||
//
|
||||
// GND ---[ x ]------ 5V
|
||||
// |
|
||||
//
|
||||
// measure at x (connect to AIN0).
|
||||
|
||||
|
||||
#include "ADS1X15.h"
|
||||
|
||||
// choose you sensor
|
||||
// ADS1013 ADS(0x48);
|
||||
// ADS1014 ADS(0x48);
|
||||
// ADS1015 ADS(0x48);
|
||||
// ADS1113 ADS(0x48);
|
||||
// ADS1114 ADS(0x48);
|
||||
ADS1115 ADS(0x48);
|
||||
|
||||
uint32_t start, d1, d2;
|
||||
int x;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("ADS1X15_LIB_VERSION: ");
|
||||
Serial.println(ADS1X15_LIB_VERSION);
|
||||
|
||||
ADS.begin();
|
||||
ADS.setGain(0); // 6.144 volt
|
||||
|
||||
for (int dr = 0; dr < 8; dr++)
|
||||
{
|
||||
ADS.setDataRate(dr);
|
||||
Serial.print("DR:\t");
|
||||
Serial.println(dr);
|
||||
|
||||
test_single_shot();
|
||||
test_continuous();
|
||||
|
||||
Serial.print("\t\tFACTOR:\t");
|
||||
Serial.println(1.0 * d1 / d2);
|
||||
}
|
||||
|
||||
Serial.println("\nDone...");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
void test_single_shot()
|
||||
{
|
||||
Serial.print(__FUNCTION__);
|
||||
|
||||
ADS.setMode(1);
|
||||
start = micros();
|
||||
x = ADS.readADC(0);
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
x = ADS.readADC(0);
|
||||
}
|
||||
d1 = micros() - start;
|
||||
Serial.print("\t");
|
||||
Serial.println(d1);
|
||||
}
|
||||
|
||||
void test_continuous()
|
||||
{
|
||||
Serial.print(__FUNCTION__);
|
||||
|
||||
ADS.setMode(0);
|
||||
start = micros();
|
||||
x = ADS.readADC(0);
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
x = ADS.getValue();
|
||||
}
|
||||
d2 = micros() - start;
|
||||
Serial.print("\t\t");
|
||||
Serial.println(d2);
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
||||
51
examples/ADS_read/ADS_read.ino
Normal file
51
examples/ADS_read/ADS_read.ino
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// FILE: ADS_read.ino
|
||||
// AUTHOR: Rob.Tillaart
|
||||
// VERSION: 0.2.1
|
||||
// PURPOSE: read analog inputs - straightforward.
|
||||
//
|
||||
|
||||
// test
|
||||
// connect 1 potmeter per port.
|
||||
//
|
||||
// GND ---[ x ]------ 5V
|
||||
// |
|
||||
//
|
||||
// measure at x (connect to AIN0).
|
||||
//
|
||||
|
||||
#include "ADS1X15.h"
|
||||
|
||||
ADS1115 ADS(0x48);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("ADS1X15_LIB_VERSION: ");
|
||||
Serial.println(ADS1X15_LIB_VERSION);
|
||||
|
||||
ADS.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
ADS.setGain(0);
|
||||
|
||||
int16_t val_0 = ADS.readADC(0);
|
||||
int16_t val_1 = ADS.readADC(1);
|
||||
int16_t val_2 = ADS.readADC(2);
|
||||
int16_t val_3 = ADS.readADC(3);
|
||||
|
||||
float f = ADS.toVoltage(1); // voltage factor
|
||||
|
||||
Serial.print("\tAnalog0: "); Serial.print(val_0); Serial.print('\t'); Serial.println(val_0 * f, 3);
|
||||
Serial.print("\tAnalog1: "); Serial.print(val_1); Serial.print('\t'); Serial.println(val_1 * f, 3);
|
||||
Serial.print("\tAnalog2: "); Serial.print(val_2); Serial.print('\t'); Serial.println(val_2 * f, 3);
|
||||
Serial.print("\tAnalog3: "); Serial.print(val_3); Serial.print('\t'); Serial.println(val_3 * f, 3);
|
||||
Serial.println();
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
||||
62
examples/ADS_read_RDY/ADS_read_RDY.ino
Normal file
62
examples/ADS_read_RDY/ADS_read_RDY.ino
Normal file
@@ -0,0 +1,62 @@
|
||||
//
|
||||
// FILE: ADS_read_RDY.ino
|
||||
// AUTHOR: Rob.Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: read analog inputs - straightforward.
|
||||
//
|
||||
|
||||
// test
|
||||
// connect 1 potmeter per port.
|
||||
//
|
||||
// GND ---[ x ]------ 5V
|
||||
// |
|
||||
//
|
||||
// measure at x (connect to AIN0).
|
||||
//
|
||||
|
||||
// EXPERIMENTAL
|
||||
//
|
||||
// The RDY pin (or ALERT Pin) is triggered when conversion is ready
|
||||
//
|
||||
|
||||
#include "ADS1X15.h"
|
||||
|
||||
ADS1115 ADS(0x48);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("ADS1X15_LIB_VERSION: ");
|
||||
Serial.println(ADS1X15_LIB_VERSION);
|
||||
|
||||
ADS.begin();
|
||||
ADS.setGain(0); // 6.144 volt
|
||||
ADS.setDataRate(7); // fast
|
||||
ADS.setMode(1); // continuous mode
|
||||
ADS.readADC(0); // first read to trigger
|
||||
|
||||
// set the thresholds to Trigger RDY pin
|
||||
ADS.setComparatorThresholdLow(0x0000);
|
||||
ADS.setComparatorThresholdHigh(0x0200);
|
||||
ADS.setComparatorQueConvert(0); // enable RDY pin !!
|
||||
ADS.setComparatorLatch(0);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
ADS.setGain(0);
|
||||
|
||||
int16_t val_0 = ADS.readADC(0);
|
||||
|
||||
float f = ADS.toVoltage(1); // voltage factor
|
||||
|
||||
Serial.print("\tAnalog0: ");
|
||||
Serial.print(val_0);
|
||||
Serial.print('\t');
|
||||
Serial.println(val_0 * f, 3);
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
||||
50
examples/ADS_read_async/ADS_read_async.ino
Normal file
50
examples/ADS_read_async/ADS_read_async.ino
Normal file
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// FILE: ADS_read_async.ino
|
||||
// AUTHOR: Rob.Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// PURPOSE: read analog inputs - asynchronous
|
||||
//
|
||||
|
||||
// test
|
||||
// connect 1 potmeter per port.
|
||||
//
|
||||
// GND ---[ x ]------ 5V
|
||||
// |
|
||||
//
|
||||
// measure at x (connect to AIN0).
|
||||
//
|
||||
|
||||
#include "ADS1X15.h"
|
||||
|
||||
ADS1115 ADS(0x48);
|
||||
float f = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("ADS1X15_LIB_VERSION: ");
|
||||
Serial.println(ADS1X15_LIB_VERSION);
|
||||
|
||||
ADS.begin();
|
||||
ADS.setGain(0);
|
||||
f = ADS.toVoltage(); // voltage factor
|
||||
ADS.requestADC(0);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (ADS.isBusy() == false)
|
||||
{
|
||||
int16_t val_0 = ADS.getValue();
|
||||
ADS.requestADC(0); // request a new one
|
||||
Serial.print("\tAnalog0: ");
|
||||
Serial.print(val_0);
|
||||
Serial.print('\t');
|
||||
Serial.println(val_0 * f, 3);
|
||||
}
|
||||
// simulate other tasks...
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
||||
62
examples/ADS_read_async_rdy/ADS_read_async_rdy.ino
Normal file
62
examples/ADS_read_async_rdy/ADS_read_async_rdy.ino
Normal file
@@ -0,0 +1,62 @@
|
||||
//
|
||||
// FILE: ADS_read_async_rdy.ino
|
||||
// AUTHOR: Rob.Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// PURPOSE: read analog inputs - straightforward.
|
||||
//
|
||||
|
||||
// test
|
||||
// connect 1 potmeter per port.
|
||||
//
|
||||
// GND ---[ x ]------ 5V
|
||||
// |
|
||||
//
|
||||
// measure at x (connect to AIN0).
|
||||
//
|
||||
|
||||
// EXPERIMENTAL
|
||||
//
|
||||
// The RDY pin (or ALERT Pin) is triggered when conversion is ready
|
||||
//
|
||||
|
||||
#include "ADS1X15.h"
|
||||
|
||||
ADS1115 ADS(0x48);
|
||||
float f = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("ADS1X15_LIB_VERSION: ");
|
||||
Serial.println(ADS1X15_LIB_VERSION);
|
||||
|
||||
ADS.begin();
|
||||
ADS.setGain(0); // 6.144 volt
|
||||
ADS.setDataRate(0); // slow so the led blinks visible for the eye.
|
||||
f = ADS.toVoltage(); // voltage factor
|
||||
ADS.requestADC(0);
|
||||
|
||||
// set the thresholds to Trigger RDY pin
|
||||
ADS.setComparatorThresholdLow(0x0000);
|
||||
ADS.setComparatorThresholdHigh(0x0200);
|
||||
ADS.setComparatorQueConvert(0); // enable RDY pin !!
|
||||
ADS.setComparatorLatch(0);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (ADS.isReady())
|
||||
{
|
||||
int16_t val_0 = ADS.getValue();
|
||||
ADS.requestADC(0); // request a new one
|
||||
Serial.print("\tAnalog0: ");
|
||||
Serial.print(val_0);
|
||||
Serial.print('\t');
|
||||
Serial.println(val_0 * f, 3);
|
||||
}
|
||||
// simulate other tasks...
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
||||
82
examples/ADS_read_comparator_1/ADS_read_comparator_1.ino
Normal file
82
examples/ADS_read_comparator_1/ADS_read_comparator_1.ino
Normal file
@@ -0,0 +1,82 @@
|
||||
//
|
||||
// FILE: ADS_read_comparator_1.ino
|
||||
// AUTHOR: Rob.Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: read analog inputs - straightforward.
|
||||
//
|
||||
|
||||
// test
|
||||
// connect 1 potmeter per port.
|
||||
//
|
||||
// GND ---[ x ]------ 5V
|
||||
// |
|
||||
//
|
||||
// measure at x (connect to AIN0).
|
||||
//
|
||||
//
|
||||
// GND ---[LED]---[ALERT_PIN]---[ R ]--- 5V
|
||||
//
|
||||
// Connect a LED (+ resistor) to ALERT PIN
|
||||
// and see it trigger at configured way by the comparator.
|
||||
//
|
||||
|
||||
|
||||
#include "ADS1X15.h"
|
||||
|
||||
ADS1115 ADS(0x48);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("ADS1X15_LIB_VERSION: ");
|
||||
Serial.println(ADS1X15_LIB_VERSION);
|
||||
|
||||
ADS.begin();
|
||||
|
||||
// change if needed.
|
||||
ADS.setComparatorMode(1); // 0 = TRADITIONAL 1 = WINDOW
|
||||
|
||||
ADS.setComparatorPolarity(0); // 0 = LOW (default) 1 = HIGH
|
||||
|
||||
// note NON-LATCH gives only a short pulse
|
||||
ADS.setComparatorLatch(1); // 0 = NON LATCH 1 = LATCH
|
||||
|
||||
ADS.setComparatorQueConvert(0); // 0 = trigger alert after 1 conversion
|
||||
|
||||
// set the thresholds as a number...
|
||||
// ADS.setComparatorThresholdLow(5000); // change if needed
|
||||
// ADS.setComparatorThresholdHigh(20000); // change if needed
|
||||
|
||||
// set the threshold as a voltage by using the voltage factor.
|
||||
float f = ADS.toVoltage(1); // voltage factor
|
||||
ADS.setComparatorThresholdLow(1.234 / f); // convert volts to number needed
|
||||
ADS.setComparatorThresholdHigh(3.142 / f); // convert volts to number needed
|
||||
|
||||
Serial.println(ADS.getComparatorThresholdLow());
|
||||
Serial.println(ADS.getComparatorThresholdHigh());
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
ADS.setGain(0);
|
||||
|
||||
int16_t val_0 = ADS.readADC(0);
|
||||
|
||||
float f = ADS.toVoltage(1); // voltage factor
|
||||
|
||||
Serial.print("\tAnalog0: ");
|
||||
Serial.print(val_0);
|
||||
Serial.print('\t');
|
||||
Serial.print(val_0 * f, 3);
|
||||
Serial.print('\t');
|
||||
Serial.print(ADS.getComparatorThresholdLow() * f, 3);
|
||||
Serial.print('\t');
|
||||
Serial.print(ADS.getComparatorThresholdHigh() * f, 3);
|
||||
Serial.println();
|
||||
|
||||
delay(100);
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
||||
62
examples/ADS_setWireClock/ADS_setWireClock.ino
Normal file
62
examples/ADS_setWireClock/ADS_setWireClock.ino
Normal file
@@ -0,0 +1,62 @@
|
||||
//
|
||||
// FILE: ADS_setWireClock.ino
|
||||
// AUTHOR: Rob.Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: read analog inputs - straightforward.
|
||||
//
|
||||
|
||||
// test
|
||||
// connect 1 potmeter per port.
|
||||
//
|
||||
// GND ---[ x ]------ 5V
|
||||
// |
|
||||
//
|
||||
// measure at x (connect to AIN0).
|
||||
//
|
||||
|
||||
#include "ADS1X15.h"
|
||||
|
||||
ADS1115 ADS(0x48);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("ADS1X15_LIB_VERSION: ");
|
||||
Serial.println(ADS1X15_LIB_VERSION);
|
||||
|
||||
ADS.begin();
|
||||
|
||||
Serial.println(F("\nSET\tACTUAL\n=================="));
|
||||
for (uint32_t speed = 50000; speed <= 1000000; speed += 50000)
|
||||
{
|
||||
ADS.setWireClock(speed);
|
||||
Serial.print(speed);
|
||||
Serial.print("\t");
|
||||
Serial.println(ADS.getWireClock());
|
||||
}
|
||||
ADS.setWireClock(100000);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
ADS.setGain(0);
|
||||
|
||||
int16_t val_0 = ADS.readADC(0);
|
||||
int16_t val_1 = ADS.readADC(1);
|
||||
int16_t val_2 = ADS.readADC(2);
|
||||
int16_t val_3 = ADS.readADC(3);
|
||||
|
||||
float f = ADS.toVoltage(1); // voltage factor
|
||||
|
||||
Serial.print("\tAnalog0: "); Serial.print(val_0); Serial.print('\t'); Serial.println(val_0 * f, 3);
|
||||
Serial.print("\tAnalog1: "); Serial.print(val_1); Serial.print('\t'); Serial.println(val_1 * f, 3);
|
||||
Serial.print("\tAnalog2: "); Serial.print(val_2); Serial.print('\t'); Serial.println(val_2 * f, 3);
|
||||
Serial.print("\tAnalog3: "); Serial.print(val_3); Serial.print('\t'); Serial.println(val_3 * f, 3);
|
||||
Serial.println();
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
||||
Reference in New Issue
Block a user