【Infineon XENSIV PAS CO2 sensor】Arduino routine test
[Copy link]
Last time I built a test circuit on a breadboard https://en.eeworld.com/bbs/thread-1223050-1-1.html and found that I couldn't read the sensor data. After being pointed out by netizens, it might be the unreliable Dupont line. I took the time to draw a simple Arduino Uno R3 interface compatible expansion board:
The 5V to 12V power module uses a high-end DCDC module (100+ dollars) that MPS offers for free. The effect of the module being plugged into the expansion board is as follows:
Tested using esp32s3 development board:
Test code, using IO17 and IO18 as I2C interface:
#include <Arduino.h>
#include <pas-co2-ino.hpp>
#define I2C_FREQ_HZ 100000
#define PERIODIC_MEAS_INTERVAL_IN_SECONDS 10
#define PRESSURE_REFERENCE 900
#define I2C_SDA 17
#define I2C_SCL 18
PASCO2Ino cotwo;
int16_t co2ppm;
Error_t err;
void setup()
{
Serial.begin(9600);
delay(800);
Serial.println("serial initialized");
/* Initialize the i2c interface used by the sensor */
Wire.begin(I2C_SDA, I2C_SCL,I2C_FREQ_HZ);
//Wire.setClock(I2C_FREQ_HZ);
/* Initialize the sensor */
err = cotwo.begin();
if(XENSIV_PASCO2_OK != err)
{
Serial.print("initialization error: ");
Serial.println(err);
}
/* We can set the reference pressure before starting
* the measure
*/
err = cotwo.setPressRef(PRESSURE_REFERENCE);
if(XENSIV_PASCO2_OK != err)
{
Serial.print("pressure reference error: ");
Serial.println(err);
}
/*
* Configure the sensor to measureme periodically
* every 10 seconds
*/
err = cotwo.startMeasure(PERIODIC_MEAS_INTERVAL_IN_SECONDS);
if(XENSIV_PASCO2_OK != err)
{
Serial.print("start measure error: ");
Serial.println(err);
}
delay(1000);
}
void loop()
{
/* Wait for the value to be ready. */
delay(PERIODIC_MEAS_INTERVAL_IN_SECONDS*1000);
err = cotwo.getCO2(co2ppm);
if(XENSIV_PASCO2_OK != err)
{
/* Retry in case of timing synch mismatch */
if(XENSIV_PASCO2_ERR_COMM == err)
{
delay(600);
err = cotwo.getCO2(co2ppm);
if(XENSIV_PASCO2_OK != err)
{
Serial.print("get co2 error: ");
Serial.println(err);
}
}
}
Serial.print("co2 ppm value : ");
Serial.println(co2ppm);
/*
* Assuming we have some mechanism to obtain a
* pressure reference (i.e. a pressure sensor),
* we could compensate again by setting the new reference.
* Here we just keep the initial value.
*/
err = cotwo.setPressRef(PRESSURE_REFERENCE);
if(XENSIV_PASCO2_OK != err)
{
Serial.print("pressure reference error: ");
Serial.println(err);
}
}
This time we got the correct result, and the sensor outputted the carbon dioxide content data:
appendix
I will try to port the Arduino version driver to the STM32 or CH32 platform when I have time.
|