0.4.0 ADS1x15

This commit is contained in:
Rob Tillaart 2023-12-06 17:03:16 +01:00
parent 7f909c9f2f
commit b32f817808
29 changed files with 280 additions and 248 deletions

View File

@ -1,7 +1,7 @@
//
// FILE: ADS1X15.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.3.13
// VERSION: 0.4.0
// DATE: 2013-03-24
// PUPROSE: Arduino library for ADS1015 and ADS1115
// URL: https://github.com/RobTillaart/ADS1X15
@ -140,33 +140,8 @@ void ADS1X15::reset()
}
#if defined (ESP8266) || defined(ESP32)
bool ADS1X15::begin(int sda, int scl)
{
_wire->begin(sda, scl);
if ((_address < 0x48) || (_address > 0x4B)) return false;
if (! isConnected()) return false;
return true;
}
#elif defined (ARDUINO_ARCH_RP2040) && !defined(__MBED__)
bool ADS1X15::begin(int sda, int scl)
{
_wire->setSDA(sda);
_wire->setSCL(scl);
_wire->begin();
if ((_address < 0x48) || (_address > 0x4B)) return false;
if (! isConnected()) return false;
return true;
}
#endif
bool ADS1X15::begin()
{
_wire->begin();
if ((_address < 0x48) || (_address > 0x4B)) return false;
if (! isConnected()) return false;
return true;

View File

@ -2,7 +2,7 @@
//
// FILE: ADS1X15.h
// AUTHOR: Rob Tillaart
// VERSION: 0.3.13
// VERSION: 0.4.0
// DATE: 2013-03-24
// PUPROSE: Arduino library for ADS1015 and ADS1115
// URL: https://github.com/RobTillaart/ADS1X15
@ -12,7 +12,7 @@
#include "Arduino.h"
#include "Wire.h"
#define ADS1X15_LIB_VERSION (F("0.3.13"))
#define ADS1X15_LIB_VERSION (F("0.4.0"))
// allow compile time default address
// address in { 0x48, 0x49, 0x4A, 0x4B }, no test...
@ -36,12 +36,6 @@ class ADS1X15
public:
void reset();
#if defined (ESP8266) || defined(ESP32)
bool begin(int sda, int scl);
#elif defined (ARDUINO_ARCH_RP2040) && !defined(__MBED__)
bool begin(int sda, int scl);
#endif
bool begin();
bool isConnected();

View File

@ -5,17 +5,22 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.4.0] - 2023-12-06
- refactor API, begin()
- update readme.md
- update examples
----
## [0.3.13] - 2023-09-20
- fix #61 ESP32 begin()
## [0.3.12] - 2023-09-11
- update and add examples
- add **getLastRequest()** to track last type of measurement.
- update readme.md
- minor edits.
## [0.3.11] - 2023-08-31
- update readme.md
- move code from .h to .cpp

View File

@ -37,6 +37,15 @@ interesting from functionality point of view as these can also do
differential measurements.
#### 0.4.0 Breaking change
Version 0.4.0 introduced a breaking change.
You cannot set the pins in **begin()** any more.
This reduces the dependency of processor dependent Wire implementations.
The user has to call **Wire.begin()** and can optionally set the Wire pins
before calling **begin()**.
#### Related
- https://github.com/RobTillaart/MCP_ADC (10 & 12 bit ADC, SPI, fast)
@ -419,6 +428,9 @@ Set the number of conversions before trigger activates.
The **void setComparatorQueConvert(uint8_t mode)** is used to set the number of
conversions that exceed the threshold before the **ALERT/RDY** pin is set **HIGH**.
A value of 3 (or above) effectively disables the comparator. See table below.
To enable the conversion-ready function of the ALERT/RDY pin, it is necessary to set the MSB of the Hi_thresh register to 1 and the MSB of the Lo_thresh register to 0.
See [examples](https://github.com/RobTillaart/ADS1X15/blob/master/examples/ADS_continuous_differential/ADS_continuous_differential.ino).
- **void setComparatorQueConvert(uint8_t mode)** See table below.
- **uint8_t getComparatorQueConvert()** returns value set.
@ -442,27 +454,14 @@ mean something different see - Comparator Mode above or datasheet.
- **int16_t getComparatorThresholdHigh()** reads value from device.
## RP2040 specific
- **bool begin(int sda, int scl)** begin communication with the ADC.
It has the parameter for selecting on which pins the communication should happen.
Check RP2040 Pinout for compatible pins.
If, "Wire1" is used, you need to add "&Wire1" in the constructor.
## Future ideas & improvements
#### Must
- Improve documentation (always)
#### Should
- investigate of remove the begin(sda, scl) versions
as the responsibility for the Wire configuration
should not be in this library.
#### Could

View File

@ -27,6 +27,8 @@ void setup()
Serial.print("ADS1X15_LIB_VERSION: ");
Serial.println(ADS1X15_LIB_VERSION);
Wire.begin();
for (uint8_t i = 0; i < 4; i++)
{
uint8_t address = 0x48 + i;
@ -36,7 +38,8 @@ void setup()
Serial.print(" ");
Serial.println(ADS[i].begin() ? "connected" : "not connected");
ADS[i].setDataRate(4); // 0 = slow 4 = medium 7 = fast, but more noise
// 0 = slow 4 = medium 7 = fast, but more noise
ADS[i].setDataRate(4);
}
ADS_request_all();
}

