Skip to content

Commit e30ffcd

Browse files
committed
0.3.9 ADS1X15 + update examples
1 parent c01e6f0 commit e30ffcd

File tree

25 files changed

+251
-60
lines changed

25 files changed

+251
-60
lines changed

libraries/ADS1x15/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ 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+
- update and add examples
9+
10+
811
## [0.3.9] - 2023-01-21
912
- update GitHub actions
1013
- update license 2023

libraries/ADS1x15/README.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ is connected to:
4646

4747
## Interface
4848

49-
### Initializing
49+
```cpp
50+
#include "ADS1X15.h"
51+
```
52+
53+
#### Initializing
5054

5155
To initialize the library you must call constructor as described below.
5256

@@ -87,7 +91,7 @@ void begin() {
8791
```
8892
8993
90-
### I2C clock speed
94+
#### I2C clock speed
9195
9296
The function **void setWireClock(uint32_t speed = 100000)** is used to set the clock speed
9397
in Hz of the used I2C interface. typical value is 100 KHz.
@@ -104,7 +108,7 @@ See - https://github.com/arduino/Arduino/issues/11457
104108
Question: should this functionality be in this library?
105109
106110
107-
### Programmable Gain
111+
#### Programmable Gain
108112
109113
- **void setGain(uint8_t gain)** set the gain value, indicating the maxVoltage that can be measured
110114
Adjusting the gain allowing to make more precise measurements.
@@ -138,7 +142,7 @@ Check the [examples](https://github.com/RobTillaart/ADS1X15/blob/master/examples
138142
```
139143

140144

141-
### Operational mode
145+
#### Operational mode
142146

143147
The ADS sensor can operate in single shot or continuous mode.
144148
Depending on how often conversions needed you can tune the mode.
@@ -147,7 +151,7 @@ Note: the mode is not set in the device until an explicit read/request of the AD
147151
- **uint8_t getMode()** returns current mode 0 or 1, or ADS1X15_INVALID_MODE = 0xFE.
148152

149153

150-
### Data rate
154+
#### Data rate
151155

152156
- **void setDataRate(uint8_t dataRate)** Data rate depends on type of device.
153157
For all devices the index 0..7 can be used, see table below.
@@ -172,7 +176,7 @@ Data rate in samples per second, based on datasheet is described on table below.
172176
| 7 | 3300 | 860 | fastest |
173177

174178

175-
### ReadADC Single mode
179+
#### ReadADC Single mode
176180

177181
Reading the ADC is very straightforward, the **readADC()** function handles all in one call.
178182
Under the hood it uses the asynchronous calls.
@@ -221,7 +225,7 @@ in terms of code
221225
See [examples](https://github.com/RobTillaart/ADS1X15/blob/master/examples/ADS_read_async/ADS_read_async.ino).
222226
223227
224-
## ReadADC Differential
228+
#### ReadADC Differential
225229
226230
For reading the ADC in a differential way there are 4 calls possible.
227231
@@ -250,7 +254,7 @@ After one of these calls you need to call
250254
See [examples](https://github.com/RobTillaart/ADS1X15/blob/master/examples/ADS_differential/ADS_differential.ino).
251255

252256

253-
### ReadADC continuous mode
257+
#### ReadADC continuous mode
254258

255259
To use the continuous mode you need call three functions:
256260
- **void setMode(0)** 0 = CONTINUOUS, 1 = SINGLE (default).
@@ -283,7 +287,7 @@ Instead you can configure the threshold registers to allow the **ALERT/RDY**
283287
pin to trigger an interrupt signal when conversion data ready.
284288

285289

286-
### Threshold registers
290+
#### Threshold registers
287291

288292
If the thresholdHigh is set to 0x0100 and the thresholdLow to 0x0000
289293
the **ALERT/RDY** pin is triggered when a conversion is ready.
@@ -296,7 +300,7 @@ the **ALERT/RDY** pin is triggered when a conversion is ready.
296300
See [examples](https://github.com/RobTillaart/ADS1X15/blob/master/examples/ADS_read_RDY/ADS_read_RDY.ino).
297301

298302

299-
## Comparator
303+
#### Comparator
300304

301305
Please read Page 15 of the datasheet as the behaviour of the
302306
comparator is not trivial.
@@ -305,7 +309,7 @@ NOTE: all comparator settings are copied to the device only after calling
305309
**readADC()** or **requestADC()** functions.
306310

307311

308-
### Comparator Mode
312+
#### Comparator Mode
309313

310314
When configured as a **TRADITIONAL** comparator, the **ALERT/RDY** pin asserts
311315
(active low by default) when conversion data exceed the limit set in the
@@ -326,7 +330,7 @@ the high threshold register or falls below the low threshold register.
326330
In this mode the alert is held if the **LATCH** is set. This is similar as above.
327331

328332

329-
### Polarity
333+
#### Polarity
330334

331335
Default state of the **ALERT/RDY** pin is **LOW**, can be to set **HIGH**.
332336

@@ -335,7 +339,7 @@ Flag is only explicitly set after a **readADC()** or a **requestADC()**
335339
- **uint8_t getComparatorPolarity()** returns value set.
336340

337341

338-
### Latch
342+
#### Latch
339343

340344
Holds the **ALERT/RDY** to **HIGH** (or **LOW** depending on polarity) after triggered
341345
even if actual value has been 'restored to normal' value.
@@ -344,7 +348,7 @@ even if actual value has been 'restored to normal' value.
344348
- **uint8_t getComparatorLatch()** returns value set.
345349

346350

347-
### QueConvert
351+
#### QueConvert
348352

349353
Set the number of conversions before trigger activates.
350354
The **void setComparatorQueConvert(uint8_t mode)** is used to set the number of
@@ -362,7 +366,7 @@ A value of 3 (or above) effectively disables the comparator. See table below.
362366
| 3 | Disable comparator | default |
363367

364368

365-
### Threshold registers comparator mode
369+
#### Threshold registers comparator mode
366370

367371
Depending on the comparator mode **TRADITIONAL** or **WINDOW** the thresholds registers
368372
mean something different see - Comparator Mode above or datasheet.
@@ -373,7 +377,7 @@ mean something different see - Comparator Mode above or datasheet.
373377
- **int16_t getComparatorThresholdHigh()** reads value from device.
374378

375379

376-
### RP2040 specific
380+
## RP2040 specific
377381

378382
- **bool begin(int sda, int scl)** begin communication with the ADC.
379383
It has the parameter for selecting on which pins the communication should happen.

libraries/ADS1x15/examples/ADS_1114_four/ADS_1114_four.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void setup()
3636
Serial.print(" ");
3737
Serial.println(ADS[i].begin() ? "connected" : "not connected");
3838

39-
ADS[i].setDataRate(4); // 7 is fastest, but more noise
39+
ADS[i].setDataRate(4); // 0 = slow 4 = medium 7 = fast, but more noise
4040
}
4141
ADS_request_all();
4242
}

libraries/ADS1x15/examples/ADS_1114_two_continuous/ADS_1114_two_continuous.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void setup()
3131
// SETUP FIRST ADS1114
3232
ADS_1.begin();
3333
ADS_1.setGain(0); // 0 == 6.144 volt, default
34-
ADS_1.setDataRate(7); // 7 == highest
34+
ADS_1.setDataRate(7); // 0 = slow 4 = medium 7 = fast
3535

3636
// SET ALERT RDY PIN
3737
ADS_1.setComparatorThresholdHigh(0x8000);

libraries/ADS1x15/examples/ADS_RP2040_WIRE1/ADS_RP2040_WIRE1.ino

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
//
22
// FILE: ADS_RP2040_WIRE1.ino
33
// AUTHOR: Rob.Tillaart / Intubun
4-
// VERSION: 0.1.1
54
// PURPOSE: read analog input
6-
//
5+
// URL: https://github.com/RobTillaart/ADS1X15
76

87
// test
98
// connect 1 potmeter
@@ -35,7 +34,7 @@ void setup()
3534

3635
ADS.begin(26, 27); // SDA (Pin 26), SCL(Pin 27)
3736
ADS.setGain(0); // 6.144 volt
38-
ADS.setDataRate(7); // fast
37+
ADS.setDataRate(7); // 0 = slow 4 = medium 7 = fast
3938
ADS.setMode(0); // continuous mode
4039
ADS.readADC(0); // first read to trigger
4140
}

libraries/ADS1x15/examples/ADS_async_16_channel/ADS_async_16_channel.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void setup()
3939
Serial.print(" ");
4040
Serial.println(ADS[i].begin() ? "connected" : "not connected");
4141

42-
ADS[i].setDataRate(4); // 7 is fastest, but more noise
42+
ADS[i].setDataRate(4); // 0 = slow 4 = medium 7 = fast, but more noise
4343
}
4444
ADS_request_all();
4545
}

