初学者
10 分钟

使用LV30条码扫描器和STM32L496AG从各种介质捕获和解码条码

出色屏幕代码扫描性能的OEM扫描引擎

Barcode 3 Click with Discovery kit with STM32L496AG MCU

已发布 7月 22, 2025

点击板

Barcode 3 Click

开发板

Discovery kit with STM32L496AG MCU

编译器

NECTO Studio

微控制器单元

STM32L496AG

读取各种 1D 和 2D 条码类型,包括 QR 码、数据矩阵和线性条码

A

A

硬件概览

它是如何工作的?

Barcode 3 Click 基于 Rakinda 的 LV30 影像引擎,旨在实现高效的条码扫描。该组件具有激光瞄准系统和 LED 照明系统,符合 IEC 62471:2006 LED 安全标准和 IEC 60825:2014 激光安全标准。LV30 集成了 CMOS 图像传感器和复杂的图像识别系统芯片,能够快速准确地解码纸张、磁卡等多种介质上的条码。此多功能引擎可以轻松集成到OEM设备中,例如手持、便携或固定式条码扫描仪,使其成为从1D升级到2D条码扫描解决方案的绝佳选择。LV30 配备了红色 LED(波长:625±10nm)用于额外照明,即使在完全黑暗中也能进行条码扫描,并可选择开启或关闭照明。它还包括一个激光瞄准器,帮助用户准确定位条码扫描区域,提高效率。瞄准模式可以开启或关闭,建议在扫描过程中保持开启以获得更好的准确性。使用 

Barcode 3 Click 通过特定表面进行扫描时,必须确保适当防护,以防灰尘和其他可能降低 LV30 模块性能的污染物。扫描表面必须由透明材料制成;建议使用细胞铸造塑料或光学玻璃,如 PMMA、ADC 或化学钢化玻璃。虽然 LV30 在环境光下表现良好,但暴露于高频脉冲光会对其性能产生负面影响。LV30 中的照明 LED 非常明亮,但在正常使用条件下设计为安全。然而,用户应避免直接眼睛暴露于光束。LV30 的物理接口包括一个 12 针 FPC 连接器,该连接器允许 Barcode 3 Click 使用 12 线 0.5mm 间距的 FPC 电缆连接到主机 MCU。此设置支持通过 UART 接口(mikroBUS™ 插座的 TX 和 RX 引脚)或 USB 接口 进行通信。由于 LV30 在 3.3V 下工作,因此在使用 USB 接口时,通过额外的低压差(LDO)稳压器

TLV700 提供必要的电源,将 USB 电压水平转换为 LV30 所需的 3.3V。Barcode 3 Click 还具有多个其他组件以增强其功能。板载蜂鸣器为用户提供听觉反馈,指示电源开启和成功读取状态。蓝色 READ OK LED 指示灯信号成功读取条码。按下并释放 READ 按钮会激活扫描,直到解码条码或解码会话超时过期。此功能还可以通过 mikroBUS™ 插座上的 TRG 引脚实现。此外,板上还包括一个 RESET 按钮用于重置 LV30,也可以通过 mikroBUS™ 插座上的 RST 引脚操作。此 Click board™ 只能在 3.3V 逻辑电压水平下操作。在使用具有不同逻辑电平的 MCU 之前,必须执行适当的逻辑电压电平转换。此外,它配备了包含功能和示例代码的库,可作为进一步开发的参考。

Barcode 3 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
Reset
PB2
RST
ID COMM
PG11
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Scan Trigger
PA0
PWM
NC
NC
INT
UART TX
PG10
TX
UART RX
PB6
RX
NC
NC
SCL
NC
NC
SDA
NC
NC
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

Barcode 3 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

实时跟踪您的结果

应用程序输出

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”替换为要显示的参数。

软件支持

库描述

该库包含 Barcode 3 Click 驱动程序的 API。

关键功能:

  • barcode3_generic_read - 此函数通过使用UART串行接口读取所需数量的数据字节。

  • barcode3_start_scanning - 此函数通过将TRG引脚设置为低逻辑状态来启动条码扫描。

  • barcode3_stop_scanning - 此函数通过将TRG引脚设置为高逻辑状态来停止条码扫描。

开源

代码示例

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