View File

@ -27,6 +27,7 @@ void setup()
Serial.print("ADS1X15_LIB_VERSION: ");
Serial.println(ADS1X15_LIB_VERSION);
Wire.begin();
// SETUP FIRST ADS1114
ADS_1.begin();

View File

@ -5,7 +5,7 @@
// URL: https://github.com/RobTillaart/ADS1X15
// test
// connect 1 potmeter
// connect 1 potentiometer
//
// GND ---[ x ]------ 5V
// |
@ -32,7 +32,12 @@ void setup()
Serial.print("ADS1X15_LIB_VERSION: ");
Serial.println(ADS1X15_LIB_VERSION);
ADS.begin(26, 27); // SDA (Pin 26), SCL(Pin 27)
// SDA (Pin 26), SCL(Pin 27)
Wire1.begin();
Wire1.setSDA(26);
Wire1.setSCL(27);
ADS.begin();
ADS.setGain(0); // 6.144 volt
ADS.setDataRate(7); // 0 = slow 4 = medium 7 = fast
ADS.setMode(0); // continuous mode

View File

@ -1,9 +1,7 @@
//
// 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
@ -30,6 +28,8 @@ void setup()
Serial.print("ADS1X15_LIB_VERSION: ");
Serial.println(ADS1X15_LIB_VERSION);
Wire.begin();
for (uint8_t i = 0; i < 4; i++)
{
uint8_t address = 0x48 + i;
@ -39,7 +39,8 @@ void setup()
Serial.print(" ");
Serial.println(ADS[i].begin() ? "connected" : "not connected");
ADS[i].setDataRate(4); // 0 = slow 4 = medium 7 = fast, but more noise
// 0 = slow 4 = medium 7 = fast, but more noise
ADS[i].setDataRate(4);
}
ADS_request_all();
}

View File

@ -2,7 +2,6 @@
// 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
@ -36,6 +35,8 @@ void setup()
Serial.print("ADS1X15_LIB_VERSION: ");
Serial.println(ADS1X15_LIB_VERSION);
Wire.begin();
ADS0.begin();
ADS1.begin();
// ADS2.begin();
@ -46,7 +47,8 @@ void setup()
// Serial.println(ADS2.isConnected());
// Serial.println(ADS3.isConnected());
ADS0.setDataRate(4); // 0 = slow 4 = medium 7 = fast but more noise
// 0 = slow 4 = medium 7 = fast but more noise
ADS0.setDataRate(4);
ADS1.setDataRate(4);
// ADS2.setDataRate(4);
// ADS3.setDataRate(4);
@ -64,7 +66,8 @@ void loop()
// we have all 8 values
ADS_print_all();
delay(1000); // wait a second.
// wait a second.
delay(1000);
ADS_request_all();
}

View File

@ -1,7 +1,6 @@
//
// FILE: ADS_async_differential.ino
// AUTHOR: Rob.Tillaart
// VERSION: 0.1.0
// PURPOSE: read multiple differential continuously
// URL: https://github.com/RobTillaart/ADS1X15
@ -40,6 +39,8 @@ void setup()
Serial.print("ADS1X15_LIB_VERSION: ");
Serial.println(ADS1X15_LIB_VERSION);
Wire.begin();
ADS.begin();
ADS.setGain(0); // 6.144 volt
ADS.setDataRate(4); // 0 = slow 4 = medium 7 = fast

