中级
30 分钟

使用 AS7263 和 PIC32MZ1024EFH064 精准发现真实色彩。

体验真实白色的光彩。

Spectral 3 Click with PIC32MZ clicker

已发布 6月 26, 2024

点击板

Spectral 3 Click

开发板

PIC32MZ clicker

编译器

NECTO Studio

微控制器单元

PIC32MZ1024EFH064

依靠我们的多光谱光感知解决方案,实现准确、可靠和实时的色彩白色检测,确保色彩质量达到最高标准。

A

A

硬件概览

它是如何工作的?

Spectral 3 Click基于AS7263,这是一个具有电子快门和智能接口的6通道近红外光谱识别器件。这是一个非常先进的多光谱传感器,它包含一个6个光电二极管阵列元素。每个光电元素都通过高斯滤波器进行滤波,这是通过纳米光学沉积干涉滤波器技术实现的,旨在为6个近红外光谱通道提供范围:R = 610nm,S = 680nm,T = 730nm,U = 760nm,V = 810nm和W = 860nm,每个通道的FWHM为20nm。滤波器的特性是用扩散的白光测试和测量的。这项技术确保读数的漂移和温度稳定性最小。应该注意,滤波器的准确性将受到入射角的影响,该角度由集成的光圈和内部微透镜确定,对于AS7263为±20°。光电元素的测量值由16位ADC转换器数字化,并由Spectral_ID引擎处理。除了六种颜色元素的原始值外,引擎还计算了此设备上可用的所有校准值,并将它们输出为32位浮点值。在指定的积分时间(最小为2.8ms)之后,这些值可在各自的寄存器中使用,并可通过由简单的AT命令驱动的智能高级UART接口,或I2C通信协议总线进行访问。甚至温度传感器也可以通过其寄存器访问。可以在AS7263数据手册中找到所有

可用颜色坐标和保存这些值的寄存器的完整列表。传感器数据组织成两个存储区。第一个存储区包含来自S、T、U和V光电二极管的读数,而第二个存储区包含来自R、T、U和W光电二极管的读数。不同的模式允许从每个存储区进行读取,以及这两个存储区之间的组合。还有一个用于一次性读取的模式,当需要进行时间关键或触发式测量时。上面的光电二极管字母代码代表各个波长的通道(通道R、通道S、通道T等)。当选择的存储区模式确定数据准备好由主机读取时,可以触发中断。如果启用了中断(INT = 1),则将INT线拉到LOW逻辑电平,并将控制寄存器的DATA_RDY位设置为1。当读取控制寄存器时,INT线将释放。每当读取测量寄存器时,DATA_RDY位都将被清除。根据所选择的存储区模式完成一个或多个积分周期后,将生成中断。AS7263的INT线被路由到mikroBUS™ INT引脚,并可用于在主机MCU上触发中断。有关存储区读取模式和中断的更多信息,请参阅提供的AS7263数据手册。传感器的RESET线被路由到mikroBUS™ RST引脚。如果将此线拉到LOW电平超过100毫秒,则将复位设备。传感器固件保存

在外部的辅助闪存存储器IC上。用于存储AS7263传感器固件的是AT25SF041,这是一种SPI串行闪存存储器。AT25SF041 IC通过SPI线与传感器通信,这些SPI线在Spectral 3 click上内部路由。AS7263传感器的UART和I2C线路被路由到mikroBUS™相应的UART引脚(RX/TX和SDA/SCL)。要选择将用于驱动传感器IC的接口,需要将三个标记为COM SEL的表面贴装器连接器移动到左侧位置(以启用UART)或右侧位置(以启用I2C)。应该注意,所有表面贴装器连接器都需要同时移动 - 如果其中一些设置为UART,而另一些设置为I2C,则通信可能根本不可能。AS7263传感器上有两个集成的可编程LED驱动器。第一个LED恒流驱动器可编程高达10mA,并可用作状态指示器。在传感器固件编程期间,它也被激活。第二个LED驱动器用于驱动测量表面照明的光源。它可以驱动高亮度LED,电流高达100mA。这两个LED驱动器都可以通过通信接口获得。

