API Reference

The Arduino library API is implemented via the PASCO2Ino class.

XENSIV™ PAS CO2 Arduino API

class PASCO2Ino

Public Functions

PASCO2Ino(TwoWire *wire = &Wire, uint8_t intPin = unusedPin)

XENSIV™ PAS CO2 I2C Arduino Constructor.

Parameters
  • wire[in] TwoWire interface instance. Default is the Arduino primary Wire instance.

  • intPin[in] Interrupt pin. Default is UnusedPin

Pre

None

PASCO2Ino(HardwareSerial *serial, uint8_t intPin = unusedPin)

XENSIV™ PAS CO2 UART Arduino Constructor.

Parameters
  • serial[in] Serial interface instance

  • intPin[in] Interrupt pin. Default is UnusedPin

Pre

None

~PASCO2Ino()

XENSIV™ PAS CO2 Arduino Destructor.

It disables the sensor and deletes all the dynamically created PAL instances in the constructor

Pre

None

Error_t begin()

Begins the sensor.

Initializes the serial interface if the initialization is delegated to the PASCO2 class. Sets the I2C freq or UART baudrate to the default values prior the serial interface initialization. Initializes the interrupt pin if used.

Returns

XENSIV™ PAS CO2 error code

Pre

None

Returns

XENSIV_PASCO2_OK – if success

Error_t end()

Ends the sensor.

Deinitializes the serial interface if the deinitialization is delegated to the PASCO2Ino class. Deinitializes the interrupt pin if used.

Returns

XENSIV™ PAS CO2 error code

Pre

begin()

Returns

XENSIV_PASCO2_OK – always

Error_t startMeasure(int16_t periodInSec = 0, int16_t alarmTh = 0, void (*cback)(void*) = nullptr, bool earlyNotification = false)

Triggers the internal measuring of the sensor.

The function start the measurement controlling the different sensor modes and features depending on the configured arguments.

Single shot

If the function is called with no arguments, the sensor will be triggered to perform a single shot measurement. The user needs to poll with getCO2() until the CO2 value is available and has been read out from the sensor. The CO2 concentration value read will be zero as long as no value is available or if any error occurred in the readout attempt. Polling example:

PASCO2Ino cotwo(serial_intf); 
int16_t   co2ppm;

serial_intf.begin();

cotwo.begin();              

cotwo.startMeasure();

do{ cotwo.getCO2(co2ppm); } while (co2ppm == 0);  

Continuous measurement

Continuous measurements (periodInSec) will configure the sensor to perform a measurement every desired period. Between 5 and 4095 seconds. Without further arguments, the user has to poll with getCO2() until the value is available. Any super loop or thread routine, can just consists on reading the CO2 (getCO2()). For example, measure every 5 minutes:

PASCO2Ino cotwo(serial_intf);
int16_t   co2ppm;

serial_intf.begin();

cotwo.begin();  

cotwo.startMeasure(300);

while(1)
{
    delay(300000); // Measure will be ready every 5 min

    do{ cotwo.getCO2(co2ppm); } while (co2ppm == 0);  
    // ... do something with the co2 value ... 
}

Synching readouts with the hardware interrupt

In order not to saturate the sensor with constant serial requests, especially in continuous mode, it is recommended to synch the readout with a timer. Or even better using the hardware GPIO hardware interrupt. If the interrupt pin has been provided, passing a callback function will enable the interrupt mode. The type of interrupt is decided depending on the value of the rest of the arguments and operations modes. Some example:

volatile bool intFlag = false;
void cback(void *)
{
    intFlag = true;
}

PASCO2Ino cotwo(serial_intf, interrupt);
int16_t   co2ppm;

serial_intf.begin();

cotwo.begin();  

cotwo.startMeasure(300,0,cback);

