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

eew_cT3H5d   2024-10-24 23:52 楼主

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

526590ba29e46f31d2604239e5867fa.jpg

获取传感器相关数据:

image.png

 

程序源码:

#include <Wire.h>
#include "Adafruit_SHT4x.h"
Adafruit_SHT4x sht4 = Adafruit_SHT4x();

#include <Adafruit_SCD30.h>
Adafruit_SCD30  scd30;


#include "Adafruit_SGP30.h"
Adafruit_SGP30 sgp;

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


#include <Arduino.h>
#include <SensirionUartSen44.h>
#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(&humidity, &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);
  
}

 

系统框图:

image.png  

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

回复评论

暂无评论,赶紧抢沙发吧
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复