Spectral 3 Click hardware overview image

功能概述

开发板

PIC32MZ Clicker 是一款紧凑型入门开发板,它将 Click 板™的灵活性带给您喜爱的微控制器,使其成为实现您想法的完美入门套件。它配备了一款板载 32 位带有浮点单元的 Microchip PIC32MZ 微控制器,一个 USB 连接器,LED 指示灯,按钮,一个 mikroProg 连接器,以及一个用于与外部电子设备接口的头部。得益于其紧凑的设计和清晰易识别的丝网标记,它提供了流畅且沉浸式的工作体验,允许在任

何情况下、任何地方都能访问。PIC32MZ Clicker 开 发套件的每个部分都包含了使同一板块运行最高效的必要组件。除了可以选择 PIC32MZ Clicker 的编程方式,使用 USB HID mikroBootloader 或通过外部 mikroProg 连接器为 PIC,dsPIC 或 PIC32 编程外,Clicker 板还包括一个干净且调节过的开发套件电源供应模块。USB Micro-B 连接可以提供多达 500mA 的电流,这足以操作所有板载和附加模块。所有 

mikroBUS™ 本身支持的通信方法都在这块板上,包 括已经建立良好的 mikroBUS™ 插槽、重置按钮以及若干按钮和 LED 指示灯。PIC32MZ Clicker 是 Mikroe 生态系统的一个组成部分,允许您在几分钟内创建新的应用程序。它由 Mikroe 软件工具原生支持,得益于大量不同的 Click 板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作的许多方面。

PIC32MZ clicker double side image

微控制器概述 

MCU卡片 / MCU

default

建筑

PIC32

MCU 内存 (KB)

1024

硅供应商

Microchip

引脚数

64

RAM (字节)

524288

使用的MCU引脚

mikroBUS™映射器

NC
NC
AN
Reset
RE5
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
RB5
INT
UART TX
RB2
TX
UART RX
RB0
RX
I2C Clock
RD10
SCL
I2C Data
RD9
SDA
NC
NC
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

Spectral 3 Click Schematic schematic

一步一步来

项目组装

PIC32MZ clicker front image hardware assembly

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

PIC32MZ clicker front image hardware assembly
Thermo 26 Click front image hardware assembly
Prog-cut hardware assembly
Micro B Connector clicker - 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
Flip&Click PIC32MZ 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”替换为要显示的参数。

软件支持

库描述

这个库包含了Spectral 3 Click驱动程序的API。

关键函数:

  • spectral3_module_reset - 重置模块

  • spectral3_send_command - 发送命令

  • spectral3_get_data - 读取原始X、Y、Z和NIR数据,以及两个特殊的内部寄存器D和C。

开源

代码示例

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

