中级
30 分钟

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

从触摸到手势

Touchpad 5 Click with EasyAVR v7

已发布 6月 25, 2024

点击板

Touchpad 5 Click

开发板

EasyAVR v7

编译器

NECTO Studio

微控制器单元

ATmega644

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

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

功能概述

开发板

EasyAVR v7 是第七代AVR开发板,专为快速开发嵌入式应用的需求而设计。它支持广泛的16位AVR微控制器,来自Microchip,并具有一系列独特功能,如强大的板载mikroProg程序员和通过USB的在线电路调试器。开发板布局合理,设计周到,使得最终用户可以在一个地方找到所有必要的元素,如开关、按钮、指示灯、连接器等。EasyAVR v7 通过每个端口的四种不同连接器,比以往更高效地连接附件板、传感器和自定义电子产品。EasyAVR v7 开发板的每个部分

都包含了使同一板块运行最高效的必要组件。一个集成的mikroProg,一个快速的USB 2.0程序员,带有mikroICD硬件在线电路调试器,提供许多有价值的编 程/调试选项和与Mikroe软件环境的无缝集成。除此之外,它还包括一个干净且调节过的开发板电源供应模块。它可以使用广泛的外部电源,包括外部12V电源供应,7-12V交流或9-15V直流通过DC连接器/螺丝端子,以及通过USB Type-B(USB-B)连接器的电源。通信选项如USB-UART和RS-232也包括在内,与

广受好评的mikroBUS™标准、三种显示选项(7段、图形和基于字符的LCD)和几种不同的DIP插座一起,覆盖了广泛的16位AVR MCU。EasyAVR v7 是Mikroe快速开发生态系统的一个组成部分。它由Mikroe软件工具原生支持,得益于大量不同的Click板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作和开发的许多方面。

EasyAVR v7 horizontal image

微控制器概述 

MCU卡片 / MCU

ATmega644

建筑

AVR

MCU 内存 (KB)

64

硅供应商

Microchip

引脚数

40

RAM (字节)

4096

使用的MCU引脚

mikroBUS™映射器

NC
NC
AN
Reset
PA6
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
PD2
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PC0
SCL
I2C Data
PC1
SDA
NC
NC
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

Touchpad 5 Click Schematic schematic

一步一步来

项目组装

EasyAVR v7 front image hardware assembly

从选择您的开发板和Click板™开始。以EasyAVR v7作为您的开发板开始。

EasyAVR v7 front image hardware assembly
GNSS2 Click front image hardware assembly
EasyAVR v7 Access DIP 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 Compiler Selection Step Image hardware assembly
NECTO Output Selection Step Image hardware assembly
Necto image step 6 hardware assembly
Necto DIP image step 7 hardware assembly
EasyPIC PRO v7a Display Selection Necto Step hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto PreFlash Image 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" );
    }
}

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;
}
  
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

额外支持

资源

喜欢这个项目吗?

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