上次在面包板上搭建测试电路https://bbs.eeworld.com.cn/thread-1223050-1-1.html,发现无法读出传感器数据,经过网友指点,可能是杜邦线不可靠的问题。抽空画了一个简单的arduino uno r3接口兼容扩展板:
5V转12V电源模块,正好使用了MPS活动白嫖的高端DCDC模块(100+大洋),模块插在扩展板上的效果:
#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);
}
}
这次得到了正确的结果,传感器输出了二氧化碳含量数据:
附件
后续有时间尝试将arduino版驱动移植到stm32或者ch32平台。
引用: 秦天qintian0303 发表于 2022-12-1 16:47 真奢侈,随意搭一个升压模块就可以了
贵的就是香一些