eew_cT3H5d 发表于 2024-10-24 23:52

2024 DigiKey创意大赛】职场提神法宝项目-ESP32-C6多协议获取传感器数据

本帖最后由 eew_cT3H5d 于 2024-10-26 22:35 编辑

<p>先看效果:硬件连接,温湿度、光照、TVOC、二氧化碳传感器通过QWIIC连接,PM2.5传感器通过串口0连接</p>

<p></p>

<p>获取传感器相关数据:</p>

<p></p>

<p>&nbsp;</p>

<p>程序源码:</p>

<pre>
<code>#include &lt;Wire.h&gt;
#include "Adafruit_SHT4x.h"
Adafruit_SHT4x sht4 = Adafruit_SHT4x();

#include &lt;Adafruit_SCD30.h&gt;
Adafruit_SCD30scd30;


#include "Adafruit_SGP30.h"
Adafruit_SGP30 sgp;

#include "Adafruit_LTR329_LTR303.h"
Adafruit_LTR329 ltr = Adafruit_LTR329();


#include &lt;Arduino.h&gt;
#include &lt;SensirionUartSen44.h&gt;
#define SENSOR_SERIAL_INTERFACE Serial0
SensirionUartSen44 sen44;


void setup() {
Serial.begin(115200);
sht4.begin();
sht4.setPrecision(SHT4X_HIGH_PRECISION);
sht4.setHeater(SHT4X_NO_HEATER);

scd30.begin();

sgp.begin();

ltr.begin();
ltr.setGain(LTR3XX_GAIN_2);
ltr.setIntegrationTime(LTR3XX_INTEGTIME_100);
ltr.setMeasurementRate(LTR3XX_MEASRATE_200);

SENSOR_SERIAL_INTERFACE.begin(115200);
sen44.begin(SENSOR_SERIAL_INTERFACE);
sen44.startMeasurement();

}

void loop() {
sensors_event_t humidity, temp;
uint16_t visible_plus_ir, infrared,co2,tvoc;

    uint16_t SEN44_error;
    uint16_t massConcentrationPm1p0;
    uint16_t massConcentrationPm2p5;
    uint16_t massConcentrationPm4p0;
    uint16_t massConcentrationPm10p0;
    float vocIndex;
    float ambientHumidity;
    float ambientTemperature;


sht4.getEvent(&amp;humidity, &amp;temp);

if (scd30.dataReady()){co2 = scd30.CO2;}

if (sgp.IAQmeasure()) { tvoc = sgp.TVOC;}

if (ltr.newDataAvailable()) {ltr.readBothChannels(visible_plus_ir, infrared);}


      SEN44_error = sen44.readMeasuredMassConcentrationAndAmbientValues(
      massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0,
      massConcentrationPm10p0, vocIndex, ambientHumidity, ambientTemperature);


Serial.print("A");Serial.print(temp.temperature);Serial.print("B");Serial.print(humidity.relative_humidity);
Serial.print("C");Serial.print(scd30.CO2, 3);Serial.print("D");Serial.print(sgp.TVOC);
Serial.print("E");Serial.print(massConcentrationPm2p5);Serial.print("F");Serial.print(vocIndex);Serial.println("@");
delay(1000);

}</code></pre>

<p>&nbsp;</p>

<p>系统框图:</p>

<p> &nbsp;</p>
页: [1]
查看完整版本: 2024 DigiKey创意大赛】职场提神法宝项目-ESP32-C6多协议获取传感器数据