中级
30 分钟

使用ZMOD4510和STM32F031K6迎接清新空气

新鲜空气的守护者:我们的解决方案,为您带来更健康的生活

Air quality 8 Click with Nucleo 32 with STM32F031K6 MCU

已发布 10月 01, 2024

点击板

Air quality 8 Click

开发板

Nucleo 32 with STM32F031K6 MCU

编译器

NECTO Studio

微控制器单元

STM32F031K6

为了应对日益严重的空气污染问题,我们的监控解决方案如同守护者,确保您呼吸的空气质量最高。

A

A

硬件概览

它是如何工作的?

Air Quality 8 Click基于ZMOD4510,这是一款由瑞萨设计的预校准数字传感器,旨在可靠检测室内外空气质量。该传感器具备选择性臭氧测量能力(NO2和O3),在连续运行中功耗低于23mW,提高了能效而不影响空气质量。它还具有电气和气体校准、经过验证的MOx材料、数字接口、硅氧烷耐受性、高灵敏度和长期稳定性,可实现ppb级检测限度。其扩展的工作湿度和温度范围覆盖5至90%RH和-20°C至50°C,臭氧和二氧化氮的测量范围为20至500ppb。ZMOD4510的气体传感元件由硅基MEMS结构上的加热元件、金属氧化物(MOx)化学电阻器和CMOS信号调节IC组成,该IC控制传感

器温度并测量MOx电阻,电阻是气体浓度的函数。它有两种工作模式。第一种模式允许对空气质量进行一般测量,包括对二氧化氮(NO2)和臭氧(O3)的非选择性测量。第二种模式允许选择性测量臭氧(O3),在快速采样率为2秒时,平均功耗为0.2mW。它根据研究和国际标准检测典型气体,并使用一系列应用温度对空气进行采样并报告空气质量指数(AQI)。传感器不需要主动或直接的气流通过传感器模块,因为环境气体的扩散不会限制传感器的响应时间。ZMOD4510还可以检测安全相关气体;然而,该传感器模块并非设计用于可靠检测这些干扰物,因此未获批准用于安全关键或生命保

护应用。Air Quality 8 Click使用标准I2C两线接口与MCU通信,以读取数据和配置设置,支持100kHz时钟频率的标准模式和高达400kHz的快速模式操作。此外,它还具有其他功能,如连接到mikroBUS™插座RST引脚的复位引脚,将模块置于低逻辑电平时进入复位状态,以及连接到mikroBUS™插座INT引脚的额外中断信号,用于指示测量过程的状态。此Click board™只能在3.3V逻辑电压水平下运行。因此,在使用不同逻辑电平的MCU之前,必须进行适当的逻辑电压电平转换。此外,此Click board™配备了包含函数和示例代码的库,可用作进一步开发的参考。

Air quality 8 Click top side image
Air quality 8 Click bottom side image

功能概述

开发板

Nucleo 32开发板搭载STM32F031K6 MCU,提供了一种经济且灵活的平台,适用于使用32引脚封装的STM32微控制器进行实验。该开发板具有Arduino™ Nano连接性,便于通过专用扩展板进行功能扩展,并且支持mbed,使其能够无缝集成在线资源。板载集成

ST-LINK/V2-1调试器/编程器,支持通过USB重新枚举,提供三种接口:虚拟串口(Virtual Com port)、大容量存储和调试端口。该开发板的电源供应灵活,可通过USB VBUS或外部电源供电。此外,还配备了三个LED指示灯(LD1用于USB通信,LD2用于电源

指示,LD3为用户可控LED)和一个复位按钮。STM32 Nucleo-32开发板支持多种集成开发环境(IDEs),如IAR™、Keil®和基于GCC的IDE(如AC6 SW4STM32),使其成为开发人员的多功能工具。

Nucleo 32 with STM32F031K6 MCU double side image

微控制器概述 

MCU卡片 / MCU

default

建筑

ARM Cortex-M0

MCU 内存 (KB)

32

硅供应商

STMicroelectronics

引脚数

32

RAM (字节)

4096

你完善了我!

配件

Click Shield for Nucleo-32是扩展您的开发板功能的理想选择,专为STM32 Nucleo-32引脚布局设计。Click Shield for Nucleo-32提供了两个mikroBUS™插座,可以添加来自我们不断增长的Click板™系列中的任何功能。从传感器和WiFi收发器到电机控制和音频放大器,我们应有尽有。Click Shield for Nucleo-32与STM32 Nucleo-32开发板兼容,为用户提供了一种经济且灵活的方式,使用任何STM32微控制器快速创建原型,并尝试各种性能、功耗和功能的组合。STM32 Nucleo-32开发板无需任何独立的探针,因为它集成了ST-LINK/V2-1调试器/编程器,并随附STM32全面的软件HAL库和各种打包的软件示例。这个开发平台为用户提供了一种简便且通用的方式,将STM32 Nucleo-32兼容开发板与他们喜欢的Click板™结合,应用于即将开展的项目中。

Click Shield for Nucleo-32 accessories 1 image

使用的MCU引脚

mikroBUS™映射器

NC
NC
AN
Reset
PA11
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
Interrupt
PA12
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PB6
SCL
I2C Data
PB7
SDA
NC
NC
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

Air quality 8 Click Schematic schematic

一步一步来

项目组装

Click Shield for Nucleo-144 front image hardware assembly

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

Click Shield for Nucleo-144 front image hardware assembly
Nucleo 144 with STM32L4A6ZG MCU front image hardware assembly
2x4 RGB Click front image hardware assembly
Prog-cut hardware assembly
Nucleo-32 with STM32 MCU MB 1 - 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”替换为要显示的参数。

软件支持

库描述

该库包含 Air quality 8 Click 驱动程序的 API。

