Skip to content

Commit

Permalink
Allow other pin options for Alphasense CO2, as done in Turbidity Plus
Browse files Browse the repository at this point in the history
Signed-off-by: Sara Damiano <[email protected]>
  • Loading branch information
SRGDamia1 committed Sep 30, 2024
1 parent c65d3a8 commit cbbd3b4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
3 changes: 2 additions & 1 deletion examples/menu_a_la_carte/menu_a_la_carte.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions src/sensors/AlphasenseCO2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
50 changes: 31 additions & 19 deletions src/sensors/AlphasenseCO2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
/**@}*/

Expand Down Expand Up @@ -165,28 +173,26 @@
* {{ @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/);
/// "partPerMillion" (ppm)
#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
/**@}*/

/**
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
*/
Expand Down Expand Up @@ -330,15 +344,13 @@ 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
* [Alphasense IRC-A1 CO2](@ref sensor_alphasense_co2).
*
* @ingroup sensor_alphasense_co2
*/
/* clang-format on */
class AlphasenseCO2_Voltage : public Variable {
public:
/**
Expand Down

0 comments on commit cbbd3b4

Please sign in to comment.