中级
30 分钟

使用SHT40、SGP40和STM32L496AG保持最佳湿度水平,保护您的空间免受损害

赋能更健康的家居

Environment 2 Click with Discovery kit with STM32L496AG MCU

已发布 7月 22, 2025

点击板

Environment 2 Click

开发板

Discovery kit with STM32L496AG MCU

编译器

NECTO Studio

微控制器单元

STM32L496AG

通过积极监测湿度水平和空气质量参数,创造更健康的生活环境,确保您和您所爱之人的福祉。

A

A

硬件概览

它是如何工作的?

Environment 2 Click基于SHT40和SGP40,这是一款高精度、最佳的SHT相对湿度和温度传感器,与Sensirion的基于MOx的气体传感器组合。SHT40提供了更低的功耗、更高的精度规格以及完全校准的数字I2C快速模式Plus接口,以实现最快的数据传输。它覆盖了0到100%RH和-40°C到125°C的扩展操作湿度和温度范围,精度分别为±1.8%RH和±0.2°C。相反,该组合解决方案的附加气体传感器SGP40提供了湿度补偿的基于VOC的室内空气质量信号和温度控制的微热板。SHT40在推荐的平

均温度和湿度范围(5-60°C和20-80%RH)内运行效果最佳。长期暴露在推荐正常范围之外的条件下,尤其是在高相对湿度下,可能会暂时偏移RH信号。返回推荐的平均温度和湿度范围后,传感器将恢复到规格范围内。SGP40的输出信号由Sensirion的VOC算法处理,该算法会自动适应传感器所暴露的环境,将原始信号转换为VOC指数。传感元件和VOC算法在现实应用中对污染气体具有无与伦比的抗污染性,确保了卓越的长期稳定性、低漂移、高再现性和可靠性。Environment 2 

Click通过标准I2C双线接口与MCU通信。由于两个传感器的操作仅需3.3V逻辑电压电平,因此该Click板™还具有德州仪器的PCA9306电压电平转换器。I2C接口总线线路路由到双向电压电平转换器,使该Click板™能够与3.3V和5V的MCU正常工作。此Click板™可以通过VIO SEL跳线选择3.3V或5V逻辑电压电平。这种方式下,3.3V和5V的MCU都可以正确使用通信线路。此外,该Click板™配备了包含易于使用的函数和示例代码的库,可作为进一步开发的参考。

Environment 2 Click top side image
Environment 2 Click bottom side image

功能概述

开发板

32L496GDISCOVERY Discovery 套件是一款功能全面的演示和开发平台,专为搭载 Arm® Cortex®-M4 内核的 STM32L496AG 微控制器设计。该套件适用于需要在高性能、先进图形处理和超低功耗之间取得平衡的应用,支持无缝原型开发,适用于各种嵌入式解决方案。STM32L496AG 采用创新的节能架构,集成

了扩展 RAM 和 Chrom-ART 图形加速器,在提升图形性能的同时保持低功耗,使其特别适用于音频处理、图形用户界面和实时数据采集等对能效要求较高的应用。为了简化开发流程,该开发板配备了板载 ST-LINK/V2-1 调试器/编程器,提供即插即用的调试和编程体验,使用户无需额外硬件即可轻松加载、调

试和测试应用程序。凭借低功耗特性、增强的内存能力以及内置调试工具,32L496GDISCOVERY 套件是开发先进嵌入式系统、实现高效能解决方案的理想选择。

Discovery kit with STM32L496AG MCU double side image

微控制器概述 

MCU卡片 / MCU

STM32L496AG Image

建筑

ARM Cortex-M4

MCU 内存 (KB)

1024

硅供应商

STMicroelectronics

引脚数

169

RAM (字节)

327680

使用的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
PB7
SDA
Power Supply
5V
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

Environment 2 Click Schematic schematic

一步一步来

项目组装

Discovery kit with STM32H750XB MCU front image hardware assembly

从选择您的开发板和Click板™开始。以Discovery kit with STM32L496AG MCU作为您的开发板开始。

