diff options
author | Wolfgang (Wolle) Ewald <wolfgang.ewald@wolles-elektronikkiste.de> | 2020-06-27 13:18:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-27 13:18:25 +0200 |
commit | 3e985fecc3c0472991300542ae4740aba17a4c42 (patch) | |
tree | bd14d4f98587a1196a62d4cae41cd60e2dfa7658 /examples/Single_Shot_Conv_Ready_Alert_Controlled | |
parent | Delete dummy (diff) | |
download | ADS1115_WE-3e985fecc3c0472991300542ae4740aba17a4c42.tar ADS1115_WE-3e985fecc3c0472991300542ae4740aba17a4c42.tar.gz ADS1115_WE-3e985fecc3c0472991300542ae4740aba17a4c42.tar.bz2 ADS1115_WE-3e985fecc3c0472991300542ae4740aba17a4c42.tar.lz ADS1115_WE-3e985fecc3c0472991300542ae4740aba17a4c42.tar.xz ADS1115_WE-3e985fecc3c0472991300542ae4740aba17a4c42.tar.zst ADS1115_WE-3e985fecc3c0472991300542ae4740aba17a4c42.zip |
Diffstat (limited to 'examples/Single_Shot_Conv_Ready_Alert_Controlled')
-rw-r--r-- | examples/Single_Shot_Conv_Ready_Alert_Controlled/Single_Shot_Conv_Ready_Alert_Controlled.ino | 149 |
1 files changed, 148 insertions, 1 deletions
diff --git a/examples/Single_Shot_Conv_Ready_Alert_Controlled/Single_Shot_Conv_Ready_Alert_Controlled.ino b/examples/Single_Shot_Conv_Ready_Alert_Controlled/Single_Shot_Conv_Ready_Alert_Controlled.ino index 8b13789..27d24e7 100644 --- a/examples/Single_Shot_Conv_Ready_Alert_Controlled/Single_Shot_Conv_Ready_Alert_Controlled.ino +++ b/examples/Single_Shot_Conv_Ready_Alert_Controlled/Single_Shot_Conv_Ready_Alert_Controlled.ino @@ -1 +1,148 @@ - +/***************************************************************************
+* Example sketch for the ADS1115_WE library
+*
+* This sketch shows how you can use the alert pin as conversion ready alert pin.
+* Please note that you need to enable the alert pin with setAlertPinMode. Choose any
+* parameter except ADS1115_DISABLE_ALERT.
+*
+* Further information can be found on:
+* https://wolles-elektronikkiste.de/ads1115
+*
+***************************************************************************/
+
+#include<ADS1115_WE.h>
+#include<Wire.h>
+#define I2C_ADDRESS 0x48
+int interruptPin = 2;
+volatile bool convReady = false;
+
+ADS1115_WE adc(I2C_ADDRESS);
+// ADS1115_WE adc = ADS1115_WE(); // Alternative: sets default address 0x48
+
+void setup() {
+ Wire.begin();
+ Serial.begin(9600);
+ pinMode(interruptPin, INPUT_PULLUP);
+ if(!adc.init()){
+ Serial.println("ADS1115 not connected!");
+ }
+
+ /* Set the voltage range of the ADC to adjust the gain
+ * Please note that you must not apply more than VDD + 0.3V to the input pins!
+ *
+ * ADS1115_RANGE_6144 -> +/- 6144 mV
+ * ADS1115_RANGE_4096 -> +/- 4096 mV
+ * ADS1115_RANGE_2048 -> +/- 2048 mV (default)
+ * ADS1115_RANGE_1024 -> +/- 1024 mV
+ * ADS1115_RANGE_0512 -> +/- 512 mV
+ * ADS1115_RANGE_0256 -> +/- 256 mV
+ */
+ adc.setVoltageRange_mV(ADS1115_RANGE_6144); //comment line/change paramater to change range
+
+ /* Set the inputs to be compared
+ *
+ * ADS1115_COMP_0_1 -> compares 0 with 1 (default)
+ * ADS1115_COMP_0_3 -> compares 0 with 3
+ * ADS1115_COMP_1_3 -> compares 1 with 3
+ * ADS1115_COMP_2_3 -> compares 2 with 3
+ * ADS1115_COMP_0_GND -> compares 0 with GND
+ * ADS1115_COMP_1_GND -> compares 1 with GND
+ * ADS1115_COMP_2_GND -> compares 2 with GND
+ * ADS1115_COMP_3_GND -> compares 3 with GND
+ */
+ adc.setCompareChannels(ADS1115_COMP_0_GND); //comment line/change paramater to change channels
+
+ /* Set number of conversions out of limit after which the alert pin will be active
+ * - or you can disable the alert (including conversion ready alert)
+ *
+ * ADS1115_ASSERT_AFTER_1 -> after 1 conversion
+ * ADS1115_ASSERT_AFTER_2 -> after 2 conversions
+ * ADS1115_ASSERT_AFTER_3 -> after 3 conversions
+ * ADS1115_DISABLE_ALERT -> disable comparator / alert pin (default)
+ */
+ adc.setAlertPinMode(ADS1115_ASSERT_AFTER_1); //needed in this sketch to enable alert pin (doesn't matter if you choose after 1,2 or 3)
+
+ /* Set the conversion rate in SPS (samples per second)
+ * Options should be self-explaining:
+ *
+ * ADS1115_8_SPS
+ * ADS1115_16_SPS
+ * ADS1115_32_SPS
+ * ADS1115_64_SPS
+ * ADS1115_128_SPS (default)
+ * ADS1115_250_SPS
+ * ADS1115_475_SPS
+ * ADS1115_860_SPS
+ */
+ adc.setConvRate(ADS1115_8_SPS); //comment line/change paramater to change SPS
+
+ /* Set continous or single shot mode:
+ *
+ * ADS1115_CONTINOUS -> continous mode
+ * ADS1115_SINGLE -> single shot mode (default)
+ */
+ //adc.setMeasureMode(ADS1115_CONTINOUS); // continous mode does not work with conversion ready
+
+ /* Choose maximum limit or maxium and minimum alert limit (window)in Volt - alert pin will
+ * be active when measured values are beyond the maximum limit or outside the window
+ * Upper limit first: setAlertLimit_V(MODE, maximum, minimum)
+ * In max limit mode the minimum value is the limit where the alert pin will be deactivated (if
+ * not latched)
+ *
+ * ADS1115_MAX_LIMIT
+ * ADS1115_WINDOW
+ *
+ */
+ //adc.setAlertModeAndLimit_V(ADS1115_MAX_LIMIT, 3.0, 1.5); //uncomment if you want to change the default
+
+ /* Enable or disable latch. If latch is enabled the alarm pin will be active until the
+ * conversion register is read (getResult functions). If disabled the alarm pin will be
+ * deactivated with next value within limits.
+ *
+ * ADS1115_LATCH_DISABLED (default)
+ * ADS1115_LATCH_ENABLED
+ */
+ //adc.setAlertLatch(ADS1115_LATCH_ENABLED); //uncomment if you want to change the default
+
+ /* Sets the alert pin polarity if active:
+ *
+ * /* Enable or disable latch. If latch is enabled the alarm pin will be active until the
+ * conversion register is read (getResult functions). If disabled the alarm pin will be
+ * deactivated with next value within limits.
+ *
+ * ADS1115_ACT_LOW -> active low (default)
+ * ADS1115_ACT_HIGH -> active high
+ */
+ //adc.setAlertPol(ADS1115_ACT_LOW); //uncomment if you want to change the default
+
+ /* With this function the alert pin will be active, when a conversion is ready.
+ * In order to deactivate, use the setAlertLimit_V function
+ */
+ adc.setAlertPinToConversionReady(); //needed for this sketch
+
+ Serial.println("ADS1115 Example Sketch - Single Shot, Conversion Ready Alert controlled");
+ Serial.println();
+ attachInterrupt(digitalPinToInterrupt(interruptPin), convReadyAlert, FALLING);
+ adc.startSingleMeasurement();
+}
+
+void loop() {
+ float voltage = 0.0;
+ static int counter = 0;
+ if(convReady){
+ counter++;
+ convReady = false;
+ if(counter==32){ // counter is 32, conversion rate is 8 SPS --> 4s
+ voltage = adc.getResult_V(); // alternative: getResult_mV for Millivolt
+ Serial.print("Channel 0 vs GND [V]: ");
+ Serial.println(voltage);
+ Serial.println("-------------------------------");
+ counter = 0;
+ }
+ adc.startSingleMeasurement();
+ }
+}
+
+void convReadyAlert(){
+ convReady = true;
+}
|