summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWolfgang (Wolle) Ewald <wolfgang.ewald@wolles-elektronikkiste.de>2020-08-08 11:38:20 +0200
committerGitHub <noreply@github.com>2020-08-08 11:38:20 +0200
commit1f26c3979751e7ad0285d0c4f5811ec184907597 (patch)
tree98b6ca319e96f30b0f5ef9143685802aedbe1b5e /src
parentAdd files via upload (diff)
downloadADS1115_WE-1f26c3979751e7ad0285d0c4f5811ec184907597.tar
ADS1115_WE-1f26c3979751e7ad0285d0c4f5811ec184907597.tar.gz
ADS1115_WE-1f26c3979751e7ad0285d0c4f5811ec184907597.tar.bz2
ADS1115_WE-1f26c3979751e7ad0285d0c4f5811ec184907597.tar.lz
ADS1115_WE-1f26c3979751e7ad0285d0c4f5811ec184907597.tar.xz
ADS1115_WE-1f26c3979751e7ad0285d0c4f5811ec184907597.tar.zst
ADS1115_WE-1f26c3979751e7ad0285d0c4f5811ec184907597.zip
Diffstat (limited to '')
-rw-r--r--src/ADS1115_WE.cpp19
-rw-r--r--src/ADS1115_WE.h31
2 files changed, 47 insertions, 3 deletions
diff --git a/src/ADS1115_WE.cpp b/src/ADS1115_WE.cpp
index 9da6d48..6ccd3f4 100644
--- a/src/ADS1115_WE.cpp
+++ b/src/ADS1115_WE.cpp
@@ -163,14 +163,29 @@ float ADS1115_WE::getResult_mV(){
return result;
}
+int16_t ADS1115_WE::getRawResult(){
+ int16_t rawResult = readRegister(ADS1115_CONV_REG);
+ return rawResult;
+}
+
int16_t ADS1115_WE::getResultWithRange(int16_t min, int16_t max){
int16_t rawResult = readRegister(ADS1115_CONV_REG);
- //rawResult = (int) (rawResult * (voltageRange * 1.0 / 6144));
int16_t result = 0;
- result = map(rawResult, 0, 32767, min, max);
+ result = map(rawResult, -32767, 32767, min, max);
return result;
}
+int16_t ADS1115_WE::getResultWithRange(int16_t min, int16_t max, int16_t maxMillivolt){
+ int16_t rawResult = readRegister(ADS1115_CONV_REG);
+ int16_t result = 0;
+ result = map(rawResult, -32767, 32767, min, max);
+ result = (int16_t) (1.0 * result * voltageRange / maxMillivolt);
+ return result;
+}
+
+uint16_t ADS1115_WE::getVoltageRange_mV(){
+ return voltageRange;
+}
void ADS1115_WE::setAlertPinToConversionReady(){
writeRegister(ADS1115_LO_THRESH_REG, (0<<15));
diff --git a/src/ADS1115_WE.h b/src/ADS1115_WE.h
index ce0cec2..888ef00 100644
--- a/src/ADS1115_WE.h
+++ b/src/ADS1115_WE.h
@@ -202,8 +202,37 @@ public:
void startSingleMeasurement();
float getResult_V();
float getResult_mV();
+
+ /* Get the raw result from the conversion register:
+ * The conversion register contains the conversion result of the amplified (!)
+ * voltage. This means the value depends on the voltage as well as on the
+ * voltage range. E.g. if the voltage range is 6.144 mV (ADS1115_RANGE_6144),
+ * +32767 is 6.144 mV; if the range is 4.096 mV, +32767 is 4.096 mV, and so on.
+ */
+ int16_t getRawResult();
+
+ /* Skaling of the result to a different range:
+ * The results in the conversion register are in a range of -32767 to +32767
+ * You might want to receive the result in a different scale, e.g. -1023 to 1023.
+ * For -1023 to 1023, and if you have chosen e.g. ADS1115_RANGE_4096, 0 Volt would
+ * give 0 as result and 4.096 mV would give 1023. -4.096 mV would give -1023.
+ */
int16_t getResultWithRange(int16_t min, int16_t max);
-
+
+ /* Scaling of the result to a different range plus scaling to a voltage range:
+ * You can use this variant if you also want to scale to a voltage range. E.g. in
+ * in order to get results equivalent to an Arduino UNO (10 bit, 5000 mV range), you
+ * would choose getResultWithRange(-1023, 1023, 5000). A difference to the Arduino
+ * UNO is that you can measure negative voltages.
+ * You have to ensure that the voltage range you scale to is smaller than the
+ * measuring voltage range. For this example only ADS1115_RANGE_6144 would cover the
+ * scale up to 5000 mV.
+ */
+ int16_t getResultWithRange(int16_t min, int16_t max, int16_t maxVoltage);
+
+ /* This function returns the voltage range ADS1115_RANGE_XXXX in Millivolt */
+ uint16_t getVoltageRange_mV();
+
/* With this function the alert pin will be active, when a conversion is ready.
* In order to deactivate, use the setAlertLimit_V function
*/