Skip to content

Commit 156c4cc

Browse files
committed
0.3.11 ADS1x15
1 parent f804076 commit 156c4cc

File tree

6 files changed

+148
-51
lines changed

6 files changed

+148
-51
lines changed

libraries/ADS1x15/ADS1X15.cpp

Lines changed: 76 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: ADS1X15.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.3.10
4+
// VERSION: 0.3.11
55
// DATE: 2013-03-24
66
// PUPROSE: Arduino library for ADS1015 and ADS1115
77
// URL: https://github.com/RobTillaart/ADS1X15
@@ -173,19 +173,6 @@ bool ADS1X15::begin()
173173
}
174174

175175

176-
bool ADS1X15::isBusy()
177-
{
178-
return isReady() == false;
179-
}
180-
181-
182-
bool ADS1X15::isReady()
183-
{
184-
uint16_t val = _readRegister(_address, ADS1X15_REG_CONFIG);
185-
return ((val & ADS1X15_OS_NOT_BUSY) > 0);
186-
}
187-
188-
189176
bool ADS1X15::isConnected()
190177
{
191178
_wire->beginTransmission(_address);
@@ -307,15 +294,17 @@ int16_t ADS1X15::readADC(uint8_t pin)
307294
}
308295

309296

310-
void ADS1X15::requestADC_Differential_0_1()
297+
int16_t ADS1X15::readADC_Differential_0_1()
311298
{
312-
_requestADC(ADS1X15_MUX_DIFF_0_1);
299+
return _readADC(ADS1X15_MUX_DIFF_0_1);
313300
}
314301

315302

316-
int16_t ADS1X15::readADC_Differential_0_1()
303+
int16_t ADS1X15::getValue()
317304
{
318-
return _readADC(ADS1X15_MUX_DIFF_0_1);
305+
int16_t raw = _readRegister(_address, ADS1X15_REG_CONVERT);
306+
if (_bitShift) raw >>= _bitShift; // Shift 12-bit results
307+
return raw;
319308
}
320309

321310

@@ -327,18 +316,77 @@ void ADS1X15::requestADC(uint8_t pin)
327316
}
328317

329318

330-
int16_t ADS1X15::getValue()
319+
void ADS1X15::requestADC_Differential_0_1()
331320
{
332-
int16_t raw = _readRegister(_address, ADS1X15_REG_CONVERT);
333-
if (_bitShift) raw >>= _bitShift; // Shift 12-bit results
334-
return raw;
321+
_requestADC(ADS1X15_MUX_DIFF_0_1);
322+
}
323+
324+
325+
bool ADS1X15::isBusy()
326+
{
327+
return isReady() == false;
328+
}
329+
330+
331+
bool ADS1X15::isReady()
332+
{
333+
uint16_t val = _readRegister(_address, ADS1X15_REG_CONFIG);
334+
return ((val & ADS1X15_OS_NOT_BUSY) > 0);
335+
}
336+
337+
338+
void ADS1X15::setComparatorMode(uint8_t mode)
339+
{
340+
_compMode = mode == 0 ? 0 : 1;
341+
}
342+
343+
344+
uint8_t ADS1X15::getComparatorMode()
345+
{
346+
return _compMode;
347+
}
348+
349+
350+
void ADS1X15::setComparatorPolarity(uint8_t pol)
351+
{
352+
_compPol = pol ? 0 : 1;
353+
}
354+
355+
356+
uint8_t ADS1X15::getComparatorPolarity()
357+
{
358+
return _compPol;
359+
}
360+
361+
362+
void ADS1X15::setComparatorLatch(uint8_t latch)
363+
{
364+
_compLatch = latch ? 0 : 1;
365+
}
366+
367+
368+
uint8_t ADS1X15::getComparatorLatch()
369+
{
370+
return _compLatch;
371+
}
372+
373+
374+
void ADS1X15::setComparatorQueConvert(uint8_t mode)
375+
{
376+
_compQueConvert = (mode < 3) ? mode : 3;
377+
}
378+
379+
380+
uint8_t ADS1X15::getComparatorQueConvert()
381+
{
382+
return _compQueConvert;
335383
}
336384

337385

338386
void ADS1X15::setComparatorThresholdLow(int16_t lo)
339387
{
340388
_writeRegister(_address, ADS1X15_REG_LOW_THRESHOLD, lo);
341-
};
389+
}
342390

343391

344392
int16_t ADS1X15::getComparatorThresholdLow()
@@ -367,17 +415,16 @@ int8_t ADS1X15::getError()
367415
}
368416

369417

418+
//////////////////////////////////////////////////////
419+
//
420+
// EXPERIMENTAL
421+
//
370422
void ADS1X15::setWireClock(uint32_t clockSpeed)
371423
{
372424
_clockSpeed = clockSpeed;
373425
_wire->setClock(_clockSpeed);
374426
}
375427

