中级
30 分钟

通过SHT41A-AD1B和STM32G071RB提升环境健康 - 湿度和空气质量融合

晴空万里,健康生活

Environment 4 Click with Nucleo 64 with STM32G071RB MCU

已发布 10月 08, 2024

点击板

Environment 4 Click

开发板

Nucleo 64 with STM32G071RB MCU

编译器

NECTO Studio

微控制器单元

STM32G071RB

监测室内湿度水平和空气质量,以确保更健康的生活和工作环境,降低呼吸问题和过敏的风险。

A

A

硬件概览

它是如何工作的?

Environment 4 Click 基于 SHT41A-AD1B,这是第4代高精度 SHT 相对湿度和温度传感器,结合了 Sensirion 的 SGP41 基于 MOx 的气体传感器。基于 Sensirion 的成熟 CMOSens® 技术和在湿度传感方面的长期经验,SHT41A-AD1B 确保了最高的精度。它覆盖了从 0 到 100%RH 和 -40°C 到 125°C 的扩展工作湿度和温度范围,精度分别为 ±2%RH 和 ±0.3°C。SHT41A-AD1B 还专门用于汽车应用,满足诸如 85°C/85%RH 加速寿命测试和 AEC Q100 资格认证等可靠性要求。SHT41A-AD1B 在推荐的平均温度和湿度范围 5-60°C 和 20-80%RH 内工作效果最佳。长时间暴露在推荐正常范围之外的条件

下,尤其是在高相对湿度下,可能会暂时偏移 RH 信号。回到推荐的平均温度和湿度范围后,传感器将恢复到规格范围内。此组合解决方案的补充部分是 SGP41,这是 Sensirion 新的基于 MOx 的气体传感器,可提供一个 VOC 和一个基于 NOx 的室内空气质量信号。正如所述,SGP41 提供两个对室内环境中常见的 VOC 以及氧化气体(如 NOx 或 O3)敏感的原始数字信号。这意味着该板可以持续监测 VOC 和 NOx 情况,包括人类无法感知的潜在有害事件。原始信号与感应材料电阻的对数成正比,并由 Sensirion 强大的气体指数算法处理。该算法可自动触发空气处理设备清除室内气体污染物,而无需手动用户干

预。Environment 4 Click 使用标准 I2C 2 线接口与 MCU 通信。由于这两个传感器都只需要 3.3V 的逻辑电压水平运行,因此该 Click board™ 还配备了德州仪器的 PCA9306 电压电平转换器。I2C 接口总线线路被路由到双向电压电平转换器,使得该 Click board™ 能够与 3.3V 和 5V 的 MCU 正常工作。该 Click board™ 可以在 3.3V 或 5V 逻辑电压水平下运行,通过 VCC SEL 跳线选择。这样,3.3V 和 5V 的 MCU 都可以正确使用通信线路。此外,该 Click board™ 配备了包含易于使用的函数和示例代码的库,可作为进一步开发的参考。

Environment 4 Click top side image
Environment 4 Click bottom side image

功能概述

开发板

Nucleo-64 搭载 STM32G071RB MCU 提供了一种经济高效且灵活的平台,供开发者探索新想法并原型设计他们的项目。该板利用 STM32 微控制器的多功能性,使用户能够为他们的项目选择最佳的性能与功耗平衡。它配备了 LQFP64 封装的 STM32 微控制器,并包含了如用户 LED(同时作为 ARDUINO® 信号)、用户和复位按钮,以及 32.768kHz 晶体振荡器用于精确的计时操作等基本组件。Nucleo-64 板设计考虑到扩展性和灵活性,它特有的 ARDUINO® Uno

V3 扩展连接器和 ST morpho 扩展引脚头,提供了对 STM32 I/O 的完全访问,以实现全面的项目整合。电源供应选项灵活,支持 ST-LINK USB VBUS 或外部电源,确保在各种开发环境中的适应性。该板还配备了一个具有 USB 重枚举功能的板载 ST-LINK 调试器/编程器,简化了编程和调试过程。此外,该板设计旨在简化高级开发,它的外部 SMPS 为 Vcore 逻辑供电提供高效支持,支持 USB 设备全速或 USB SNK/UFP 全速,并内置加密功能,提升了项目的功效

和安全性。通过外部 SMPS 实验的专用连接器、 用于 ST-LINK 的 USB 连接器以及 MIPI® 调试连接器,提供了更多的硬件接口和实验可能性。开发者将通过 STM32Cube MCU Package 提供的全面免费软件库和示例得到广泛支持。这些,加上与多种集成开发环境(IDE)的兼容性,包括 IAR Embedded Workbench®、MDK-ARM 和 STM32CubeIDE,确保了流畅且高效的开发体验,使用户能够充分利用 Nucleo-64 板在他们的项目中的能力。

Nucleo 64 with STM32G071RB MCU double side image

微控制器概述 

MCU卡片 / MCU

default

建筑

ARM Cortex-M0

MCU 内存 (KB)

128

硅供应商

STMicroelectronics

引脚数

64

RAM (字节)

36864

你完善了我!

配件