View File

@ -40,6 +40,8 @@ void setup()
Serial.print("ADS1X15_LIB_VERSION: ");
Serial.println(ADS1X15_LIB_VERSION);
Wire.begin();
ADS.begin();
ADS.setGain(0); // 6.144 volt
ADS.setDataRate(7); // 0 = slow 4 = medium 7 = fast

View File

@ -52,6 +52,7 @@ void setup()
Serial.print("ADS1X15_LIB_VERSION: ");
Serial.println(ADS1X15_LIB_VERSION);
Wire.begin();
Wire.setClock(400000);
ADS.begin();

View File

@ -41,6 +41,8 @@ void setup()
Serial.print("ADS1X15_LIB_VERSION: ");
Serial.println(ADS1X15_LIB_VERSION);
Wire.begin();
pinMode(2, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(2), adsReady, RISING);

View File

@ -43,6 +43,8 @@ void setup()
Serial.print("ADS1X15_LIB_VERSION: ");
Serial.println(ADS1X15_LIB_VERSION);
Wire.begin();
// SETUP FIRST ADS1115
ADS_1.begin();
ADS_1.setGain(0); // 6.144 volt

View File

@ -44,6 +44,8 @@ void setup()
Serial.print("ADS1X15_LIB_VERSION: ");
Serial.println(ADS1X15_LIB_VERSION);
Wire.begin();
// SET INTERRUPT HANDLER TO CATCH CONVERSION READY
pinMode(2, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(2), adsReady, RISING);
@ -55,8 +57,10 @@ void setup()
ADS.setDataRate(0); // 0 = slow 4 = medium 7 = fast (7 = fails )
// every step is about a factor 2 slower.
// SET ALERT RDY PIN
// SET ALERT RDY PIN (QueConvert mode)
// set the MSB of the Hi_thresh register to 1
ADS.setComparatorThresholdHigh(0x8000);
// set the MSB of the Lo_thresh register to 0
ADS.setComparatorThresholdLow(0x0000);
ADS.setComparatorQueConvert(0);

View File

@ -38,6 +38,8 @@ void setup()
Serial.print("ADS1X15_LIB_VERSION: ");
Serial.println(ADS1X15_LIB_VERSION);
Wire.begin();
ADS.begin();
ADS.setGain(0);
}

View File

@ -34,13 +34,17 @@ void setup()
Serial.print("ADS1X15_LIB_VERSION: ");
Serial.println(ADS1X15_LIB_VERSION);
Wire.begin();
// SETUP FIRST ADS1115
ADS_1.begin();
ADS_1.setGain(0); // 6.144 volt
ADS_1.setDataRate(7); // 0 = slow 4 = medium 7 = fast
// SET ALERT RDY PIN
// SET ALERT RDY PIN (QueConvert mode)
// set the MSB of the Hi_thresh register to 1
ADS_1.setComparatorThresholdHigh(0x8000);
// set the MSB of the Lo_thresh register to 0
ADS_1.setComparatorThresholdLow(0x0000);
ADS_1.setComparatorQueConvert(0);
@ -58,7 +62,9 @@ void setup()
ADS_2.setDataRate(7);
// SET ALERT RDY PIN
// set the MSB of the Hi_thresh register to 1
ADS_2.setComparatorThresholdHigh(0x8000);
// set the MSB of the Lo_thresh register to 0
ADS_2.setComparatorThresholdLow(0x0000);
ADS_2.setComparatorQueConvert(0);

View File

@ -35,6 +35,8 @@ void setup()
Serial.print("ADS1X15_LIB_VERSION: ");
Serial.println(ADS1X15_LIB_VERSION);
Wire.begin();
ADS.begin();
ADS.setGain(0); // 6.144 volt
Serial.println("Voltage");

View File

@ -38,10 +38,10 @@ void setup()
Serial.print("ADS1X15_LIB_VERSION: ");
Serial.println(ADS1X15_LIB_VERSION);
ADS.begin();
Wire.begin();
Wire.setClock(100000);
ADS.begin();
ADS.setGain(0); // 6.144 volt
for (int dr = 0; dr < 8; dr++)

View File

@ -23,6 +23,9 @@ void setup()
while(!Serial);
Serial.println(__FILE__);
Wire.begin();
Wire.setClock(100000);
ADS.begin(); // use defaults
readADC = analogRead; // start with internal

