【测评SGP40】快速部署实现的人工智能环境空气质量跟踪模型 #2 上电测试的arduino篇
<p>1、在开箱之后,现在获得的资料之后,用arduino代码开始测试。</p><p>具体连接参见上贴子,可以连接UART,如下图,其中UART选择SEL为悬空。</p>
<p></p>
<p> </p>
<p>2、 不过从代码分析看,只是支持I2C读取。</p>
<pre>
<code class="language-cpp">#include "sgp40_voc_index.h"
void setup() {
int16_t err;
Serial.begin(115200);// start serial for output
// wait for serial connection from PC
// comment the following line if you'd like the output
// without waiting for the interface being ready
while(!Serial);
/* Initialize I2C bus, SHT, SGP and VOC Engine */
while ((err = sensirion_init_sensors())) {
Serial.print("initialization failed: ");
Serial.println(err);
sensirion_sleep_usec(1000000); /* wait one second */
}
Serial.println("initialization successful");
}
/* Run one measurement per second */
void loop() {
int16_t err;
int32_t voc_index;
int32_t temperature_celsius;
int32_t relative_humidity_percent;
err = sensirion_measure_voc_index_with_rh_t(
&voc_index, &relative_humidity_percent, &temperature_celsius );
if (err == STATUS_OK) {
Serial.print("VOCindex:");
Serial.print(voc_index);
Serial.print("\t");
Serial.print("Humidity[%RH]:");
Serial.print(relative_humidity_percent * 0.001f);
Serial.print("\t");
Serial.print("Temperature:");
Serial.println(temperature_celsius * 0.001f);
} else {
Serial.print("error reading signal: ");
Serial.println(err);
}
sensirion_sleep_usec(1000000); /* wait one second */
}</code></pre>
<p>头文件如下,</p>
<pre>
<code class="language-cpp">
#include "sgp40_voc_index.h"
#include "sensirion_arch_config.h"
#include "sensirion_voc_algorithm.h"
#include "sgp40.h"
#include "shtc1.h"
#ifdef __cplusplus
extern "C" {
#endif
static VocAlgorithmParams voc_algorithm_params;
int16_t sensirion_init_sensors() {
int16_t ret;
sensirion_i2c_init();
ret = shtc1_probe();
if (ret)
return SENSIRION_SHT_PROBE_FAILED;
ret = sgp40_probe();
if (ret)
return SENSIRION_SGP_PROBE_FAILED;
VocAlgorithm_init(&voc_algorithm_params);
return 0;
}
int16_t sensirion_measure_voc_index(int32_t* voc_index) {
return sensirion_measure_voc_index_with_rh_t(voc_index, NULL, NULL);
}
int16_t sensirion_measure_voc_index_with_rh_t(int32_t* voc_index,
int32_t* relative_humidity,
int32_t* temperature) {
int32_t int_temperature, int_humidity;
int16_t ret;
uint16_t sraw;
ret = shtc1_measure_blocking_read(&int_temperature, &int_humidity);
if (ret)
return SENSIRION_GET_RHT_SIGNAL_FAILED;
if (temperature) {
*temperature = int_temperature;
}
if (relative_humidity) {
*relative_humidity = int_humidity;
}
ret = sgp40_measure_raw_with_rht_blocking_read(int_humidity,
int_temperature, &sraw);
if (ret) {
return SENSIRION_GET_SGP_SIGNAL_FAILED;
}
VocAlgorithm_process(&voc_algorithm_params, sraw, voc_index);
return 0;
}
#ifdef __cplusplus
}
#endif</code></pre>
<p>不过下载代码后没有正确启动数据,读取失败。就是如下指令返回的是读取错误。</p>
<p>err = sensirion_init_sensors()</p>
<p></p>
<p>这下进度就受阻了,需要分析看为什么这样的情况出现。</p>
<p> </p>
<p>这个有点坑爹,i2c需要外接上拉电阻,板子上没有。。。我测试也是这种情况。。。不能开箱即用,串口呢,没有Arduino驱动,也没有其它微控制器的串口驱动,坑爹。好在协议简单,我自己写了,啥时候空了发出来。</p>
dql2016 发表于 2021-2-1 13:25
这个有点坑爹,i2c需要外接上拉电阻,板子上没有。。。我测试也是这种情况。。。不能开箱即用,串口呢,没 ...
<p>是板子设计的问题吗?</p>
nmg 发表于 2021-2-26 11:33
是板子设计的问题吗?
<p>是的</p>
dql2016 发表于 2021-2-1 13:25
这个有点坑爹,i2c需要外接上拉电阻,板子上没有。。。我测试也是这种情况。。。不能开箱即用,串口呢,没 ...
<p>手册里提到I2C需要外部上拉电阻。一般单片机如果配置内部上拉应该也可以使用。</p> littleshrimp 发表于 2021-3-1 11:22
手册里提到I2C需要外部上拉电阻。一般单片机如果配置内部上拉应该也可以使用。
<p>有时间试试看<img height="48" src="https://bbs.eeworld.com.cn/static/editor/plugins/hkemoji/sticker/facebook/congra.gif" width="48" /></p>
页:
[1]