关键功能:

  • airquality8_calc_oaq - Air Quality 8 计算空气质量指数(AQI)功能

  • airquality8_read_rmox - Air Quality 8 计算rmox电阻功能

  • airquality8_start_measurement - Air Quality 8 开始测量功能

开源

代码示例

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

/*!
 * @file main.c
 * @brief AirQuality8 Click example
 *
 * # Description
 * This library contains API for Air Quality 8 Click driver.
 * The library initializes and defines the I2C bus drivers 
 * to write and read data from registers. 
 * The library also includes a function for configuring sensor and measurement, 
 * read and calculate mox resistance ( RMOX ) and air quality index ( AQI ), etc.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initialization of I2C module and log UART, and additional pins.
 * After the driver inits and executes a default configuration, 
 * the app read product ID and configuration parameters, 
 * initializes the sensor and measurement.
 *
 * ## Application Task
 * This is an example that demonstrates the use of the Air Quality 8 Click board™.
 * In this example, the app performs the start of the measurement,
 * reads an array of the 15 mox resistances measurements ( RMOX ), 
 * and calculates the air quality index ( AQI ), the app also, displays if an error occurs.
 * Results are being sent to the Usart Terminal where you can track their changes.
 *
 * ## Additional Function
 * - static void display_error ( void )
 *
 * @author Nenad Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "airquality8.h"

static airquality8_t airquality8;
static log_t logger;
static uint16_t mox_lr;
static uint16_t mox_er;
static uint8_t status_flag;

static void display_error ( void )
{
    if ( status_flag == AIRQUALITY8_ERROR_INIT_OUT_OF_RANGE )
    {
        log_printf( &logger, " The initialize value is out of range.\r\n" );
    }
    
    if ( status_flag == AIRQUALITY8_ERROR_GAS_TIMEOUT )
    {
        log_printf( &logger, " The operation took too long.\r\n" );
    }
    
    if ( status_flag == AIRQUALITY8_ERROR_I2C )
    {
        log_printf( &logger, " Failure in i2c communication.\r\n" );
    }
    
    if ( status_flag == AIRQUALITY8_ERROR_SENSOR_UNSUPPORTED )
    {
        log_printf( &logger, " Sensor is not supported with this firmware.\r\n" );
    }
    
    if ( status_flag == AIRQUALITY8_ERROR_CONFIG_MISSING )
    {
        log_printf( &logger, " There is no pointer to a valid configuration.\r\n" );
    }
    
    if ( status_flag == AIRQUALITY8_ERROR_SENSOR )
    {
        log_printf( &logger, " Sensor malfunction.\r\n" );
    }
}

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    airquality8_cfg_t airquality8_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.
    airquality8_cfg_setup( &airquality8_cfg );
    AIRQUALITY8_MAP_MIKROBUS( airquality8_cfg, MIKROBUS_1 );
    if ( I2C_MASTER_ERROR == airquality8_init( &airquality8, &airquality8_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( AIRQUALITY8_ERROR == airquality8_default_cfg ( &airquality8 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    Delay_ms( 100 );
    
    static uint8_t cfg_data[ 6 ];
    static uint8_t prod_data[ 5 ];
    static uint16_t pid;
    
    airquality8_get_sensor_info( &airquality8, &cfg_data[ 0 ], &prod_data[ 0 ], &pid );
    
    if ( pid != AIRQUALITY8_PRODUCT_ID )
    {
        status_flag = AIRQUALITY8_ERROR_I2C;
        display_error( );
        for ( ; ; );
    }
    Delay_ms( 100 );
    
    log_printf( &logger, "---------------------------\r\n" );
    log_printf( &logger, " Product ID : 0x%.2X  \r\n", pid );
    Delay_ms( 100 );
    
    airquality8_init_sensor( &airquality8, &mox_lr, &mox_er );
    Delay_ms( 10 );
    
    airquality8_init_measurement( &airquality8 );
    Delay_ms( 10 );
    
    log_printf( &logger, "---------------------------\r\n" );
    log_info( &logger, " Application Task " );
    log_printf( &logger, "---------------------------\r\n" );
    log_printf( &logger, "      Air Quality Index\r\n" );
    log_printf( &logger, "- - - - - - - - - - - - - -\r\n" );
    Delay_ms( 100 );
}

void application_task ( void ) 
{   
    static uint8_t status_data;
    static float rmox;
    static float rmox_seq[ 15 ];
    static float aqi;
    
    status_flag = airquality8_start_measurement( &airquality8 );

    airquality8_get_status( &airquality8, &status_data );
    Delay_ms( 10 );
    
    while ( ( status_data & AIRQUALITY8_STATUS_LAST_SEQ_STEP_MASK ) != AIRQUALITY8_OK )
    {
        airquality8_get_status( &airquality8, &status_data );
        Delay_ms( 10 );
    }

    for ( uint8_t n_cnt = 0; n_cnt < 15; n_cnt++ )
    {        
        status_flag = airquality8_read_rmox( &airquality8, &rmox, mox_lr, mox_er );
        rmox_seq[ n_cnt ] = rmox;
        Delay_ms( 100 ); 
        
        if ( status_flag != AIRQUALITY8_OK )
        {
            display_error( );
        }
    }       
    
    aqi = airquality8_calc_oaq( rmox_seq, AIRQUALITY8_RCDA_STRATEGY_ADJ, AIRQUALITY8_GAS_DETECTION_STRATEGY_AUTO );
    log_printf( &logger, " \tAQI : %.3f \r\n", aqi );
    log_printf( &logger, "---------------------------\r\n" );
    Delay_ms( 1000 );
}

void main ( void ) 
{
    application_init( );

    for ( ; ; ) 
    {
        application_task( );
    }
}

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

额外支持

资源

喜欢这个项目吗?

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