View File

@ -26,6 +26,7 @@ void setup()
Serial.print("ADS1X15_LIB_VERSION: ");
Serial.println(ADS1X15_LIB_VERSION);
Wire.begin();
ADS.begin();
}

View File

@ -5,7 +5,7 @@
// URL: https://github.com/RobTillaart/ADS1X15
// test
// connect 1 potmeter per port.
// connect 1 potentiometer per port.
//
// GND ---[ x ]------ 5V
// |
@ -31,6 +31,8 @@ void setup()
Serial.print("ADS1X15_LIB_VERSION: ");
Serial.println(ADS1X15_LIB_VERSION);
Wire.begin();
ADS.begin();
ADS.setGain(0); // 6.144 volt
ADS.setDataRate(7); // 0 = slow 4 = medium 7 = fast

View File

@ -27,6 +27,8 @@ void setup()
Serial.print("ADS1X15_LIB_VERSION: ");
Serial.println(ADS1X15_LIB_VERSION);
Wire.begin();
ADS.begin();
ADS.setGain(0);
f = ADS.toVoltage(); // voltage factor
@ -39,7 +41,8 @@ void loop()
if (ADS.isBusy() == false)
{
int16_t val_0 = ADS.getValue();
ADS.requestADC(0); // request a new one
// request a new one
ADS.requestADC(0);
Serial.print("\tAnalog0: ");
Serial.print(val_0);
Serial.print('\t');

View File

@ -32,8 +32,11 @@ void setup()
Serial.print("ADS1X15_LIB_VERSION: ");
Serial.println(ADS1X15_LIB_VERSION);
Wire.begin();
ADS.begin();
ADS.setGain(0); // 6.144 volt
// select slow so the led blinks visible for the eye.
ADS.setDataRate(0); // 0 = slow 4 = medium 7 = fast
f = ADS.toVoltage(); // voltage factor
@ -52,7 +55,8 @@ void loop()
if (ADS.isReady())
{
int16_t val_0 = ADS.getValue();
ADS.requestADC(0); // request a new one
// request a new one
ADS.requestADC(0);
Serial.print("\tAnalog0: ");
Serial.print(val_0);
Serial.print('\t');

View File

@ -32,6 +32,8 @@ void setup()
Serial.print("ADS1X15_LIB_VERSION: ");
Serial.println(ADS1X15_LIB_VERSION);
Wire.begin();
ADS.begin();
// change if needed.

View File

@ -5,7 +5,7 @@
// URL: https://github.com/RobTillaart/ADS1X15
// test
// connect 1 potmeter per port.
// connect 1 potentiometer per port.
//
// GND ---[ x ]------ 5V
// |

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/ADS1X15"
},
"version": "0.3.13",
"version": "0.4.0",
"license": "MIT",
"frameworks": "*",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=ADS1X15
version=0.3.13
version=0.4.0
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for ADS1015 - I2C 12 bit ADC and ADS1115 I2C 16 bit ADC

View File

@ -27,6 +27,7 @@
unittest_setup()
{
fprintf(stderr, "ADS1X15_LIB_VERSION: %s\n", (char *) ADS1X15_LIB_VERSION);
}
@ -37,8 +38,6 @@ unittest_teardown()
unittest(test_constants)
{
fprintf(stderr, "ADS1X15_LIB_VERSION: %s\n", (char *) ADS1X15_LIB_VERSION);
assertEqual(0x48, ADS1015_ADDRESS);
assertEqual(0x48, ADS1115_ADDRESS);
assertEqual( 0, ADS1X15_OK);
@ -51,6 +50,9 @@ unittest(test_constants)
unittest(test_begin)
{
ADS1115 ADS(0x48);
Wire.begin();
assertTrue(ADS.begin());
assertTrue(ADS.isConnected());
assertTrue(ADS.isBusy());
@ -60,6 +62,9 @@ unittest(test_begin)
unittest(test_gain)
{
ADS1115 ADS(0x48);
Wire.begin();
assertTrue(ADS.begin());
assertEqual(0, ADS.getGain());
@ -78,6 +83,9 @@ unittest(test_gain)
unittest(test_Voltage)
{
ADS1115 ADS(0x48);
Wire.begin();
assertTrue(ADS.begin());
// should test all values?
@ -96,4 +104,5 @@ unittest(test_Voltage)
unittest_main()
// --------
// -- END OF FILE --