Click Shield for Nucleo-64 配备了两个专有的 mikroBUS™ 插座,使得所有的 Click board™ 设备都可以轻松地与 STM32 Nucleo-64 开发板连接。这样,Mikroe 允许其用户从不断增长的 Click boards™ 范围中添加任何功能,如 WiFi、GSM、GPS、蓝牙、ZigBee、环境传感器、LED、语音识别、电机控制、运动传感器等。您可以使用超过 1537 个 Click boards™,这些 Click boards™ 可以堆叠和集成。STM32 Nucleo-64 开发板基于 64 引脚封装的微控制器,采用 32 位 MCU,配备 ARM Cortex M4 处理器,运行速度为 84MHz,具有 512Kb Flash 和 96KB SRAM,分为两个区域,顶部区域代表 ST-Link/V2 调试器和编程器,而底部区域是一个实际的开发板。通过 USB 连接方便地控制和供电这些板子,以便直接对 Nucleo-64 开发板进行编程和高效调试,其中还需要额外的 USB 线连接到板子上的 USB 迷你接口。大多数 STM32 微控制器引脚都连接到了板子左右边缘的 IO 引脚上,然后连接到两个现有的 mikroBUS™ 插座上。该 Click Shield 还有几个开关,用于选择 mikroBUS™ 插座上模拟信号的逻辑电平和 mikroBUS™ 插座本身的逻辑电压电平。此外,用户还可以通过现有的双向电平转换器,使用任何 Click board™,无论 Click board™ 是否在 3.3V 或 5V 逻辑电压电平下运行。一旦将 STM32 Nucleo-64 开发板与我们的 Click Shield for Nucleo-64 连接,您就可以访问数百个工作于 3.3V 或 5V 逻辑电压电平的 Click boards™。

Click Shield for Nucleo-64 accessories 1 image

使用的MCU引脚

mikroBUS™映射器

NC
NC
AN
NC
NC
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
NC
NC
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PB8
SCL
I2C Data
PB9
SDA
Power Supply
5V
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

Environment 4 Click Schematic schematic

一步一步来

项目组装

Click Shield for Nucleo-64 front image hardware assembly

从选择您的开发板和Click板™开始。以Nucleo 64 with STM32G071RB MCU作为您的开发板开始。

Click Shield for Nucleo-64 front image hardware assembly
Nucleo 64 with STM32F401RE MCU front image hardware assembly
EEPROM 13 Click front image hardware assembly
Prog-cut hardware assembly
Nucleo-64 with STM32XXX MCU MB 1 Mini B Conn - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Clicker 4 for STM32F4 HA MCU Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

实时跟踪您的结果

应用程序输出

1. 应用程序输出 - 在调试模式下,“应用程序输出”窗口支持实时数据监控,直接提供执行结果的可视化。请按照提供的教程正确配置环境,以确保数据正确显示。

2. UART 终端 - 使用UART Terminal通过USB to UART converter监视数据传输,实现Click board™与开发系统之间的直接通信。请根据项目需求配置波特率和其他串行设置,以确保正常运行。有关分步设置说明,请参考提供的教程

3. Plot 输出 - Plot功能提供了一种强大的方式来可视化实时传感器数据,使趋势分析、调试和多个数据点的对比变得更加直观。要正确设置,请按照提供的教程,其中包含使用Plot功能显示Click board™读数的分步示例。在代码中使用Plot功能时,请使用以下函数:plot(insert_graph_name, variable_name);。这是一个通用格式,用户需要将“insert_graph_name”替换为实际图表名称,并将“variable_name”替换为要显示的参数。

软件支持

库描述

该库包含 Environment 4 Click 驱动程序的 API。

关键功能:

  • environment4_sht_read_meas_hp - 此功能以高精度从 SHT41A 设备读取温度和湿度测量值

  • environment4_sgp_exe_conditioning - 此功能通过使用 I2C 串行接口执行 SGP41 设备的调节命令

  • environment4_sgp_meas_raw_signals - 此功能通过使用 I2C 串行接口测量 SGP41 设备的原始信号

开源

代码示例

完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio 应用程序代码也可以在MIKROE的GitHub账户中找到。