/*!
 * @file main.c
 * @brief Barcode 3 Click Example.
 *
 * # Description
 * This example demonstrates the use of the Barcode 3 Click board by scanning
 * and displaying the content of a barcode or QR Code.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver, stops scanning and resets the barcode device.
 *
 * ## Application Task
 * Triggers scanning and waits up to 3 seconds for the barcode to be detected.
 * If a barcode or QR Code is detected, it displays its content on the USB UART.
 *
 * ## Additional Function
 * - static void barcode3_clear_app_buf ( void )
 * - static void barcode3_log_app_buf ( void )
 * - static err_t barcode3_process ( barcode3_t *ctx )
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "barcode3.h"

// Application buffer size
#define APP_BUFFER_SIZE             500
#define PROCESS_BUFFER_SIZE         200

static barcode3_t barcode3;
static log_t logger;

static uint8_t app_buf[ APP_BUFFER_SIZE ] = { 0 };
static int32_t app_buf_len = 0;

/**
 * @brief Barcode 3 clearing application buffer.
 * @details This function clears memory of application buffer and reset its length.
 * @note None.
 */
static void barcode3_clear_app_buf ( void );

/**
 * @brief Barcode 3 log application buffer.
 * @details This function logs data from application buffer to USB UART.
 * @note None.
 */
static void barcode3_log_app_buf ( void );

/**
 * @brief Barcode 3 data reading function.
 * @details This function reads data from device and concatenates data to application buffer. 
 * @param[in] ctx : Click context object.
 * See #barcode3_t object definition for detailed explanation.
 * @return @li @c  0 - Read some data.
 *         @li @c -1 - Nothing is read.
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t barcode3_process ( barcode3_t *ctx );

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    barcode3_cfg_t barcode3_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.
    barcode3_cfg_setup( &barcode3_cfg );
    BARCODE3_MAP_MIKROBUS( barcode3_cfg, MIKROBUS_1 );
    if ( UART_ERROR == barcode3_init( &barcode3, &barcode3_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    barcode3_stop_scanning ( &barcode3 );
    barcode3_reset_device ( &barcode3 );
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    uint16_t timeout = 0;
    log_printf( &logger, "\r\n------- SCAN START ------\r\n" );
    barcode3_start_scanning ( &barcode3 );
    while ( ++timeout < 3000 )
    {
        if ( BARCODE3_OK == barcode3_process( &barcode3 ) )
        {
            barcode3_log_app_buf( );
            barcode3_clear_app_buf( );
            Delay_10ms ( );
            while ( BARCODE3_OK == barcode3_process( &barcode3 ) )
            {
                barcode3_log_app_buf( );
                barcode3_clear_app_buf( );
                Delay_10ms ( );
            }
            break;
        }
        Delay_1ms ( );
    }
    log_printf( &logger, "------- SCAN STOP -------\r\n" );
    barcode3_stop_scanning ( &barcode3 );
    Delay_ms ( 1000 );
    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;
}

static void barcode3_clear_app_buf ( void ) 
{
    memset( app_buf, 0, app_buf_len );
    app_buf_len = 0;
}

static void barcode3_log_app_buf ( void )
{
    for ( int32_t buf_cnt = 0; buf_cnt < app_buf_len; buf_cnt++ )
    {
        log_printf( &logger, "%c", app_buf[ buf_cnt ] );
    }
}

static err_t barcode3_process ( barcode3_t *ctx ) 
{
    uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
    int32_t overflow_bytes = 0;
    int32_t rx_cnt = 0;
    int32_t rx_size = barcode3_generic_read( ctx, rx_buf, PROCESS_BUFFER_SIZE );
    if ( ( rx_size > 0 ) && ( rx_size <= APP_BUFFER_SIZE ) ) 
    {
        if ( ( app_buf_len + rx_size ) > APP_BUFFER_SIZE ) 
        {
            overflow_bytes = ( app_buf_len + rx_size ) - APP_BUFFER_SIZE;
            app_buf_len = APP_BUFFER_SIZE - rx_size;
            memmove ( app_buf, &app_buf[ overflow_bytes ], app_buf_len );
            memset ( &app_buf[ app_buf_len ], 0, overflow_bytes );
        }
        for ( rx_cnt = 0; rx_cnt < rx_size; rx_cnt++ ) 
        {
            if ( rx_buf[ rx_cnt ] ) 
            {
                app_buf[ app_buf_len++ ] = rx_buf[ rx_cnt ];
            }
        }
        return BARCODE3_OK;
    }
    return BARCODE3_ERROR;
}

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

额外支持

资源

喜欢这个项目吗?

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