while(1)
{
    while(!intFlag) { // block or yield() };
    cotwo.getCO2(co2ppm);   
    // ... do something with the co2 value ... 
    intFlag = false;
}

Alarm mode

If the alarm threshold argument is non-zero, the alarm mode is activated, and the sensor internal flag will be enabled if the concentration of CO2 goes above the specified value. This option is better combined with the interupt mode. Thus, if the interrupt mode is available and a callback function is passed, the interrupt will occurr only when the co2 concentration goes above the threshold. This makes mostly sense for continuous measurement configuration. But it can be used as well for a single shot configuration

Early notification

The early notification mode can be used for battery power solutions. The interrupt signal can trigger the enablement of the 12V emitter power supply just before the measurement is performed, and switch it off as the interrupt signal is disabled. Therefore, the power supply 12V only needs to be on during the CO2 sensing.

When this flag is set, the alarm interrupt functionality is not available. Both options cannot be combined.

Parameters
  • periodInSec[in] Enables continuous measurement with the specified period. The default value is 0, meaning single shot operation. The valid period range goes between 5 and 4095 seconds

  • alarmTh[in] Enables upper alarm threshold mode for the specified ppm value The default value is 0, meaning no alarm mode. For any non-zero value, the sensor will internally set the alarm flag. If an interrupt callback function is provided, then the interrupt will occurr only when the defined threshold has been tresspassed

  • cback[in] Pointer to the callback function to be called upon interrupt

  • earlyNotification[in] Enables early notifification interrupt. Disabled (false) by default

Returns

XENSIV™ PAS CO2 error code

Pre

begin()

Returns

XENSIV_PASCO2_OK – if success

Error_t stopMeasure()

Stops the internal measuring of the sensor.

Sets operation mode to idle

Returns

XENSIV™ PAS CO2 error code

Pre

begin()

Returns

XENSIV_PASCO2_OK – if success

Error_t getCO2(int16_t &CO2PPM)

Gets the CO2 concentration measured.

The value read is zero when no measurement is yet available or an error has ocurrred.

Parameters

co2ppm[out] CO2 concentration read (in ppm)

Returns

XENSIV™ PAS CO2 error code

Pre

startMeasure()

Returns

XENSIV_PASCO2_OK – if success

Error_t getDiagnosis(Diag_t &diagnosis)

Gets diagnosis information.

The sensor status registers includes the following flags:

  • Sensor ready

  • PWM pin enabled

  • Temperature out of range error

  • IR emitter voltage out of range error

  • Communication error which will be stored in the Diag_t struct varible passed by argument. After reading the flags, these are cleared in the device writing in the corresponding clear flag bitfields.

Parameters

diagnosis[out] Struct to store the diagnosis flags values

Returns

XENSIV™ PAS CO2 error code

Pre

None

Returns

XENSIV_PASCO2_OK – if success

Error_t setABOC(ABOC_t aboc, int16_t abocRef)

Configures the sensor automatic baseline compensation.

Parameters
  • aboc[in] Automatic baseline compenstation mode

  • abocRef[in] Automatic baseline compensation reference

Returns

XENSIV™ PAS CO2 error code

Pre

begin()

Returns

XENSIV_PASCO2_OK – if success

Error_t setPressRef(uint16_t pressRef)

Sets the sensor pressure reference.

Parameters

pressRef[in] Pressure reference value. Min value is 750, and max 1150.

Returns

XENSIV™ PAS CO2 error code

Pre

begin()

Returns

XENSIV_PASCO2_OK – if success

Error_t performForcedCompensation(uint16_t co2Ref)

Performs force compensation.

Calculates the offset compensation when the sensor is exposed to a CO2 reference value.

Warning

The device is left in idle mode after the compensation value is stored in non-volatile memory.

Parameters

co2Ref[in] Automatic baseline compenstation mode

Returns

XENSIV™ PAS CO2 error code

Pre

begin()

Returns

XENSIV_PASCO2_OK – if success

Error_t clearForcedCompensation()

Resets the forced calibration correction factor.

Returns

XENSIV™ PAS CO2 error code

Pre

begin()

Returns

XENSIV_PASCO2_OK – if success

Error_t reset()

Resets the sensor via serial command.

Returns

XENSIV™ PAS CO2 error code

Pre

begin()

Returns

XENSIV_PASCO2_OK – if success

Error_t getDeviceID(uint8_t &prodID, uint8_t &revID)

Gets device product identifier.

Parameters
  • prodID[out] Product identifier

  • revID[out] Version identifier

Returns

XENSIV™ PAS CO2 error code

Pre

begin()

Returns

XENSIV_PASCO2_OK – if success

Error_t getRegister(uint8_t regAddr, uint8_t *data, uint8_t len)

Reads from the sensor device into the given data buffer.

Parameters
  • regAddr[in] Start register address

  • data[out] Pointer to the data buffer to store the register values of the sensor

  • len[in] Number of bytes of data to be read

Returns

XENSIV™ PAS CO2 error code

Pre

begin()

Returns

XENSIV_PASCO2_OK – if success

Error_t setRegister(uint8_t regAddr, const uint8_t *data, uint8_t len)

Writes the given data buffer into the sensor device.

Parameters
  • regAddr[in] Start register address

  • data[in] Pointer to the data buffer to be written in the sensor

  • len[in] Number of bytes of data to be written

Returns

XENSIV™ PAS CO2 error code

Pre

begin()

Returns

XENSIV_PASCO2_OK – if success

Public Static Attributes

static constexpr uint8_t unusedPin = 0xFFU

Unused pin

Types

Return Error Codes

typedef int32_t Error_t
XENSIV_PASCO2_OK

Result code indicating a successful operation

XENSIV_PASCO2_ERR_COMM

Result code indicating a communication error

XENSIV_PASCO2_ERR_WRITE_TOO_LARGE

Result code indicating that an unexpectedly large I2C write was requested which is not supported

XENSIV_PASCO2_ERR_NOT_READY

Result code indicating that the sensor is not yet ready after reset

XENSIV_PASCO2_ICCERR

Result code indicating whether a non-valid command has been received by the serial communication interface

XENSIV_PASCO2_ORVS

Result code indicating whether a condition where VDD12V has been outside the specified valid range has been detected

XENSIV_PASCO2_ORTMP

Result code indicating whether a condition where the temperature has been outside the specified valid range has been detected

XENSIV_PASCO2_READ_NRDY

Result code indicating that a new CO2 value is not yet ready

Dignosis

typedef xensiv_pasco2_status_t Diag_t
union xensiv_pasco2_status_t
#include <xensiv_pasco2.h>

Structure of the sensor’s status register (SENS_STS)

Public Members

uint32_t __pad0__
uint32_t iccerr

Communication error notification bit. Indicates whether an invalid command has been received by the serial communication interface

uint32_t orvs

Out-of-range VDD12V error bit

uint32_t ortmp

Out-of-range temperature error bit

uint32_t pwm_dis_st

PWM_DIS pin status

uint32_t sen_rdy

Sensor ready bit

struct xensiv_pasco2_status_t::[anonymous] b

Structure used for bit access

uint8_t u

Type used for byte access

Baseline Offset Compensation

typedef xensiv_pasco2_boc_cfg_t ABOC_t
enum xensiv_pasco2_boc_cfg_t

Enum defining the different device baseline offset compensation (BOC) modes

Values:

enumerator XENSIV_PASCO2_BOC_CFG_DISABLE

No offset compensation occurs

enumerator XENSIV_PASCO2_BOC_CFG_AUTOMATIC

The offset is periodically updated at each BOC computation

enumerator XENSIV_PASCO2_BOC_CFG_FORCED

Forced compensation

XENSIV™ PAS CO2 C Reference API

The Arduino library is wrapping the platform abstracted C library from this project. Find out the complete C core library documentation here.