/*!
 * @file main.c
 * @brief Environment 4 Click example
 *
 * # Description
 * This example demonstrates the use of Environment 4 Click board by reading
 * the temperature and humidity data and calculating VOC and NOx indexes.
 * 
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver, and reads and displays the SGP41 sensor unique serial number
 * and performs its build-in self-test. After that performs the SHT41 sensor software reset
 * and reads its unique serial number. Finally, it initializes the sensirion gas index algorithm
 * for VOC and NOx index calculation.
 *
 * ## Application Task
 * Reads the temperature (degC) and the relative humidity (%RH) data from SHT41 sensor with high precision.
 * For the first 10 seconds it executes NOx conditioning and after that it reads the raw signals for VOC and NOx
 * data and processes them with sensirion's gas index algorithm for calculating VOC and NOx indexes.
 * All data will be displayed on the USB UART approximately once per second.
 * 
 * @note
 * Time required for reliably detecting VOC and NOx events on switching ON is typically less than 60 seconds.
 * Refer to the SGP41 sensor datasheet for more timing specifications.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "environment4.h"
#include "sensirion_gas_index_algorithm.h"

static environment4_t environment4;
static log_t logger;

static GasIndexAlgorithmParams voc_params;
static GasIndexAlgorithmParams nox_params;

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    environment4_cfg_t environment4_cfg;  /**< Click config object. */

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, " Application Init " );

    // Click initialization.
    environment4_cfg_setup( &environment4_cfg );
    ENVIRONMENT4_MAP_MIKROBUS( environment4_cfg, MIKROBUS_1 );
    if ( I2C_MASTER_ERROR == environment4_init( &environment4, &environment4_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    uint16_t serial_num_sgp[ 3 ];
    if ( ENVIRONMENT4_OK == environment4_sgp_get_serial_num ( &environment4, serial_num_sgp ) )
    {
        log_printf ( &logger, " SGP Serial number: 0x%.4X%.4X%.4X\r\n", 
                     serial_num_sgp[ 0 ], serial_num_sgp[ 1 ], serial_num_sgp[ 2 ] );
    }
    
    uint8_t test_result_sgp;
    if ( ENVIRONMENT4_OK == environment4_sgp_exe_self_test ( &environment4, &test_result_sgp ) )
    {
        log_printf ( &logger, " SGP Self test result: " );
        if ( ENVIRONMENT4_SGP_SELF_TEST_OK == test_result_sgp )
        {
            log_printf ( &logger, "OK\r\n" );
        }
        else
        {
            if ( ENVIRONMENT4_SGP_SELF_TEST_VOC_PIXEL == test_result_sgp )
            {
                log_printf ( &logger, "VOC pixel fail; " );
            }
            if ( ENVIRONMENT4_SGP_SELF_TEST_NOX_PIXEL == test_result_sgp )
            {
                log_printf ( &logger, "NOx pixel fail; " );
            }
            log_printf ( &logger, "\r\n" );
        }
    }
    
    if ( ENVIRONMENT4_OK == environment4_sht_soft_reset ( &environment4 ) )
    {
        log_printf ( &logger, " SHT Software reset\r\n" );
        Delay_1sec ( );
    }
    
    uint32_t serial_num_sht;
    if ( ENVIRONMENT4_OK == environment4_sht_read_serial_num ( &environment4, &serial_num_sht ) )
    {
        log_printf ( &logger, " SHT Serial number: 0x%.8LX\r\n", serial_num_sht );
    }
    
    log_printf ( &logger, " Initialize Gas Index algorithm for VOC and NOx\r\n" );
    GasIndexAlgorithm_init ( &voc_params, GasIndexAlgorithm_ALGORITHM_TYPE_VOC );
    GasIndexAlgorithm_init ( &nox_params, GasIndexAlgorithm_ALGORITHM_TYPE_NOX );
    
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    float temperature, humidity;
    uint16_t comp_rh, comp_t, sraw_voc, sraw_nox;
    int32_t voc_index, nox_index;
    static uint8_t conditioning_num = 10;
    Delay_ms ( 1000 );
    if ( ENVIRONMENT4_OK == environment4_sht_read_meas_hp ( &environment4, &temperature, &humidity ) )
    {
        log_printf ( &logger, "\r\n Temperature: %.2f degC\r\n", temperature );
        log_printf ( &logger, " Humidity: %.2f %%RH\r\n", humidity );
        
        comp_rh = ( uint16_t ) ( humidity * ENVIRONMENT4_SHT_DATA_RESOLUTION / 
                                 ( ENVIRONMENT4_SHT_ABS_MAX_HUM - ENVIRONMENT4_SHT_ABS_MIN_HUM ) );
        comp_t = ( uint16_t ) ( ( temperature - ENVIRONMENT4_SHT_ABS_MIN_TEMP ) * ENVIRONMENT4_SHT_DATA_RESOLUTION / 
                                ( ENVIRONMENT4_SHT_ABS_MAX_TEMP - ENVIRONMENT4_SHT_ABS_MIN_TEMP ) );
        if ( conditioning_num ) 
        {
            if ( ENVIRONMENT4_OK == environment4_sgp_exe_conditioning ( &environment4, comp_rh, comp_t, &sraw_voc ) )
            {
                conditioning_num--;
            }
        } 
        else 
        {
            if ( ENVIRONMENT4_OK == environment4_sgp_meas_raw_signals ( &environment4, comp_rh, comp_t, &sraw_voc, &sraw_nox ) )
            {
                GasIndexAlgorithm_process( &voc_params, ( int32_t ) sraw_voc, &voc_index );
                GasIndexAlgorithm_process( &nox_params, ( int32_t ) sraw_nox, &nox_index );
                log_printf ( &logger, " VOC Index: %ld\r\n", voc_index );
                log_printf ( &logger, " NOx Index: %ld\r\n", nox_index );
            }
        }
    }
}

int main ( void ) 
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif
    
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}

// ------------------------------------------------------------------------ END

额外支持

资源

喜欢这个项目吗?

'购买此套件' 按钮会直接带您进入购物车,您可以在购物车中轻松添加或移除产品。