Skip to content

Commit 0974529

Browse files
authored
fix #68, gain for ADS1x13 (#69)
- fix #68, gain bugs ADS1x13 - add unit test for ADS1x13 - update GitHub/actions to v4 - removed depreciated **getLastValue()** - add multiplexer section to readme.md
1 parent 7ad1382 commit 0974529

File tree

12 files changed

+170
-15
lines changed

12 files changed

+170
-15
lines changed

.github/workflows/arduino-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
lint:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v3
9+
- uses: actions/checkout@v4
1010
- uses: arduino/arduino-lint-action@v1
1111
with:
1212
library-manager: update

.github/workflows/arduino_test_runner.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@v3
11+
- uses: actions/checkout@v4
1212
- uses: ruby/setup-ruby@v1
1313
with:
1414
ruby-version: 2.6

.github/workflows/jsoncheck.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
test:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v4
1414
- name: json-syntax-check
1515
uses: limitusus/json-syntax-check@v1
1616
with:

ADS1X15.cpp

Lines changed: 34 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.4.1
4+
// VERSION: 0.4.2
55
// DATE: 2013-03-24
66
// PURPOSE: Arduino library for ADS1015 and ADS1115
77
// URL: https://github.com/RobTillaart/ADS1X15
@@ -193,7 +193,7 @@ float ADS1X15::toVoltage(int16_t value)
193193
if (value == 0) return 0;
194194

195195
float volts = getMaxVoltage();
196-
if (volts < 0) return volts;
196+
if (volts < 0) return volts; // propagate error
197197

198198
volts *= value;
199199
if (_config & ADS_CONF_RES_16)
@@ -530,6 +530,22 @@ ADS1013::ADS1013(uint8_t address, TwoWire *wire)
530530
_conversionDelay = ADS1015_CONVERSION_DELAY;
531531
_bitShift = 4;
532532
_maxPorts = 1;
533+
_gain = ADS1X15_PGA_2_048V; // fixed value
534+
}
535+
536+
537+
// ADS1x13 has no gain so set default.
538+
// Table 8. Config Register Field Descriptions
539+
void ADS1013::setGain(uint8_t gain)
540+
{
541+
_gain = gain; // keep compiler happy.
542+
_gain = ADS1X15_PGA_2_048V; // fixed value
543+
}
544+
545+
546+
uint8_t ADS1013::getGain()
547+
{
548+
return 2; // fixed value
533549
}
534550

535551

@@ -623,6 +639,22 @@ ADS1113::ADS1113(uint8_t address, TwoWire *wire)
623639
_conversionDelay = ADS1115_CONVERSION_DELAY;
624640
_bitShift = 0;
625641
_maxPorts = 1;
642+
_gain = ADS1X15_PGA_2_048V; // fixed value
643+
}
644+
645+
646+
// ADS1x13 has no gain so set default.
647+
// Table 8. Config Register Field Descriptions
648+
void ADS1113::setGain(uint8_t gain)
649+
{
650+
_gain = gain; // keep compiler happy.
651+
_gain = ADS1X15_PGA_2_048V; // fixed value
652+
}
653+
654+
655+
uint8_t ADS1113::getGain()
656+
{
657+
return 2; // fixed value
626658
}
627659

628660

ADS1X15.h

Lines changed: 10 additions & 6 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.4.1
5+
// VERSION: 0.4.2
66
// DATE: 2013-03-24
77
// PURPOSE: 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.4.1"))
15+
#define ADS1X15_LIB_VERSION (F("0.4.2"))
1616

1717
// allow compile time default address
1818
// address in { 0x48, 0x49, 0x4A, 0x4B }, no test...
@@ -72,8 +72,8 @@ class ADS1X15
7272
int16_t readADC_Differential_0_1();
7373

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

7979

@@ -86,7 +86,7 @@ class ADS1X15
8686
bool isReady();
8787

8888

89-
// returns a pin 0x0[0..3] or
89+
// returns a pin 0x0[0..3] or
9090
// a differential "mode" 0x[pin second][pin first] or
9191
// 0xFF (no request / invalid request)
9292
uint8_t lastRequest();
@@ -164,7 +164,7 @@ class ADS1X15
164164
uint8_t _compLatch;
165165
uint8_t _compQueConvert;
166166