376-
377-
//////////////////////////////////////////////////////
378-
//
379-
// EXPERIMENTAL
380-
//
381428
// see https://github.com/RobTillaart/ADS1X15/issues/22
382429
// https://github.com/arduino/Arduino/issues/11457
383430
// TODO: get the real clock speed from the I2C interface if possible.
@@ -396,7 +443,7 @@ uint32_t ADS1X15::getWireClock()
396443
// not supported.
397444
// return -1;
398445

399-
#else // best effort is remembering it
446+
#else // best effort is remembering it
400447
return _clockSpeed;
401448
#endif
402449
}

libraries/ADS1x15/ADS1X15.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// FILE: ADS1X15.H
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.3.10
5+
// VERSION: 0.3.11
66
// DATE: 2013-03-24
77
// PUPROSE: Arduino library for ADS1015 and ADS1115
88
// URL: https://github.com/RobTillaart/ADS1X15
@@ -12,7 +12,7 @@
1212
#include "Arduino.h"
1313
#include "Wire.h"
1414

15-
#define ADS1X15_LIB_VERSION (F("0.3.10"))
15+
#define ADS1X15_LIB_VERSION (F("0.3.11"))
1616

1717
// allow compile time default address
1818
// address in { 0x48, 0x49, 0x4A, 0x4B }, no test...
@@ -39,7 +39,7 @@ class ADS1X15
3939
#if defined (ESP8266) || defined(ESP32)
4040
bool begin(int sda, int scl);
4141
#elif defined (ARDUINO_ARCH_RP2040) && !defined(__MBED__)
42-
bool begin(int sda, int scl);
42+
bool begin(int sda, int scl);
4343
#endif
4444

4545
bool begin();
@@ -94,25 +94,25 @@ class ADS1X15
9494
// COMPARATOR
9595
// 0 = TRADITIONAL > high => on < low => off
9696
// else = WINDOW > high or < low => on between => off
97-
void setComparatorMode(uint8_t mode) { _compMode = mode == 0 ? 0 : 1; };
98-
uint8_t getComparatorMode() { return _compMode; };
97+
void setComparatorMode(uint8_t mode);
98+
uint8_t getComparatorMode();
9999

100100
// 0 = LOW (default)
101101
// else = HIGH
102-
void setComparatorPolarity(uint8_t pol) { _compPol = pol ? 0 : 1; };
103-
uint8_t getComparatorPolarity() { return _compPol; };
102+
void setComparatorPolarity(uint8_t pol);
103+
uint8_t getComparatorPolarity();
104104

105105
// 0 = NON LATCH
106106
// else = LATCH
107-
void setComparatorLatch(uint8_t latch) { _compLatch = latch ? 0 : 1; };
108-
uint8_t getComparatorLatch() { return _compLatch; };
107+
void setComparatorLatch(uint8_t latch);
108+
uint8_t getComparatorLatch();
109109

110110
// 0 = trigger alert after 1 conversion
111111
// 1 = trigger alert after 2 conversions
112112
// 2 = trigger alert after 4 conversions
113113
// 3 = Disable comparator = default, also for all other values.
114-
void setComparatorQueConvert(uint8_t mode) { _compQueConvert = (mode < 3) ? mode : 3; };
115-
uint8_t getComparatorQueConvert() { return _compQueConvert; };
114+
void setComparatorQueConvert(uint8_t mode);
115+
uint8_t getComparatorQueConvert();
116116

117117
void setComparatorThresholdLow(int16_t lo);
118118
int16_t getComparatorThresholdLow();
@@ -129,6 +129,7 @@ class ADS1X15
129129
// not necessary the actual value
130130
uint32_t getWireClock();
131131

132+
132133
protected:
133134
ADS1X15();
134135

libraries/ADS1x15/CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
- update and add examples
99

1010

11+
## [0.3.11] - 2023-08-31
12+
- update readme.md
13+
- move code from .h to .cpp
14+
- reordered code in .cpp to follow .h
15+
- minor edits
16+
17+
1118
## [0.3.10] - 2023-06-07
1219
- fix NANO RP2040
1320
- update and add examples
1421
- minor edits
1522

16-
1723
## [0.3.9] - 2023-01-21
1824
- update GitHub actions
1925
- update license 2023
@@ -25,7 +31,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2531
- simplified changelog.md
2632

2733
## [0.3.7] - 2022-06-21
28-
- fix ESP32 Wire.begin datatype
34+
- fix ESP32 Wire.begin data type
2935

3036
## [0.3.6] - 2022-03-10
3137