Discovery kit with STM32H750XB MCU front image hardware assembly
Thermo 21 Click front image hardware assembly
Prog-cut hardware assembly
Board mapper by product7 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
Discovery kit with STM32H750XB MCU NECTO MCU Selection Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto image step 11 hardware assembly

软件支持

库描述

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

关键功能:

  • environment2_get_temp_hum - Environment 2 获取温度和相对湿度的函数

  • environment2_get_air_quality - Environment 2 获取空气质量数据的函数

  • environment2_sgp40_measure_test - Environment 2 SGP40测量测试函数

开源

代码示例

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

/*!
 * @file main.c
 * @brief Environment2 Click example
 *
 * # Description
 * This library contains API for Environment 2 Click driver.
 * The library contains drivers for measuring air quality,
 * temperature and relative humidity.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes I2C driver and triggers the built-in self-test checking,
 * set heater off, performs sensors configuration and initialize VOC algorithm.
 *
 * ## Application Task
 * This is an example that demonstrates the use of the Environment 2 Click board.
 * Measured and display air quality ( raw data ), 
 * temperature ( degrees Celsius ), relative humidity ( % ) and VOC Index.
 * Results are being sent to the Usart Terminal where you can track their changes.
 * All data logs write on USB UART changes every 2 sec.
 *
 * @author Nenad Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "environment2.h"

static environment2_t environment2;
static log_t logger;

static uint16_t air_quality;
static float humidity;
static float temperature;
static int32_t voc_index;
static environment2_voc_algorithm_params voc_algorithm_params;

void application_init ( void ) {
    log_cfg_t log_cfg;                    /**< Logger config object. */
    environment2_cfg_t environment2_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.

    environment2_cfg_setup( &environment2_cfg );
    ENVIRONMENT2_MAP_MIKROBUS( environment2_cfg, MIKROBUS_1 );
    err_t init_flag = environment2_init( &environment2, &environment2_cfg );
    if ( init_flag == I2C_MASTER_ERROR ) {
        log_error( &logger, " Application Init Error. " );
        log_printf( &logger, " Please, run program again... " );

        for ( ; ; );
    }

    log_printf( &logger, "    Application Task   \r\n" );
    log_printf( &logger, "-----------------------\r\n" );
    log_printf( &logger, "  Environment 2 Click  \r\n" );
    log_printf( &logger, "-----------------------\r\n" );
    
    if ( environment2_sgp40_measure_test( &environment2 ) == ENVIRONMENT2_SGP40_TEST_PASSED ) {
        log_printf( &logger, "    All tests passed\r\n" );
        log_printf( &logger, "      Successfully\r\n" );
    } else {
        log_printf( &logger, "    One or more tests have\r\n" );
        log_printf( &logger, "     Failed\r\n" );
    }
    log_printf( &logger, "-----------------------\r\n" );
    Delay_ms ( 100 );
    
    environment2_sgp40_heater_off( &environment2 );
    Delay_ms ( 100 );
    
    environment2_config_sensors( );
    Delay_ms ( 100 );
}

void application_task ( void ) {
    environment2_get_temp_hum(  &environment2, &humidity, &temperature );
    Delay_ms ( 100 );
    
    log_printf( &logger, " Humidity    : %.2f %% \r\n", humidity );
    log_printf( &logger, " Temperature : %.2f C \r\n", temperature );
    
    environment2_get_air_quality( &environment2, &air_quality );
    Delay_ms ( 100 );
    
    log_printf( &logger, " Air Quality : %d \r\n", air_quality );
    log_printf( &logger, "- - - - - - - - - -  - \r\n" );
    
    environment2_get_voc_index( &environment2, &voc_index );
    Delay_ms ( 100 );
    
    log_printf( &logger, " VOC Index   : %d  \r\n", ( uint16_t ) voc_index );
    log_printf( &logger, "-----------------------\r\n" );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
}

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

额外支持

资源

喜欢这个项目吗?

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