初学者
10 分钟

使用COM-09032和STM32L496AG实现精确自然的控制

提升您的HMI体验

THUMBSTICK Click with Discovery kit with STM32L496AG MCU

已发布 7月 22, 2025

点击板

THUMBSTICK Click

开发板

Discovery kit with STM32L496AG MCU

编译器

NECTO Studio

微控制器单元

STM32L496AG

实现游戏控制台和手柄的精确模拟控制,增强游戏体验,或者满足需要精确控制输入的应用,如机器人学或无人机导航系统。

A

A

硬件概览

它是如何工作的?

Thumbstick Click基于Sparkfun的COM-09032,这是一款高品质的2轴模拟型拇指杆。这种类型的拇指杆具有自动居中功能(弹簧回位),使其在释放时能够自动居中。它还包含一个舒适的杯状黑色旋钮/帽子,使其感觉像一个拇指杆,非常类似于流行游戏机(如PSP)手柄上使用的“模拟”摇杆。这个特性使它适用于众多应用作为人机界面。它由两个10kΩ电位器组成,一个用于上/下,另一个用于左/右方向,作为双可调电压分压器,在控制杆形式中提供2轴模拟输入。随

着拇指杆完全组装并工作,电压将随着拇指杆的移动 而变化。需要测量电位器阻值变化来读取拇指杆的物理位置。这就是为什么MCP3204,一款Microchip公司提供的具有高达100ksps转换速率的12位A/D转换器,通过与SPI协议兼容的简单串行接口连接拇指杆与mikroBUS™插座,以确定摇杆的X和Y的值。由于MCP3204的分辨率为12位,每个模拟通道(轴)上的值可以从0变化到4095。因此,如果杆在X轴上从一端移动到另一端,则X值将从0变化到4095,当沿Y轴移

动时也会发生类似的情况。拇指杆保持在中心位置的值大约为2048。此外,拇指杆具有一个按键功能,通过mikroBUS™插座的INT线向主机MCU发送中断信号。这个Click板™可以通过SMD跳线选择3.3V和5V逻辑电压电平运行。这样,3.3V和5V功能的MCU都可以正确使用通信线路。但是,Click板™配备了一个包含易于使用的功能和示例代码的库,可用作进一步开发的参考。

THUMBSTICK Click hardware overview 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
SPI Chip Select
PG11
CS
SPI Clock
PI1
SCK
SPI Data OUT
PD3
MISO
SPI Data IN
PI3
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Interrupt
PH2
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

THUMBSTICK 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

软件支持

库描述

这个库包含Thumbstick Click驱动的API。

关键函数:

  • thumbstick_button_state - 获取拇指杆按钮状态的函数

  • thumbstick_get_position - 通过轴函数获取拇指杆位置

开源

代码示例

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

/*!
 * \file 
 * \brief Thumbstick Click example
 * 
 * # Description
 * The demo application shows Clickboard axis postioning and button pressed.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initialization of Click board's and log's objects.
 * 
 * ## Application Task  
 * It reads the position of the thumbstick,
 *  - You will get data on log on every change of thumbstick axis position, or if you hold 
 *      thumbstick in one postion it will repeat the same log when timer reaches timeout.
 *  - You will get data on log whenever you press thumbstick button and release it.
 * 
 * \author Luka Filipovic
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "thumbstick.h"

// ------------------------------------------------------------------ VARIABLES

static thumbstick_t thumbstick;
static log_t logger;


static uint8_t old_butt_state;
static uint8_t button_state;

static thumbstick_position_t old_pos;
static thumbstick_position_t thumbstick_pos;

static uint16_t timer_cnt;
#define TIMER_FLAG 1000

static bool change_state;

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;
    thumbstick_cfg_t cfg;

    /** 
     * 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.

    thumbstick_cfg_setup( &cfg );
    THUMBSTICK_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    thumbstick_init( &thumbstick, &cfg );
    
    thumbstick_set_sensitivity( POSTION_SENS_DEFAULT );
    
    thumbstick_get_position( &thumbstick, &old_pos );
    old_butt_state = thumbstick_button_state( &thumbstick );
    timer_cnt = 0;
    change_state = false;
}

void application_task ( void )
{
    //Button pressed
    button_state = thumbstick_button_state( &thumbstick );

    if ( old_butt_state != button_state )
    {
        if ( button_state == THUMBSTICK_PRESS_BUTTON )
        {
            log_printf( &logger, ">> Button is pressed \r\n" );
            Delay_ms ( 100 );
        }
        else
        {
            log_printf( &logger, ">> Button is released \r\n" );
            Delay_ms ( 100 );
        }
        old_butt_state = button_state;
    }

    //Thumbstick postion
    thumbstick_get_position( &thumbstick, &thumbstick_pos );
    
    if ( ( old_pos.vertical != thumbstick_pos.vertical ) || ( timer_cnt >= TIMER_FLAG ) )
    {
        if ( thumbstick_pos.vertical == THUMBSTICK_POSITION_TOP )
        {
            log_printf( &logger, ">> TOP \r\n" );
            change_state = true;
        }
        else if ( thumbstick_pos.vertical == THUMBSTICK_POSITION_BOTTOM )
        {
            log_printf( &logger, ">> BOTTOM \r\n" );
            change_state = true;
        }
        
        old_pos = thumbstick_pos;
    }
    
    if ( (old_pos.horizontal != thumbstick_pos.horizontal ) || ( timer_cnt >= TIMER_FLAG )  )
    {
        if ( thumbstick_pos.horizontal == THUMBSTICK_POSITION_LEFT )
        {
            log_printf( &logger, ">> LEFT \r\n" );
            change_state = true;
        }
        else if ( thumbstick_pos.horizontal == THUMBSTICK_POSITION_RIGHT )
        {
            log_printf( &logger, ">> RIGHT \r\n" );
            change_state = true;
        }
        
        old_pos = thumbstick_pos;
    }
    
    if ( ( timer_cnt >= TIMER_FLAG ) || ( change_state == true )  )
    {
        timer_cnt = 0;
        change_state = false;
    }
    
    timer_cnt++;
    Delay_ms ( 1 );
}

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

额外支持

资源

喜欢这个项目吗?

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