libraries/ADS1x15/examples/ADS_async_8_channel/ADS_async_8_channel.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void setup()
4646
// Serial.println(ADS2.isConnected());
4747
// Serial.println(ADS3.isConnected());
4848

49-
ADS0.setDataRate(4); // 7 is fastest, but more noise
49+
ADS0.setDataRate(4); // 0 = slow 4 = medium 7 = fast but more noise
5050
ADS1.setDataRate(4);
5151
// ADS2.setDataRate(4);
5252
// ADS3.setDataRate(4);

libraries/ADS1x15/examples/ADS_async_differential/ADS_async_differential.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// AUTHOR: Rob.Tillaart
44
// VERSION: 0.1.0
55
// PURPOSE: read multiple differential continuously
6-
//
6+
// URL: https://github.com/RobTillaart/ADS1X15
77

88
// test
99
// connect 4 potmeters
@@ -42,7 +42,7 @@ void setup()
4242

4343
ADS.begin();
4444
ADS.setGain(0); // 6.144 volt
45-
ADS.setDataRate(4); // medium
45+
ADS.setDataRate(4); // 0 = slow 4 = medium 7 = fast
4646

4747
// single shot mode
4848
ADS.setMode(1);

libraries/ADS1x15/examples/ADS_continuous/ADS_continuous.ino

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
//
22
// FILE: ADS_continuous.ino
33
// AUTHOR: Rob.Tillaart
4-
// VERSION: 0.1.1
54
// PURPOSE: read analog input
6-
//
5+
// URL: https://github.com/RobTillaart/ADS1X15
76

