中级
30 分钟

使用IQS550和STM32G431RB释放电容感应技术的力量

从触摸到手势

Touchpad 5 Click with Nucleo 64 with STM32G431RB MCU

已发布 11月 08, 2024

点击板

Touchpad 5 Click

开发板

Nucleo 64 with STM32G431RB MCU

编译器

NECTO Studio

微控制器单元

STM32G431RB

强大的投影电容控制器,可在任何环境中实现精确和自适应的触摸交互。

A

A

硬件概览

它是如何工作的?

Touchpad 5 Click 基于 Azoteq 公司的 IQS550,这是一款投影电容触摸和接近跟踪板/触摸屏控制器。IQS550 提供高灵敏度的接近唤醒和通过许多可由 I2C 控制的传感器线进行触摸检测。其先进的片上信号处理能力提供了稳定的高性能和高灵敏度。此外,实现了多个滤波器来检测和抑制噪声、跟踪缓慢变化的环境条件,并避免可能漂移的影响。IQS550 控制器非常灵活,提供了诸如接近、触摸、捕捉、触摸强度、面积和实际手指位置等多种输出,一次解决所有问题。在 Click boards™ 前端,一个清晰定义的区域代表触摸板区域。该区域是 PCB 上的一组导电电极的矩阵,彼此电气隔离,

排列为 X 和 Y 的行和列,尺寸为 29x23mm。一个电极由多个菱形元素组成,通过导电颈连接到下一个。控制器使用了在触摸板上的投影电容电荷传递原理。当诸如人类手指之类的导电物体靠近感应垫时,将会降低检测到的电容。对传感器数据应用阈值,以识别接近和触摸偏差区域。然后将触摸区域的轮廓转换为笛卡尔位置坐标,连续监测以识别手势。用户可以访问所有数据层——原始传感器数据、传感器接近/触摸状态数据、XY 坐标和手势输出。Touchpad 5 Click 使用标准 I2C 2 线接口与 MCU 进行通信,最大时钟频率为 400kHz,通过软件寄存器完全可调。在 

mikroBUS™ 插槽的 INT 引脚上添加了一个额外的准备信号,指示通信窗口何时可用新数据以获取最佳响应。因此,使用 INT 引脚作为通信触发器对响应速率是最佳的。除了该引脚之外,该 Click board™ 还具有一个复位功能,通过 mikroBUS™ 插槽上的 RST 引脚进行路由,其低逻辑电平可将模块置于复位状态,高电平可使模块正常运行。该 Click board™ 只能使用 3.3V 逻辑电压电平进行操作。在使用具有不同逻辑电平的 MCU 之前,板子必须执行适当的逻辑电压电平转换。然而,该 Click board™ 配备了一个包含函数和示例代码的库,可用作进一步开发的参考。

Touchpad 5 Click top side image
Touchpad 5 Click bottom side image

功能概述

开发板

Nucleo-64 搭载 STM32G431RB 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 STM32G431RB MCU double side image

微控制器概述 

MCU卡片 / MCU

STM32G431RB front image

建筑

ARM Cortex-M4

MCU 内存 (KB)

128

硅供应商

STMicroelectronics

引脚数

64

RAM (字节)

32k

你完善了我!

配件

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
Reset
PC12
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
PC14
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PB8
SCL
I2C Data
PB9
SDA
NC
NC
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

Touchpad 5 Click Schematic schematic

一步一步来

项目组装

Click Shield for Nucleo-64 accessories 1 image hardware assembly

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

Click Shield for Nucleo-64 accessories 1 image hardware assembly
Nucleo 64 with STM32G474RE MCU front image hardware assembly
BarGraph 5 Click front image hardware assembly
Prog-cut hardware assembly
Nucleo-64 with STM32GXXX MCU MB 1 Micro 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”替换为要显示的参数。

软件支持

库描述

该库包含 Touchpad 5 Click 驱动程序的 API。

关键功能:

  • touchpad5_get_touch - 这个函数获取触摸的 XY 数据。

  • touchpad5_get_status - 这个函数获取接近、触摸或捕获数据的状态。

  • touchpad5_wait_ready - 这个函数等待通信窗口可用。

开源

代码示例

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

/*!
 * @file main.c
 * @brief TouchPad5 Click example
 *
 * # Description
 * This example demonstrates the use of Touchpad 5 click board by utilizing the touchpad XY
 * and snap functionalities.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and USB UART logging and displays the device version information
 * such as product number, project number, major/minor release number, hardware ID, hardware
 * revision and bootloader status.
 *
 * ## Application Task
 * Task busy waits for the touchpad controller ready bit using polling operation. When the
 * communication window is available, the snap functionality is being checked, as well as 
 * XY touchpad data. Based on the user's touch sensibility and duration, one of the two 
 * features is being determined and logged over UART terminal. Snap (click) corresponds to
 * the shorter and lighter 'click' gesture, while the touch is detected as longer and 
 * stronger 'swipe' gesture.
 * 
 * @note This example relies on the IQS5xx-A000 firmware of the touch-pad controller.
 *
 * @author Stefan Popovic
 *
 */

