Skip to content

Commit cc6f8d9

Browse files
committed
0.3.12 ADS1x15
1 parent fb8e834 commit cc6f8d9

File tree

7 files changed

+82
-10
lines changed

7 files changed

+82
-10
lines changed

libraries/ADS1x15/ADS1X15.cpp

Lines changed: 25 additions & 2 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.11
4+
// VERSION: 0.3.12
55
// DATE: 2013-03-24
66
// PUPROSE: Arduino library for ADS1015 and ADS1115
77
// URL: https://github.com/RobTillaart/ADS1X15
@@ -136,6 +136,7 @@ void ADS1X15::reset()
136136
_compPol = 1;
137137
_compLatch = 0;
138138
_compQueConvert = 3;
139+
_lastRequest = 0xFFFF; // no request yet
139140
}
140141

141142

@@ -335,6 +336,24 @@ bool ADS1X15::isReady()
335336
}
336337

337338

339+
uint8_t ADS1X15::lastRequest()
340+
{
341+
switch (_lastRequest)
342+
{
343+
case ADS1X15_READ_0: return 0x00;
344+
case ADS1X15_READ_1: return 0x01;
345+
case ADS1X15_READ_2: return 0x02;
346+
case ADS1X15_READ_3: return 0x03;
347+
// technically 0x01 -- but would collide with READ_1
348+
case ADS1X15_MUX_DIFF_0_1: return 0x10;
349+
case ADS1X15_MUX_DIFF_0_3: return 0x30;
350+
case ADS1X15_MUX_DIFF_1_3: return 0x31;
351+
case ADS1X15_MUX_DIFF_2_3: return 0x32;
352+
}
353+
return 0xFF;
354+
}
355+
356+
338357
void ADS1X15::setComparatorMode(uint8_t mode)
339358
{
340359
_compMode = mode == 0 ? 0 : 1;
@@ -462,7 +481,8 @@ int16_t ADS1X15::_readADC(uint16_t readmode)
462481
}
463482
else
464483
{
465-
delay(_conversionDelay); // TODO needed in continuous mode?
484+
// needed in continuous mode too, otherwise one get old value.
485+
delay(_conversionDelay);
466486
}
467487
return getValue();
468488
}
@@ -484,6 +504,9 @@ void ADS1X15::_requestADC(uint16_t readmode)
484504
else config |= ADS1X15_COMP_NON_LATCH; // bit 2 ALERT latching
485505
config |= _compQueConvert; // bit 0..1 ALERT mode
486506
_writeRegister(_address, ADS1X15_REG_CONFIG, config);
507+
508+
// remember last request type.
509+
_lastRequest = readmode;
487510
}
488511

489512

libraries/ADS1x15/ADS1X15.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#pragma once
22
//
3-
// FILE: ADS1X15.H
3+
// FILE: ADS1X15.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.3.11
5+
// VERSION: 0.3.12
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.11"))
15+
#define ADS1X15_LIB_VERSION (F("0.3.12"))
1616

1717
// allow compile time default address
1818
// address in { 0x48, 0x49, 0x4A, 0x4B }, no test...
@@ -78,6 +78,7 @@ class ADS1X15
7878
int16_t readADC_Differential_0_1();
7979

8080
// used by continuous mode and async mode.
81+
[[deprecated("Use getValue() instead")]]
8182
int16_t getLastValue() { return getValue(); }; // will be obsolete in the future 0.4.0
8283
int16_t getValue();
8384

@@ -91,6 +92,12 @@ class ADS1X15
9192
bool isReady();
9293

9394

95+
// returns a pin 0x0[0..3] or
96+
// a differential "mode" 0x[pin second][pin first] or
97+
// 0xFF (no request / invalid request)
98+
uint8_t lastRequest();
99+
100+
94101
// COMPARATOR
95102
// 0 = TRADITIONAL > high => on < low => off
96103
// else = WINDOW > high or < low => on between => off
@@ -162,6 +169,11 @@ class ADS1X15
162169
uint8_t _compLatch;
163170
uint8_t _compQueConvert;
164171

172+
// variable to track the last pin requested,
173+
// to allow for round robin query of
174+
// pins based on this state == if no last request then == 0xFFFF.
175+
uint16_t _lastRequest;
176+
165177
int16_t _readADC(uint16_t readmode);
166178
void _requestADC(uint16_t readmode);
167179
bool _writeRegister(uint8_t address, uint8_t reg, uint16_t value);

libraries/ADS1x15/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

77

8+
## [0.3.12] - 2023-09-11
89
- update and add examples
10+
- add **getLastRequest()** to track last type of measurement.
11+
- update readme.md
12+
- minor edits.
913

1014

1115
## [0.3.11] - 2023-08-31
@@ -14,7 +18,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1418
- reordered code in .cpp to follow .h
1519
- minor edits
1620

17-
1821
## [0.3.10] - 2023-06-07
1922
- fix NANO RP2040
2023
- update and add examples

libraries/ADS1x15/README.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,38 @@ After one of these calls you need to call
266266
See [examples](https://github.com/RobTillaart/ADS1X15/blob/master/examples/ADS_differential/ADS_differential.ino).
267267

268268

269+
#### lastRequestMode
270+
271+
Since 0.3.12 the library tracks the last request mode, single pin or differential.
272+
This variable is set at the moment of request, and keeps its value until a new
273+
request is made. This implies that the value / request can be quite old.
274+
275+
Values >= 0x10 are differential, values < 0x10 are single pin.
276+
277+
- **uint8_t lastRequest()** returns one of the values below.
278+
279+
| Value | Description | Notes |
280+
|:-------:|:-----------------------------|:--------|
281+
| 0xFF | no (invalid) request made | after call constructor.
282+
| 0x00 | single pin 0 |
283+
| 0x01 | single pin 1 |
284+
| 0x02 | single pin 2 |
285+
| 0x03 | single pin 3 |
286+
| 0x10 | differential pin 1 0 |
287+
| 0x30 | differential pin 3 0 |
288+
| 0x31 | differential pin 3 1 |
289+
| 0x32 | differential pin 3 2 |
290+
291+
292+
Please note that (for now) the function does not support a descriptive return value
293+
for the following two requests:
294+
- **readADC_Differential_0_2()** ADS1x15 only - in software (no async equivalent)
295+
- **readADC_Differential_1_2()** ADS1x15 only - in software (no async equivalent)
296+
297+
As these are emulated in software by two single pin calls, the state would be
298+
one of the two single pin values.
299+
300+
269301
#### ReadADC continuous mode
270302

271303
To use the continuous mode you need call three functions:
@@ -430,15 +462,15 @@ If, "Wire1" is used, you need to add "&Wire1" in the constructor.
430462

431463
#### Could
432464

433-
- More examples ?
465+
- More examples
434466
- SMB alert command (00011001) on I2C bus?
435467
- sync order .h / .cpp
436468

437469

438470
#### Wont (unless requested)
439471

440472
- type flag?
441-
- constructor for ADS1X15?
473+
- constructor for ADS1X15? No as all types are supported.
442474

443475

444476
## Support

libraries/ADS1x15/keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ readADC_Differential_1_3 KEYWORD2
3333
readADC_Differential_2_3 KEYWORD2
3434
getValue KEYWORD2
3535

36+
getLastRequest KEYWORD2
37+
3638
setComparatorMode KEYWORD2
3739
getComparatorMode KEYWORD2
3840
setComparatorPolarity KEYWORD2

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.11",
18+
"version": "0.3.12",
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.11
2+
version=0.3.12
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)