Skip to content

Commit

Permalink
0.3.12 ADS1x15
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart committed Sep 14, 2023
1 parent fb8e834 commit cc6f8d9
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 10 deletions.
27 changes: 25 additions & 2 deletions libraries/ADS1x15/ADS1X15.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// FILE: ADS1X15.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.3.11
// VERSION: 0.3.12
// DATE: 2013-03-24
// PUPROSE: Arduino library for ADS1015 and ADS1115
// URL: https://github.com/RobTillaart/ADS1X15
Expand Down Expand Up @@ -136,6 +136,7 @@ void ADS1X15::reset()
_compPol = 1;
_compLatch = 0;
_compQueConvert = 3;
_lastRequest = 0xFFFF; // no request yet
}


Expand Down Expand Up @@ -335,6 +336,24 @@ bool ADS1X15::isReady()
}


uint8_t ADS1X15::lastRequest()
{
switch (_lastRequest)
{
case ADS1X15_READ_0: return 0x00;
case ADS1X15_READ_1: return 0x01;
case ADS1X15_READ_2: return 0x02;
case ADS1X15_READ_3: return 0x03;
// technically 0x01 -- but would collide with READ_1
case ADS1X15_MUX_DIFF_0_1: return 0x10;
case ADS1X15_MUX_DIFF_0_3: return 0x30;
case ADS1X15_MUX_DIFF_1_3: return 0x31;
case ADS1X15_MUX_DIFF_2_3: return 0x32;
}
return 0xFF;
}


void ADS1X15::setComparatorMode(uint8_t mode)
{
_compMode = mode == 0 ? 0 : 1;
Expand Down Expand Up @@ -462,7 +481,8 @@ int16_t ADS1X15::_readADC(uint16_t readmode)
}
else
{
delay(_conversionDelay); // TODO needed in continuous mode?
// needed in continuous mode too, otherwise one get old value.
delay(_conversionDelay);
}
return getValue();
}
Expand All @@ -484,6 +504,9 @@ void ADS1X15::_requestADC(uint16_t readmode)
else config |= ADS1X15_COMP_NON_LATCH; // bit 2 ALERT latching
config |= _compQueConvert; // bit 0..1 ALERT mode
_writeRegister(_address, ADS1X15_REG_CONFIG, config);

// remember last request type.
_lastRequest = readmode;
}


Expand Down
18 changes: 15 additions & 3 deletions libraries/ADS1x15/ADS1X15.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once
//
// FILE: ADS1X15.H
// FILE: ADS1X15.h
// AUTHOR: Rob Tillaart
// VERSION: 0.3.11
// VERSION: 0.3.12
// DATE: 2013-03-24
// PUPROSE: Arduino library for ADS1015 and ADS1115
// URL: https://github.com/RobTillaart/ADS1X15
Expand All @@ -12,7 +12,7 @@
#include "Arduino.h"
#include "Wire.h"

#define ADS1X15_LIB_VERSION (F("0.3.11"))
#define ADS1X15_LIB_VERSION (F("0.3.12"))

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

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

Expand All @@ -91,6 +92,12 @@ class ADS1X15
bool isReady();


// returns a pin 0x0[0..3] or
// a differential "mode" 0x[pin second][pin first] or
// 0xFF (no request / invalid request)
uint8_t lastRequest();


// COMPARATOR
// 0 = TRADITIONAL > high => on < low => off
// else = WINDOW > high or < low => on between => off
Expand Down Expand Up @@ -162,6 +169,11 @@ class ADS1X15
uint8_t _compLatch;
uint8_t _compQueConvert;

// variable to track the last pin requested,
// to allow for round robin query of
// pins based on this state == if no last request then == 0xFFFF.
uint16_t _lastRequest;

int16_t _readADC(uint16_t readmode);
void _requestADC(uint16_t readmode);
bool _writeRegister(uint8_t address, uint8_t reg, uint16_t value);
Expand Down
5 changes: 4 additions & 1 deletion libraries/ADS1x15/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [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
Expand All @@ -14,7 +18,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- reordered code in .cpp to follow .h
- minor edits


## [0.3.10] - 2023-06-07
- fix NANO RP2040
- update and add examples
Expand Down
36 changes: 34 additions & 2 deletions libraries/ADS1x15/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,38 @@ After one of these calls you need to call
See [examples](https://github.com/RobTillaart/ADS1X15/blob/master/examples/ADS_differential/ADS_differential.ino).


#### lastRequestMode

Since 0.3.12 the library tracks the last request mode, single pin or differential.
This variable is set at the moment of request, and keeps its value until a new
request is made. This implies that the value / request can be quite old.

Values >= 0x10 are differential, values < 0x10 are single pin.

- **uint8_t lastRequest()** returns one of the values below.

| Value | Description | Notes |
|:-------:|:-----------------------------|:--------|
| 0xFF | no (invalid) request made | after call constructor.
| 0x00 | single pin 0 |
| 0x01 | single pin 1 |
| 0x02 | single pin 2 |
| 0x03 | single pin 3 |
| 0x10 | differential pin 1 0 |
| 0x30 | differential pin 3 0 |
| 0x31 | differential pin 3 1 |
| 0x32 | differential pin 3 2 |


Please note that (for now) the function does not support a descriptive return value
for the following two requests:
- **readADC_Differential_0_2()** ADS1x15 only - in software (no async equivalent)
- **readADC_Differential_1_2()** ADS1x15 only - in software (no async equivalent)

As these are emulated in software by two single pin calls, the state would be
one of the two single pin values.


#### ReadADC continuous mode

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

#### Could

- More examples ?
- More examples
- SMB alert command (00011001) on I2C bus?
- sync order .h / .cpp


#### Wont (unless requested)

- type flag?
- constructor for ADS1X15?
- constructor for ADS1X15? No as all types are supported.


## Support
Expand Down
2 changes: 2 additions & 0 deletions libraries/ADS1x15/keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ readADC_Differential_1_3 KEYWORD2
readADC_Differential_2_3 KEYWORD2
getValue KEYWORD2

getLastRequest KEYWORD2

setComparatorMode KEYWORD2
getComparatorMode KEYWORD2
setComparatorPolarity KEYWORD2
Expand Down
2 changes: 1 addition & 1 deletion libraries/ADS1x15/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/ADS1X15"
},
"version": "0.3.11",
"version": "0.3.12",
"license": "MIT",
"frameworks": "*",
"platforms": "*",
Expand Down
2 changes: 1 addition & 1 deletion libraries/ADS1x15/library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ADS1X15
version=0.3.11
version=0.3.12
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
Expand Down

0 comments on commit cc6f8d9

Please sign in to comment.