【英飞凌XENSIV™ PAS CO2传感器】arduino例程测试
<p>上次在面包板上搭建测试电路<a href="https://bbs.eeworld.com.cn/thread-1223050-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1223050-1-1.html</a>,发现无法读出传感器数据,经过网友指点,可能是杜邦线不可靠的问题。抽空画了一个简单的arduino uno r3接口兼容扩展板:</p><p></p>
<p></p>
<p>5V转12V电源模块,正好使用了MPS活动白嫖的高端DCDC模块(100+大洋),模块插在扩展板上的效果:</p>
<p>使用esp32s3开发板进行测试:</p>
<p>测试代码,使用IO17、IO18作为I2C接口:</p>
<pre>
<code class="language-cpp">#include <Arduino.h>
#include <pas-co2-ino.hpp>
#define I2C_FREQ_HZ100000
#define PERIODIC_MEAS_INTERVAL_IN_SECONDS10
#define PRESSURE_REFERENCE900
#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);
}
}</code></pre>
<p> </p>
<p>这次得到了正确的结果,传感器输出了二氧化碳含量数据:</p>
<p></p>
<p>附件</p>
<div></div>
<p> </p>
<p>后续有时间尝试将arduino版驱动移植到stm32或者ch32平台。</p>
<p>真奢侈,随意搭一个升压模块就可以了</p>
秦天qintian0303 发表于 2022-12-1 16:47
真奢侈,随意搭一个升压模块就可以了
<p>贵的就是香一些</p>
<p>楼主二氧化碳传感器还有吗?能转让给我玩玩吗?</p>
页:
[1]