diff --git a/examples/menu_a_la_carte/menu_a_la_carte.ino b/examples/menu_a_la_carte/menu_a_la_carte.ino index c8c82571d..7081753e0 100644 --- a/examples/menu_a_la_carte/menu_a_la_carte.ino +++ b/examples/menu_a_la_carte/menu_a_la_carte.ino @@ -824,11 +824,12 @@ Variable* ds3231Temp = // NOTE: Use -1 for any pins that don't apply or aren't being used. const int8_t AlphasenseCO2Power = sensorPowerPin; // Power pin +aco2_adsDiffMux_t AlphasenseDiffMux = DIFF_MUX_2_3; // Differential voltage config const uint8_t AlphasenseCO2ADSi2c_addr = 0x48; // The I2C address of the ADS1115 ADC // Create an Alphasense CO2 sensor object -AlphasenseCO2 alphasenseCO2(AlphasenseCO2Power, AlphasenseCO2ADSi2c_addr); +AlphasenseCO2 alphasenseCO2(AlphasenseCO2Power, AlphasenseDiffMux,AlphasenseCO2ADSi2c_addr); // Create PAR and raw voltage variable pointers for the CO2 Variable* asCO2 = new AlphasenseCO2_CO2(&alphasenseCO2, diff --git a/src/sensors/AlphasenseCO2.cpp b/src/sensors/AlphasenseCO2.cpp index 908a8c04d..db3bebff0 100644 --- a/src/sensors/AlphasenseCO2.cpp +++ b/src/sensors/AlphasenseCO2.cpp @@ -18,13 +18,14 @@ // The constructor - need the power pin and the data pin -AlphasenseCO2::AlphasenseCO2(int8_t powerPin, uint8_t i2cAddress, - uint8_t measurementsToAverage) +AlphasenseCO2::AlphasenseCO2(int8_t powerPin, aco2_adsDiffMux_t adsDiffMux, + uint8_t i2cAddress, uint8_t measurementsToAverage) : Sensor("AlphasenseCO2", ALPHASENSE_CO2_NUM_VARIABLES, ALPHASENSE_CO2_WARM_UP_TIME_MS, ALPHASENSE_CO2_STABILIZATION_TIME_MS, ALPHASENSE_CO2_MEASUREMENT_TIME_MS, powerPin, -1, measurementsToAverage, ALPHASENSE_CO2_INC_CALC_VARIABLES), + _adsDiffMux(adsDiffMux), _i2cAddress(i2cAddress) {} // Destructor @@ -82,9 +83,7 @@ bool AlphasenseCO2::addSingleMeasurementResult(void) { // Read Analog to Digital Converter (ADC) // Taking this reading includes the 8ms conversion delay. - // We're allowing the ADS1115 library to do the bit-to-volts conversion - // for us - // Measure the voltage difference across two pins from the CO2 sensor + // Measure the voltage differential across the two voltage pins adcCounts = ads.readADC_Differential_2_3(); // Convert ADC counts value to voltage (V) adcVoltage = ads.computeVolts(adcCounts); diff --git a/src/sensors/AlphasenseCO2.h b/src/sensors/AlphasenseCO2.h index 2ce0d4d80..e92663733 100644 --- a/src/sensors/AlphasenseCO2.h +++ b/src/sensors/AlphasenseCO2.h @@ -117,8 +117,16 @@ */ #define ALPHASENSE_CO2_CALIBRATION_FACTOR 1 #endif - -/// The assumed address of the ADS1115, 1001 000 (ADDR = GND) +/** + * @brief Enum for the pins used for differential voltages. + */ +typedef enum : uint16_t { + DIFF_MUX_0_1, ///< differential across pins 0 and 1 + DIFF_MUX_0_3, ///< differential across pins 0 and 3 + DIFF_MUX_1_3, ///< differential across pins 1 and 3 + DIFF_MUX_2_3 ///< differential across pins 2 and 3 +} aco2_adsDiffMux_t; +/// @brief The assumed address of the ADS1115, 1001 000 (ADDR = GND) #define ADS1115_ADDRESS 0x48 /**@}*/ @@ -165,20 +173,10 @@ * {{ @ref AlphasenseCO2_CO2 }} */ /**@{*/ -#ifdef MS_USE_ADS1015 -/// @brief Decimals places in string representation; CO2 should have 0 when -/// using an ADS1015. -#define ALPHASENSE_CO2_RESOLUTION 0 -#else -/// @brief Decimals places in string representation; CO2 should have 4 when -/// using an ADS1115. -#define ALPHASENSE_CO2_RESOLUTION 4 -#endif /// Variable number; CO2 is stored in sensorValues[0]. #define ALPHASENSE_CO2_VAR_NUM 0 /// @brief Variable name in [ODM2 controlled -/// vocabulary](http://vocabulary.odm2.org/variablename/); -/// "radiationIncomingPAR" +/// vocabulary](http://vocabulary.odm2.org/variablename/); "carbonDioxide" #define ALPHASENSE_CO2_VAR_NAME "carbonDioxide" /// @brief Variable unit name in /// [ODM2 controlled vocabulary](http://vocabulary.odm2.org/units/); @@ -186,7 +184,15 @@ #define ALPHASENSE_CO2_UNIT_NAME "partPerMillion" /// @brief Default variable short code; "AlphasenseCO2ppm" #define ALPHASENSE_CO2_DEFAULT_CODE "AlphasenseCO2ppm" - +#ifdef MS_USE_ADS1015 +/// @brief Decimals places in string representation; CO2 should have 0 when +/// using an ADS1015. +#define ALPHASENSE_CO2_RESOLUTION 0 +#else +/// @brief Decimals places in string representation; CO2 should have 4 when +/// using an ADS1115. +#define ALPHASENSE_CO2_RESOLUTION 4 +#endif /**@}*/ /** @@ -212,8 +218,8 @@ /// @brief Variable name in [ODM2 controlled /// vocabulary](http://vocabulary.odm2.org/variablename/); "voltage" #define ALPHASENSE_CO2_VOLTAGE_VAR_NAME "voltage" -/// @brief Variable unit name in -/// [ODM2 controlled vocabulary](http://vocabulary.odm2.org/units/); "volt" (V) +/// @brief Variable unit name in [ODM2 controlled +/// vocabulary](http://vocabulary.odm2.org/units/); "volt" (V) #define ALPHASENSE_CO2_VOLTAGE_UNIT_NAME "volt" /// @brief Default variable short code; "AlphasenseCO2Voltage" #define ALPHASENSE_CO2_VOLTAGE_DEFAULT_CODE "AlphasenseCO2Voltage" @@ -249,6 +255,8 @@ class AlphasenseCO2 : public Sensor { * Alphasense CO2 sensor. Use -1 if it is continuously powered. * - The Alphasense CO2 sensor requires 2-5 V DC; current draw 20-60 mA * - The ADS1115 requires 2.0-5.5V but is assumed to be powered at 3.3V + * @param adsDiffMux Which two pins _on the TI ADS1115_ that will measure + * differential voltage. See #aco2_adsDiffMux_t. * @param i2cAddress The I2C address of the ADS 1x15, default is 0x48 (ADDR * = GND) * @param measurementsToAverage The number of measurements to take and @@ -258,7 +266,8 @@ class AlphasenseCO2 : public Sensor { * its power controlled by the same pin as the Alphasense CO2 sensor. This * library does not support any other configuration. */ - AlphasenseCO2(int8_t powerPin, uint8_t i2cAddress = ADS1115_ADDRESS, + AlphasenseCO2(int8_t powerPin, aco2_adsDiffMux_t adsDiffMux = DIFF_MUX_2_3, + uint8_t i2cAddress = ADS1115_ADDRESS, uint8_t measurementsToAverage = 7); /** * @brief Destroy the AlphasenseCO2 object - no action needed @@ -279,6 +288,11 @@ class AlphasenseCO2 : public Sensor { bool addSingleMeasurementResult(void) override; private: + /** + * @brief Which two pins _on the TI ADS1115_ that will measure differential + * voltage from the Turbidity Plus. See #aco2_adsDiffMux_t + */ + aco2_adsDiffMux_t _adsDiffMux; /** * @brief Internal reference to the I2C address of the TI-ADS1x15 */ @@ -330,7 +344,6 @@ class AlphasenseCO2_CO2 : public Variable { }; -/* clang-format off */ /** * @brief The Variable sub-class used for the * [raw voltage output](@ref sensor_alphasense_co2_voltage) from an @@ -338,7 +351,6 @@ class AlphasenseCO2_CO2 : public Variable { * * @ingroup sensor_alphasense_co2 */ -/* clang-format on */ class AlphasenseCO2_Voltage : public Variable { public: /**