libraries/ADS1x15/README.md

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
[![Arduino CI](https://github.com/RobTillaart/ADS1X15/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
33
[![Arduino-lint](https://github.com/RobTillaart/ADS1X15/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/ADS1X15/actions/workflows/arduino-lint.yml)
44
[![JSON check](https://github.com/RobTillaart/ADS1X15/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/ADS1X15/actions/workflows/jsoncheck.yml)
5+
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/ADS1X15.svg)](https://github.com/RobTillaart/ADS1X15/issues)
6+
57
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/ADS1X15/blob/master/LICENSE)
68
[![GitHub release](https://img.shields.io/github/release/RobTillaart/ADS1X15.svg?maxAge=3600)](https://github.com/RobTillaart/ADS1X15/releases)
9+
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/ADS1X15.svg)](https://registry.platformio.org/libraries/robtillaart/ADS1X15)
710

811

912
# ADS1X15
@@ -29,9 +32,18 @@ although not all sensors support all functionality.
2932
| ADS1115 | 4 | 16 | 860 | Y | Y | Tested |
3033

3134

32-
As the 1015 and the 1115 are both 4 channels these are the most
35+
As the ADS1015 and the ADS1115 are both 4 channels these are the most
3336
interesting from functionality point of view as these can also do
34-
differential measurement.
37+
differential measurements.
38+
39+
40+
#### Related
41+
42+
- https://github.com/RobTillaart/MCP_ADC (10 & 12 bit ADC, SPI, fast)
43+
- https://github.com/RobTillaart/PCF8591 (8 bit ADC + 1 bit DAC)
44+
45+
46+
## I2C Address
3547

3648
The address of the ADS1113/4/5 is determined by to which pin the **ADDR**
3749
is connected to:
@@ -52,7 +64,7 @@ is connected to:
5264

5365
#### Initializing
5466

55-
To initialize the library you must call constructor as described below.
67+
To initialize the library you must call a constructor as described below.
5668

5769
- **ADS1x15()** base constructor, should not be used.
5870
- **ADS1013(uint8_t address, TwoWire \*wire = &Wire)** Constructor with device address,
@@ -105,7 +117,7 @@ better the Arduino Wire lib should support this call (ESP32 does).
105117
106118
See - https://github.com/arduino/Arduino/issues/11457
107119
108-
Question: should this functionality be in this library?
120+
Question: Should this functionality be in this library?
109121
110122
111123
#### Programmable Gain
@@ -287,6 +299,27 @@ Instead you can configure the threshold registers to allow the **ALERT/RDY**
287299
pin to trigger an interrupt signal when conversion data ready.
288300

289301

302+
#### Switching mode or channel during continuous mode
303+
304+
When switching the operating mode or the ADC channel in continuous mode, be aware that
305+
the device will always finish the running conversion.
306+
This implies that after switching the mode or channel the first sample you get is probably
307+
the last sample with the previous settings, e.g. channel.
308+
This might be a problem for your project as this value can be in an "unexpected" range (outlier).
309+
310+
The robust way to change mode or channel therefore seems to be:
311+
312+
1. stop continuous mode,
313+
1. wait for running conversion to be ready,
314+
1. reject the last conversion or process it "under old settings",
315+
1. change the settings,
316+
1. restart (continuous mode) with the new settings.
317+
318+
This explicit stop takes extra time, however it should prevent "incorrect" readings.
319+
320+
(need to be verified with different models)
321+
322+
290323
#### Threshold registers
291324

292325
If the thresholdHigh is set to 0x0100 and the thresholdLow to 0x0000
@@ -381,7 +414,7 @@ mean something different see - Comparator Mode above or datasheet.
381414

382415
- **bool begin(int sda, int scl)** begin communication with the ADC.
383416
It has the parameter for selecting on which pins the communication should happen.
384-
wireUsed is optional. Check RP2040 Pinout for compatible pins.
417+
Check RP2040 Pinout for compatible pins.
385418
If, "Wire1" is used, you need to add "&Wire1" in the constructor.
386419

387420

@@ -390,7 +423,6 @@ If, "Wire1" is used, you need to add "&Wire1" in the constructor.
390423
#### Must
391424

392425
- Improve documentation (always)
393-
- move code from .h to .cpp (0.4.0)
394426

395427

396428
#### Should
@@ -400,9 +432,20 @@ If, "Wire1" is used, you need to add "&Wire1" in the constructor.
400432

401433
- More examples ?
402434
- SMB alert command (00011001) on I2C bus?
403-
- constructor for ADS1X15 ?
435+
- sync order .h / .cpp
436+
404437

405438
#### Wont (unless requested)
406439

407440
- type flag?
441+
- constructor for ADS1X15?
442+
443+
444+
## Support
445+
446+
If you appreciate my libraries, you can support the development and maintenance.
447+
Improve the quality of the libraries by providing issues and Pull Requests, or
448+
donate through PayPal or GitHub sponsors.
449+
450+
Thank you,
408451

libraries/ADS1x15/library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/RobTillaart/ADS1X15"
1717
},
18-
"version": "0.3.10",
18+
"version": "0.3.11",
1919
"license": "MIT",
2020
"frameworks": "*",
2121
"platforms": "*",

libraries/ADS1x15/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=ADS1X15
2-
version=0.3.10
2+
version=0.3.11
33
author=Rob Tillaart <[email protected]>
44
maintainer=Rob Tillaart <[email protected]>
55
sentence=Arduino library for ADS1015 - I2C 12 bit ADC and ADS1115 I2C 16 bit ADC

0 commit comments

Comments
 (0)