#include "board.h"
#include "log.h"
#include "touchpad5.h"

// Snap buffer size
#define SNAP_BUFFER_SIZE                     ( 8 )

// Number of read channels for snap status
#define SNAP_NUMBER_OF_CHANNELS              ( 8 )

// Snap detection condition
#define SNAP_MAX_NO_CONSECUTIVE_SAMPLES      ( 3 )

// Touchpad strength threshold for XY touch detection
#define TOUCH_STRENGTH_THRESHOLD             ( 30 )

static touchpad5_t touchpad5;
static log_t logger;
static touchpad5_touch_t touch_data;
static touchpad5_ver_info_t ver_info;

// Bootloader status ( 0xA5 - present, 0xEE - not present )
static uint8_t bl_status = 0;

// Snap (click) support buffer and variables
static uint16_t snap_buffer[ SNAP_BUFFER_SIZE ] = { 0 }; 
static uint16_t snap_reference = 0;
static uint8_t snap_idx = 0;
static uint8_t tmp_count = 0;
static uint8_t snap_calc_no_samples = 0;
static uint16_t tmp_reference = 0;
static uint8_t snap_max_no_samples = SNAP_MAX_NO_CONSECUTIVE_SAMPLES;
static uint16_t snap_reg_data[ 2 * SNAP_NUMBER_OF_CHANNELS ] = { 0 };

/**
 * @brief TouchPad 5 snap sample getter.
 * @details This function gets the snap sample value as the averaged value of the predefined number of channels. 
 * @param[in] ctx : Click context object.
 * See #touchpad5_t object definition for detailed explanation.
 * @param[out] snap_data : Pointer to the memory location of the buffer where data is stored.
 * @return true  - Success,
 *         false - Error.
 *
 * @note Snap functionality must be enabled in control settings byte second byte.
 */
bool touchpad5_get_snap_sample( touchpad5_t *ctx, uint16_t *snap_data );

/**
 * @brief TouchPad 5 snap detection function.
 * @details This function checks for snap criteria defined by snap reference and predefined 
 * number of consecutive samples deviating from said reference.
 * @param[in] ctx : Click context object.
 * See #touchpad5_t object definition for detailed explanation.
 * @param[out] snap_buffer : Snap buffer with snap status data .
 * @param[in] snap_buffer_size : Buffer size of the 16-bit snap data.
 * @param[out] snap_reference : Pointer to the reference data calculated inside within each iteration.
 * @return true -  Snap detected,
 *         false - Snap not detected.
 *
 * @note Snap functionality must be enabled in control settings byte second byte.
 */
bool touchpad5_detect_snap( touchpad5_t *ctx, uint16_t *snap_buffer, uint8_t snap_buffer_size, uint16_t *snap_reference );