167-
// variable to track the last pin requested,
167+
// variable to track the last pin requested,
168168
// to allow for round robin query of
169169
// pins based on this state == if no last request then == 0xFFFF.
170170
uint16_t _lastRequest;
@@ -188,6 +188,8 @@ class ADS1013 : public ADS1X15
188188
{
189189
public:
190190
ADS1013(uint8_t Address = ADS1015_ADDRESS, TwoWire *wire = &Wire);
191+
void setGain(uint8_t gain);
192+
uint8_t getGain();
191193
};
192194

193195

@@ -217,6 +219,8 @@ class ADS1113 : public ADS1X15
217219
{
218220
public:
219221
ADS1113(uint8_t address = ADS1115_ADDRESS, TwoWire *wire = &Wire);
222+
void setGain(uint8_t gain);
223+
uint8_t getGain();
220224
};
221225

222226

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@ 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.4.2] - 2024-03-04
9+
- fix #68, gain bugs ADS1x13
10+
- add unit test for ADS1x13
11+
- update GitHub/actions to v4
12+
- removed depreciated **getLastValue()**
13+
- add multiplexer section to readme.md
14+
15+
816
## [0.4.1] - 2024-01-02
917
- fix some typos
1018
- minor edits
1119

12-
1320
## [0.4.0] - 2023-12-06
1421
- refactor API, begin()
1522
- update readme.md

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,24 @@ is connected to:
6565
| SCL | 0x4B | |
6666

6767

68+
#### I2C multiplexing
69+
70+
Sometimes you need to control more devices than possible with the default
71+
address range the device provides.
72+
This is possible with an I2C multiplexer e.g. TCA9548 which creates up
73+
to eight channels (think of it as I2C subnets) which can use the complete
74+
address range of the device.
75+
76+
Drawback of using a multiplexer is that it takes more administration in
77+
your code e.g. which device is on which channel.
78+
This will slow down the access, which must be taken into account when
79+
deciding which devices are on which channel.
80+
Also note that switching between channels will slow down other devices
81+
too if they are behind the multiplexer.
82+
83+
- https://github.com/RobTillaart/TCA9548
84+
85+
6886
## Interface
6987

7088
```cpp
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// FILE: ADS1113_getMaxVoltage.ino
3+
// AUTHOR: Rob.Tillaart
4+
// PURPOSE: read analog inputs - straightforward.
5+
// URL: https://github.com/RobTillaart/ADS1X15
6+
7+
// test for issue #68 behaviour ADS1113 / ADS1013
8+
//
9+
// connect 1 potmeter per port.
10+
//
11+
// GND ---[ x ]------ 5V
12+
// |
13+
//
14+
// measure at x (connect to AIN0).
15+
16+
17+
#include "ADS1X15.h"
18+
19+
ADS1113 ADS(0x48);
20+
21+
22+
void setup()
23+
{
24+
Serial.begin(115200);
25+
Serial.println(__FILE__);
26+
Serial.print("ADS1X15_LIB_VERSION: ");
27+
Serial.println(ADS1X15_LIB_VERSION);
28+
29+
Wire.begin();
30+
ADS.begin();
31+
32+
for (int g = 0; g < 8; g++)
33+
{
34+
ADS.setGain(g);
35+
Serial.print(g);
36+
Serial.print('\t');
37+
Serial.print(ADS.getGain()); // should all print 2
38+
Serial.print('\t');
39+
Serial.println(ADS.getMaxVoltage(), 3); // should all print 2.048
40+
}
41+
}
42+
43+
44+
void loop()
45+
{
46+
}
47+
48+
49+
// -- END OF FILE --

keywords.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Syntax Colouring Map For ADS1X15
22

33
# Data types (KEYWORD1)
4-
ADS1X13 KEYWORD1
4+
ADS1X15 KEYWORD1
5+
ADS1013 KEYWORD1
56
ADS1014 KEYWORD1
67
ADS1015 KEYWORD1
78
ADS1015 KEYWORD1

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.4.1",
18+
"version": "0.4.2",
1919
"license": "MIT",
2020
"frameworks": "*",
2121
"platforms": "*",

0 commit comments

Comments
 (0)