/*!
 * \file 
 * \brief Spectral3 Click example
 * 
 * # Description
 * This example reads and processes data from Spectral 3 clicks.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes the driver and configures the sensor.
 * 
 * ## Application Task  
 * Reads the values of all 6 channels and parses it to the USB UART each second.
 * 
 * ## Additional Function
 * - spectral3_process ( ) - The general process of collecting the sensor responses.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "spectral3.h"
#include "string.h"

#define PROCESS_COUNTER 10
#define PROCESS_RX_BUFFER_SIZE 200
#define PROCESS_PARSER_BUFFER_SIZE 400

#define SPECTRAL3_CMD_DATA      "ATDATA"
#define SPECTRAL3_CMD_AT        "AT" 
#define SPECTRAL3_CMD_GAIN      "ATGAIN=2"
#define SPECTRAL3_CMD_MODE      "ATTCSMD=2"

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

static spectral3_t spectral3;
static log_t logger;

static char current_parser_buf[ PROCESS_PARSER_BUFFER_SIZE ];

// ------------------------------------------------------- ADDITIONAL FUNCTIONS

static void spectral3_process ( void )
{
    int32_t rsp_size;
    uint16_t rsp_cnt = 0;
    
    char uart_rx_buffer[ PROCESS_RX_BUFFER_SIZE ] = { 0 };
    uint8_t check_buf_cnt;
    uint8_t process_cnt = PROCESS_COUNTER;
    
    // Clear parser buffer
    memset( current_parser_buf, 0 , PROCESS_PARSER_BUFFER_SIZE ); 
    
    while( process_cnt != 0 )
    {
        rsp_size = spectral3_generic_read( &spectral3, &uart_rx_buffer, PROCESS_RX_BUFFER_SIZE );

        if ( rsp_size > 0 )
        {  
            // Validation of the received data
            for ( check_buf_cnt = 0; check_buf_cnt < rsp_size; check_buf_cnt++ )
            {
                if ( uart_rx_buffer[ check_buf_cnt ] == 0 ) 
                {
                    uart_rx_buffer[ check_buf_cnt ] = 13;
                }
            }
            
            // Storages data in parser buffer
            rsp_cnt += rsp_size;
            if ( rsp_cnt < PROCESS_PARSER_BUFFER_SIZE )
            {
                strncat( current_parser_buf, uart_rx_buffer, rsp_size );
            }
            
            // Clear RX buffer
            memset( uart_rx_buffer, 0, PROCESS_RX_BUFFER_SIZE );
        } 
        else 
        {
            process_cnt--;
            
            // Process delay 
            Delay_100ms( );
        }
    }
}

static void parser_application ( )
{  
    uint16_t read_data[ 6 ];

    spectral3_send_command( &spectral3, SPECTRAL3_CMD_DATA );
    spectral3_process( );

    spectral3_get_data( current_parser_buf, read_data );
 
    log_printf( &logger, "-- R value: %d \r\n", read_data[ 0 ] );   
    log_printf( &logger, "-- S value: %d \r\n", read_data[ 1 ] );
    log_printf( &logger, "-- T value: %d \r\n", read_data[ 2 ] );
    log_printf( &logger, "-- U value: %d \r\n", read_data[ 3 ] );
    log_printf( &logger, "-- V value: %d \r\n", read_data[ 4 ] );
    log_printf( &logger, "-- W value: %d \r\n", read_data[ 5 ] );
    log_printf( &logger, "-----------------\r\n" );
}

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

void application_init ( void )
{
    log_cfg_t log_cfg;
    spectral3_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.

    spectral3_cfg_setup( &cfg );
    SPECTRAL3_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    spectral3_init( &spectral3, &cfg );

    spectral3_module_reset( &spectral3 );
    Delay_ms ( 500 );
    
    log_printf( &logger, "Configuring the sensor...\r\n" );
    spectral3_send_command( &spectral3, SPECTRAL3_CMD_AT );
    spectral3_process( );
    spectral3_send_command( &spectral3, SPECTRAL3_CMD_GAIN );
    spectral3_process( );
    spectral3_send_command( &spectral3, SPECTRAL3_CMD_MODE );
    spectral3_process( );
    log_printf( &logger, "The sensor has been configured!\r\n" );
    Delay_ms ( 1000 );
}

void application_task ( void )
{
    parser_application( );
}

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
/*!
 * \file 
 * \brief Spectral3 Click example
 * 
 * # Description
 * This example reads and processes data from Spectral 3 clicks.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes the driver and configures the sensor.
 * 
 * ## Application Task  
 * Reads the values of all 6 channels and parses it to the USB UART each second.
 * 
 * ## Additional Function
 * - spectral3_process ( ) - The general process of collecting the sensor responses.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "spectral3.h"
#include "string.h"

#define PROCESS_COUNTER 10
#define PROCESS_RX_BUFFER_SIZE 200
#define PROCESS_PARSER_BUFFER_SIZE 400

#define SPECTRAL3_CMD_DATA      "ATDATA"
#define SPECTRAL3_CMD_AT        "AT" 
#define SPECTRAL3_CMD_GAIN      "ATGAIN=2"
#define SPECTRAL3_CMD_MODE      "ATTCSMD=2"

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

static spectral3_t spectral3;
static log_t logger;

static char current_parser_buf[ PROCESS_PARSER_BUFFER_SIZE ];

// ------------------------------------------------------- ADDITIONAL FUNCTIONS

static void spectral3_process ( void )
{
    int32_t rsp_size;
    uint16_t rsp_cnt = 0;
    
    char uart_rx_buffer[ PROCESS_RX_BUFFER_SIZE ] = { 0 };
    uint8_t check_buf_cnt;
    uint8_t process_cnt = PROCESS_COUNTER;
    
    // Clear parser buffer
    memset( current_parser_buf, 0 , PROCESS_PARSER_BUFFER_SIZE ); 
    
    while( process_cnt != 0 )
    {
        rsp_size = spectral3_generic_read( &spectral3, &uart_rx_buffer, PROCESS_RX_BUFFER_SIZE );

        if ( rsp_size > 0 )
        {  
            // Validation of the received data
            for ( check_buf_cnt = 0; check_buf_cnt < rsp_size; check_buf_cnt++ )
            {
                if ( uart_rx_buffer[ check_buf_cnt ] == 0 ) 
                {
                    uart_rx_buffer[ check_buf_cnt ] = 13;
                }
            }
            
            // Storages data in parser buffer
            rsp_cnt += rsp_size;
            if ( rsp_cnt < PROCESS_PARSER_BUFFER_SIZE )
            {
                strncat( current_parser_buf, uart_rx_buffer, rsp_size );
            }
            
            // Clear RX buffer
            memset( uart_rx_buffer, 0, PROCESS_RX_BUFFER_SIZE );
        } 
        else 
        {
            process_cnt--;
            
            // Process delay 
            Delay_100ms( );
        }
    }
}

static void parser_application ( )
{  
    uint16_t read_data[ 6 ];

    spectral3_send_command( &spectral3, SPECTRAL3_CMD_DATA );
    spectral3_process( );

    spectral3_get_data( current_parser_buf, read_data );
 
    log_printf( &logger, "-- R value: %d \r\n", read_data[ 0 ] );   
    log_printf( &logger, "-- S value: %d \r\n", read_data[ 1 ] );
    log_printf( &logger, "-- T value: %d \r\n", read_data[ 2 ] );
    log_printf( &logger, "-- U value: %d \r\n", read_data[ 3 ] );
    log_printf( &logger, "-- V value: %d \r\n", read_data[ 4 ] );
    log_printf( &logger, "-- W value: %d \r\n", read_data[ 5 ] );
    log_printf( &logger, "-----------------\r\n" );
}

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

void application_init ( void )
{
    log_cfg_t log_cfg;
    spectral3_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.

    spectral3_cfg_setup( &cfg );
    SPECTRAL3_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    spectral3_init( &spectral3, &cfg );

    spectral3_module_reset( &spectral3 );
    Delay_ms ( 500 );
    
    log_printf( &logger, "Configuring the sensor...\r\n" );
    spectral3_send_command( &spectral3, SPECTRAL3_CMD_AT );
    spectral3_process( );
    spectral3_send_command( &spectral3, SPECTRAL3_CMD_GAIN );
    spectral3_process( );
    spectral3_send_command( &spectral3, SPECTRAL3_CMD_MODE );
    spectral3_process( );
    log_printf( &logger, "The sensor has been configured!\r\n" );
    Delay_ms ( 1000 );
}

void application_task ( void )
{
    parser_application( );
}

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

额外支持

资源

喜欢这个项目吗?

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