void application_init ( void ) 
{
    log_cfg_t log_cfg;                  /**< Logger config object. */
    touchpad5_cfg_t touchpad5_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.
    touchpad5_cfg_setup( &touchpad5_cfg );
    TOUCHPAD5_MAP_MIKROBUS( touchpad5_cfg, MIKROBUS_1 );
    if ( I2C_MASTER_ERROR == touchpad5_init( &touchpad5, &touchpad5_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    Delay_100ms();
    
    if ( TOUCHPAD5_ERROR == touchpad5_default_cfg ( &touchpad5 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    
    Delay_1sec( );
    
    if ( TOUCHPAD5_ERROR == touchpad5_check_version( &touchpad5, &ver_info ) )
    {
        log_error( &logger, " Cannot read version.\r\n " );
        for ( ; ; );
    }
    
    Delay_100ms();
    
    if ( TOUCHPAD5_ERROR == touchpad5_check_bl_status( &touchpad5, &bl_status ) )
    {
        log_error( &logger, " Cannot read bootloader status.\r\n " );
        for ( ; ; );
    }
    
    Delay_100ms();
    
    if ( ver_info.product_num != TOUCHPAD5_IQS550_PRODUCT_NUMBER ) 
    {
        log_error( &logger, " Incorrect product number.\r\n " );
        for ( ; ; );
    }
    
    log_printf( &logger, "----------------------------------------------------------------\r\n" );
    log_printf( &logger, " Product number %u \r\n",    ( uint32_t ) ver_info.product_num );
    log_printf( &logger, " Project number %u \r\n",    ( uint32_t ) ver_info.project_num );
    log_printf( &logger, " Version %.1f \r\n", ver_info.version );
    log_printf( &logger, " Hardware ID %x \r\n",       ( uint32_t ) ver_info.hw_id );
    log_printf( &logger, " Hardware revision %x \r\n", ( uint32_t ) ver_info.hw_revision );
    log_printf( &logger, " Bootloader status %x \r\n", ( uint16_t ) bl_status );
    log_printf( &logger, "----------------------------------------------------------------\r\n" );
    Delay_1sec( );
    log_printf( &logger, "----------------------------------------------------------------\r\n" );
    log_printf( &logger, " Waiting for a new touch or snap (click)\r\n" );
    log_printf( &logger, "----------------------------------------------------------------\r\n" );
    Delay_1sec( );
    log_info( &logger, " Application Task " );
}


void application_task ( void ) 
{
    // Get touchpad XY data
    touchpad5_get_touch( &touchpad5, &touch_data );
    
    // Detecting the snap (click) criteria
    if ( touchpad5_detect_snap( &touchpad5, snap_buffer, SNAP_BUFFER_SIZE, &snap_reference) && touch_data.touch_strength > 0 )
    {
        log_printf( &logger, "----------------------------------------------------------------\r\n" );
        log_printf( &logger, "\r\n* Snap (click) event occured with strength: %u *\r\n", 
                                                                        ( uint16_t ) touch_data.touch_strength ); 
        log_printf( &logger, "----------------------------------------------------------------\r\n" );
        Delay_1sec( );
    }
    // Detecting the touch criteria
    else if ( touch_data.x_pos > 0 && touch_data.y_pos > 0 && touch_data.touch_strength > TOUCH_STRENGTH_THRESHOLD )
    {
        
        log_printf( &logger, "----------------------------------------------------------------\r\n" );
        log_printf( &logger, " \r\nTouch with Tag ID %u detected\r\n",  ( uint16_t ) touch_data.id_tag );
        log_printf( &logger, "Coordinate X = %u \r\n",                               touch_data.x_pos );
        log_printf( &logger, "Coordinate Y = %u \r\n",                               touch_data.y_pos );
        log_printf( &logger, "Touch strength = %u  \r\n",               ( uint16_t ) touch_data.touch_strength );
        log_printf( &logger, "----------------------------------------------------------------\r\n\r\n" );
        Delay_ms( 100 );
    }
    
    // Monitoring to determine whether the reset occurred on the device after the last ack reset     
    if ( touch_data.xy_info & TOUCHPAD5_SHOW_RESET )
    {
        log_printf( &logger, "----------------------------------------------------------------\r\n" );
        log_error( &logger, "\r\n Unexpected reset occured. \r\n" ); 
        log_printf( &logger, "----------------------------------------------------------------\r\n\r\n" );
    }
}

void main ( void ) 
{
    application_init( );

    for ( ; ; ) 
    {
        application_task( );
    }
}
  
bool touchpad5_get_snap_sample( touchpad5_t *ctx, uint16_t *snap_data )
{
    bool status = false;
    uint16_t snap_reg_data_avg = 0;
    
    // Get snap status for desired number of channels
    if ( TOUCHPAD5_ERROR == touchpad5_get_status( ctx, TOUCHPAD5_SNAP_STATUS, &snap_reg_data, SNAP_NUMBER_OF_CHANNELS ) )
    {
        status = false; 
    }
    else
    {
        for ( int i = 0; i < SNAP_NUMBER_OF_CHANNELS; i++ )
        {
            snap_reg_data_avg += snap_reg_data[ i ];
        }
        snap_reg_data_avg /= SNAP_NUMBER_OF_CHANNELS;
        status = true;
    }
    
    *snap_data = snap_reg_data_avg;
    
    return status;
}

    
bool touchpad5_detect_snap( touchpad5_t *ctx, uint16_t *snap_buffer, uint8_t snap_buffer_size, uint16_t *snap_reference )
{
    bool status = false;
    
    snap_idx = 0;
    tmp_count = 0;
    tmp_reference = 0;
    snap_calc_no_samples = 0;
    
    // Get snap averaged samples
    for ( int i = 0; i < snap_buffer_size; i++ )
    {
        if ( false == touchpad5_get_snap_sample( ctx, &snap_buffer[ snap_idx ] ) )
        {

            return status;
        }

        ++snap_idx;
    }
    
    // Update reference value
    tmp_reference = snap_buffer[ 0 ];
    snap_idx = 1;
    while ( snap_idx < snap_buffer_size )
    {
        if ( snap_buffer[ snap_idx++ ] == tmp_reference )
        {
            ++tmp_count;
        }
    }
    
    if ( tmp_count == snap_buffer_size - 1 )
    {
        *snap_reference = tmp_reference;
    }


    // Snap detection algorithm - detecting 1 to snap_max_no_samples for confirmed snap
    for ( int i = 0; i < snap_buffer_size; i++ )
    {
        // first snapped index saved
        if ( snap_buffer[ i ] != *snap_reference )
        {
            snap_idx = i;
            ++snap_calc_no_samples;
        }
    }

    for( int i = snap_idx; i < snap_buffer_size; i++)
    {
        if ( snap_buffer[ ( i + 1 ) % snap_buffer_size] != *snap_reference ) 
        {
            ++snap_calc_no_samples;
        }
        else
        {
            snap_calc_no_samples = 0;
        }
    }
    
    if ( snap_calc_no_samples >= 1 && snap_calc_no_samples <= snap_max_no_samples )
    {
        status =  true; 
    }

    return status;
}

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

额外支持

资源

喜欢这个项目吗?

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