87
// test
98
// connect 1 potmeter
@@ -35,7 +34,7 @@ void setup()
3534

3635
ADS.begin();
3736
ADS.setGain(0); // 6.144 volt
38-
ADS.setDataRate(7); // fast
37+
ADS.setDataRate(7); // 0 = slow 4 = medium 7 = fast
3938
ADS.setMode(0); // continuous mode
4039
ADS.readADC(0); // first read to trigger
4140
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
//
2+
// FILE: ADS_continuous_3_channel.ino
3+
// AUTHOR: Rob.Tillaart
4+
// PURPOSE: read multiple analog inputs continuously
5+
// interrupt driven to catch all conversions.
6+
// URL: https://github.com/RobTillaart/ADS1X15
7+
// https://github.com/RobTillaart/ADS1X15/issues/49
8+
//
9+
// experimental, not tested extensively
10+
11+
// test
12+
// connect multiple potmeters
13+
//
14+
// RDY ----------------- pin 2 (for IRQ)
15+
//
16+
// GND ---[ x ]------ 5V
17+
// |
18+
// |
19+
// ADS(n)
20+
//
21+
// measure at x - connect to AIN0..3.
22+
//
23+
// for the test it is an option to have AIN3 connected to 5V and AIN4 to GND
24+
// so one can see these as references in the output.
25+
//
26+
// has an issue with the index of the channels. not not investigated yet.
27+
28+
29+
#include "ADS1X15.h"
30+
31+
32+
// choose your sensor
33+
// ADS1013 ADS(0x48);
34+
// ADS1014 ADS(0x48);
35+
// ADS1015 ADS(0x48);
36+
// ADS1113 ADS(0x48);
37+
// ADS1114 ADS(0x48);
38+
ADS1115 ADS(0x48);
39+
40+
volatile bool RDY = false;
41+
uint8_t channel = 0;
42+
int16_t val[4] = { 0, 0, 0, 0 };
43+
44+
int SPS = 0;
45+
uint32_t lastTime = 0;
46+
47+
48+
void setup()
49+
{
50+
Serial.begin(230400); // <<<<<<<<< fast!
51+
Serial.println(__FILE__);
52+
Serial.print("ADS1X15_LIB_VERSION: ");
53+
Serial.println(ADS1X15_LIB_VERSION);
54+
55+
Wire.setClock(400000);
56+
57+
ADS.begin();
58+
ADS.setGain(0); // 6.144 volt
59+
ADS.setDataRate(7); // 0 = slow 4 = medium 7 = fast
60+
61+
// SET ALERT RDY PIN
62+
ADS.setComparatorThresholdHigh(0x8000);
63+
ADS.setComparatorThresholdLow(0x0000);
64+
ADS.setComparatorQueConvert(0);
65+
66+
// SET INTERRUPT HANDLER TO CATCH CONVERSION READY
67+
pinMode(2, INPUT_PULLUP);
68+
attachInterrupt(digitalPinToInterrupt(2), adsReady, RISING);
69+
70+
ADS.setMode(0); // continuous mode
71+
channel = 0;
72+
ADS.requestADC(channel); // start at 0
73+
}
74+
75+
76+
void loop()
77+
{
78+
// if conversion ready
79+
// request a new one and print the last one.
80+
if (RDY)
81+
{
82+
SPS++;
83+
val[channel] = ADS.getValue();
84+
// request next channel asap
85+
channel++;
86+
if (channel >= 3) channel = 0;
87+
ADS.requestADC(channel);
88+
RDY = false;
89+
90+
// to see it works
91+
if (SPS % 200 == 0)
92+
{
93+
for (int i = 0; i < 4; i++)
94+
{
95+
Serial.print('\t');
96+
Serial.print(val[i]);
97+
}
98+
Serial.println();
99+
}
100+
}
101+
102+
103+
// print the SPS
104+
if (millis() - lastTime >= 1000)
105+
{
106+
lastTime = millis();
107+
Serial.print("SPS: ");
108+
Serial.println(SPS);
109+
SPS = 0;
110+
}
111+
}
112+
113+
114+
// interrupt service routine
115+
// kept as minimal as possible
116+
void adsReady()
117+
{
118+
RDY = true;
119+
}
120+
121+
// -- END OF FILE --

0 commit comments

Comments
 (0)