@@ -59,26 +59,30 @@ and optional the Wire interface as parameter.
5959- ** ADS1115(address, TwoWire \* wire = &Wire)** Constructor with device address,
6060and optional the Wire interface as parameter.
6161
62- The function ** setWireClock(uint32_t speed)** is used to set the clock speed of the used
63- I2C interface.
62+ The function ** void setWireClock(uint32_t speed)** is used to set the clock speed
63+ of the used I2C interface.
6464
65- The function ** getWireClock()** is a prototype. It returns the value set by setWireClock().
66- This is not necessary the actual value. When no value is set ** getWireClock()** returns 0.
67- Need to implement a read / calculate from low level I2C code (e.g. TWBR on AVR).
65+ The function ** uint32_t getWireClock()** is a prototype.
66+ It returns the value set by setWireClock().
67+ This is not necessary the actual value.
68+ When no value is set ** getWireClock()** returns 0.
69+ Need to implement a read / calculate from low level I2C code (e.g. TWBR on AVR),
70+ better the Arduino Wire lib should support this call (ESP32 does).
6871
6972After construction the ** ADS.begin()** need to be called. This will return false
7073if an invalid address is used.
71- The function ** isConnected()** can be used to verify the reading of the ADS.
72- The function ** reset()** is sets the parameters to their initial value as
74+ The function ** bool isConnected()** can be used to verify the reading of the ADS.
75+ The function ** void reset()** is sets the parameters to their initial value as
7376in the constructor.
7477
7578
7679#### Programmable Gain
7780
78- - ** setGain(gain)** set the gain value, indicating the maxVoltage that can be measured
79- Adjusting the gain allows one to make more precise measurements.
81+ - ** void setGain(uint8_t gain)** set the gain value, indicating the maxVoltage that can be measured
82+ Adjusting the gain allows one to make more precise measurements.
83+ Note: the gain is not set in the device until an explicit read/request of the ADC (any read call will do).
8084See table below.
81- - ** getGain()** returns the gain value (index).
85+ - ** uint8_t getGain()** returns the gain value (index).
8286
8387| PGA value | Max Voltage | Notes |
8488| :---------:| :-----------:| :-------:|
@@ -89,8 +93,8 @@ See table below.
8993| 8 | ±0.512V | |
9094| 16 | ±0.256V | |
9195
92- - ** getMaxVoltage()** returns the max voltage with the current gain.
93- - ** toVoltage(raw = 1)** converts a raw measurement to a voltage.
96+ - ** float getMaxVoltage()** returns the max voltage with the current gain.
97+ - ** float toVoltage(int16_t raw = 1)** converts a raw measurement to a voltage.
9498Can be used for normal and differential measurements.
9599The default value of 1 returns the conversion factor for any raw number.
96100
@@ -108,16 +112,19 @@ Check the examples.
108112
109113The ADS sensor can operate in single shot or continuous mode.
110114Depending on how often one needs a conversion one can tune the mode.
111- - ** setMode(mode)** 0 = CONTINUOUS, 1 = SINGLE (default)
112- - ** getMode()** returns current mode 0 or 1, or ADS1X15_INVALID_MODE = 0xFE.
115+ - ** void setMode(uint8_t mode)** 0 = CONTINUOUS, 1 = SINGLE (default)
116+ Note: the mode is not set in the device until an explicit read/request of the ADC (any read call will do).
117+ - ** uint8_t getMode()** returns current mode 0 or 1, or ADS1X15_INVALID_MODE = 0xFE.
118+
113119
114120
115121#### Data rate
116122
117- - ** setDataRate(dataRate)** Data rate depends on type of device.
123+ - ** void setDataRate(uint8_t dataRate)** Data rate depends on type of device.
118124For all devices the index 0..7 can be used, see table below.
119125Values above 7 ==> will be set to the default 4.
120- - ** getDataRate()** returns the current data rate (index).
126+ Note: the data rate is not set in the device until an explicit read/request of the ADC (any read call will do).
127+ - ** uint8_t getDataRate()** returns the current data rate (index).
121128
122129The library has no means to convert this index to the actual numbers
123130as that would take 32 bytes.
@@ -144,10 +151,10 @@ all in one call. Under the hood it uses the asynchronous calls.
144151If the pin number is out of range, this function will return 0.
145152
146153To read the ADC in an asynchronous way (e.g. to minimize blocking) one has to use three calls:
147- - ** requestADC(pin)** Start the conversion. pin = 0..3.
148- - ** isBusy()** Is the conversion not ready?
149- - ** isReady()** Is the conversion ready? (= wrapper around ** isBusy()** )
150- - ** getValue()** Read the result of the conversion.
154+ - ** void requestADC(uint8_t pin)** Start the conversion. pin = 0..3.
155+ - ** bool isBusy()** Is the conversion not ready?
156+ - ** bool isReady()** Is the conversion ready? (= wrapper around ** isBusy()** )
157+ - ** int16_t getValue()** Read the result of the conversion.
151158
152159
153160in terms of code
@@ -176,33 +183,35 @@ See examples
176183## ReadADC Differential
177184
178185For reading the ADC in a differential way there are 4 calls possible.
179- - **readADC_Differential_0_1()** returns the difference between 2 ADC pins.
180- - **readADC_Differential_0_3()** ADS1x15 only
181- - **readADC_Differential_1_3()** ADS1x15 only
182- - **readADC_Differential_2_3()** ADS1x15 only
183- - **readADC_Differential_0_2()** ADS1x15 only - in software (no async equivalent)
184- - **readADC_Differential_1_2()** ADS1x15 only - in software (no async equivalent)
186+ - **int16_t readADC_Differential_0_1()** returns the difference between 2 ADC pins.
187+ - **int16_t readADC_Differential_0_3()** ADS1x15 only
188+ - **int16_t readADC_Differential_1_3()** ADS1x15 only
189+ - **int16_t readADC_Differential_2_3()** ADS1x15 only
190+ - **int16_t readADC_Differential_0_2()** ADS1x15 only - in software (no async equivalent)
191+ - **int16_t readADC_Differential_1_2()** ADS1x15 only - in software (no async equivalent)
185192
186193The differential reading of the ADC can also be done with asynchronous calls.
187- - **requestADC_Differential_0_1()** starts conversion for differential reading
188- - **requestADC_Differential_0_3()** ADS1x15 only
189- - **requestADC_Differential_1_3()** ADS1x15 only
190- - **requestADC_Differential_2_3()** ADS1x15 only
194+ - **int16_t requestADC_Differential_0_1()** starts conversion for differential reading
195+ - **int16_t requestADC_Differential_0_3()** ADS1x15 only
196+ - **int16_t requestADC_Differential_1_3()** ADS1x15 only
197+ - **int16_t requestADC_Differential_2_3()** ADS1x15 only
191198
192199After one of these calls one need to call
193- - **isBusy()** Is the conversion ready?
194- - **getValue()** Read the result of the conversion.
200+ - **bool isBusy()** Is the conversion ready?
201+ - **int16_t getValue()** Read the result of the last conversion.
195202
196203
197204#### ReadADC continuous mode
198205
199206To use the continuous mode one need three calls
200- - **setMode(0)** 0 = CONTINUOUS, 1 = SINGLE (default)
201- - **readADC()** or **requestADC()** to get the continuous mode started.
202- - **getValue()** to return the last value read by the device.
207+ - **void setMode(0)** 0 = CONTINUOUS, 1 = SINGLE (default).
208+ Note: the mode is not set in the device until an explicit read/request of the ADC (any read call will do).
209+ - **int16_t readADC(uint8_t pin)** or **void requestADC(uint8_t pin)** to get the continuous mode started.
210+ - **int16_t getValue()** to return the last value read by the device.
211+ Note this can be a different pin, so be warned.
203212Calling this over and over again can give the same value multiple times.
204213
205- By using **isBusy()** or **isReady()** one can wait until new data is available.
214+ By using **bool isBusy()** or **bool isReady()** one can wait until new data is available.
206215Or one can use the **ALERT/RDY** pin to trigger via hardware the readiness of the conversion.
207216
208217See examples.
@@ -212,17 +221,22 @@ See examples.
212221
213222If the thresholdHigh is set to 0x0100 and the thresholdLow to 0x0000
214223the **ALERT/RDY** pin is triggered when a conversion is ready.
215- - **setComparatorThresholdLow(0x0000)**
216- - **setComparatorThresholdHigh(0x0100)**
224+ - **void setComparatorThresholdLow(int16_t lo)** writes value to device directly.
225+ - **void setComparatorThresholdHigh(int16_t hi)** writes value to device directly.
226+ - **int16_t getComparatorThresholdLow()** reads value from device.
227+ - **int16_t getComparatorThresholdHigh()** reads value from device.
217228
218229See examples.
219230
220231
221232## Comparator
222233
223- Please read Page 15 of the datasheet as the behavior of the
234+ Please read Page 15 of the datasheet as the behaviour of the
224235comparator is not trivial.
225236
237+ NOTE: all comparator settings are copied to the device only after an explicit
238+ **readADC()** or **requestADC()**
239+
226240
227241#### Comparator Mode
228242
@@ -231,6 +245,10 @@ When configured as a **TRADITIONAL** comparator, the **ALERT/RDY** pin asserts
231245high threshold register. The comparator then de-asserts when the input
232246signal falls below the low threshold register value.
233247
248+ - **void setComparatorMode(uint8_t mode)** value 0 = TRADITIONAL 1 = WINDOW,
249+ - **uint8_t getComparatorMode()**
250+
251+
234252If the comparator **LATCH** is set, the **ALERT/RDY** pin asserts and it will be
235253reset after reading the sensor (conversion register) again.
236254*An SMB alert command (00011001) on the I2C bus will also reset the alert state.*
@@ -245,20 +263,30 @@ In this mode the alert is held if the **LATCH** is set. This is similar as above
245263
246264Default state of the **ALERT/RDY** pin is **LOW**, can be to set **HIGH**.
247265
266+ - **void setComparatorPolarity(uint8_t pol)**
267+ Flag is only explicitly set after a **readADC()** or a **requestADC()**
268+ - **uint8_t getComparatorPolarity()** returns value set.
269+
248270
249271#### Latch
250272
251273Holds the **ALERT/RDY** to **HIGH** (or **LOW** depending on polarity) after triggered
252274even if actual value has been 'restored to normal' value.
253275
276+ - **void setComparatorLatch(uint8_t latch)** 0 = NO LATCH, not 0 = LATCH
277+ - **uint8_t getComparatorLatch()** returns value set.
278+
254279
255280#### QueConvert
256281
257282Set the number of conversions before trigger activates.
258- The **setComparatorQueConvert(uint8_t mode)** is used to set the number of
283+ The **void setComparatorQueConvert(uint8_t mode)** is used to set the number of
259284conversions that exceed the threshold before the **ALERT/RDY** pin is set **HIGH**.
260285A value of 3 (or above) effectively disables the comparator. See table below.
261286
287+ - **void setComparatorQueConvert(uint8_t mode)** See table below.
288+ - **uint8_t getComparatorQueConvert()** returns value set.
289+
262290| value | meaning | Notes |
263291|:-----:|:----------------------------------|:--------|
264292| 0 | trigger alert after 1 conversion | |
@@ -271,19 +299,17 @@ A value of 3 (or above) effectively disables the comparator. See table below.
271299
272300Depending on the comparator mode **TRADITIONAL** or **WINDOW** the thresholds registers
273301mean something different see - Comparator Mode above or datasheet.
274- - **setComparatorThresholdLow(lo)** set the low threshold; take care the hi >= lo
275- - **setComparatorThresholdHigh(hi)** set the high threshold; take care the hi >= lo
276- - **getComparatorThresholdLow()** returns set value
277- - **getComparatorThresholdHigh()** returns set value
302+ - **void setComparatorThresholdLow(int16_t lo)** set the low threshold; take care the hi >= lo.
303+ - **void setComparatorThresholdHigh(int16_t hi)** set the high threshold; take care the hi >= lo.
304+ - **int16_t getComparatorThresholdLow()** reads value from device.
305+ - **int16_t getComparatorThresholdHigh()** reads value from device.
278306
279307
280308## Future ideas & improvements
281309
282310- Improve documentation
283- - more examples?
311+ - More examples ?
284312- SMB alert command (00011001) on I2C bus?
285- - implement missing Differential reads in software.
286- - testing....
287313
288314
289315## Operation
0 commit comments