Intermediate
30 min

Count on reliable white color detection with AS7261 and MK64FN1M0VDC12

Mastering chromatic white sensing with us!

Spectral Click with Clicker 2 for Kinetis

Published Sep 21, 2023

Click board™

Spectral Click

Dev. board

Clicker 2 for Kinetis

Compiler

NECTO Studio

MCU

MK64FN1M0VDC12

Experience the brilliance of true whites and the subtlety of chromatic nuances through our multispectral color sensing technology

A

A

Hardware Overview

How does it work?

Spectral Click is based on the AS7261, an XYZ chromatic white color sensor + NIR with electronic shutter and smart interface. This is a very advanced multispectral sensor, which integrates a 6 photodiodes array element. Every photo element is filtered through the Gaussian filters, implemented through the nano-optic deposited interference filter technology, designed to meet the X, Y, Z standard observer filter characteristics, compliant with the CIE 1931 standard. This technology ensures minimal drift of the color readings and the temperature stability. It should be noted that the filter accuracy will be affected by the angle of incidence, determined by an integrated aperture and the internal microlenses, which is ±20.5° for the AS7261. The measurements from the photo elements are digitized by the 16bit ADC converter and processed by the Cognitive Light Engine (CLE). Besides the raw X, Y and Z values, the CLE calculates all the calibrated and mapped values available on this device. After the specified integration time, those values are available in their respective registers and are accessible via the smart high-level UART interface driven by simple AT commands, or the I2C communication protocol bus. Even the temperature sensor can be accessed via its register. A complete list of all the available color

coordinates and the registers which hold these values can be found in the AS7261 datasheet. The sensor data is organized in two banks. The first bank contains readings from the X, Y, Z and NIR photodiodes, while the second bank contains readings from the X, Y, Z photodiodes, as well as D (dark), and C (clear) photodiodes. Different modes allow readings to be made from each bank, as well as the combinations between these two banks. There is also a mode for one-shot reading when time-critical or triggered measurement needs to be made. An interrupt can be triggered when the data is ready for reading, depending on the selected bank mode. If the interrupt is enabled (INT = 1), the INT line is pulled to a LOW logic level and DATA_RDY bit of the control register is set to 1. The INT line is released when the control register has been read. The DATA_RDY bit will be cleared whenever the measurement registers are read. An interrupt will be generated after one or more integrating cycles are completed, depending on the selected bank mode. The INT line of the AS7261 is routed to the mikroBUS™ INT pin and can be used to trigger an interrupt on the host MCU. More about bank reading modes and the interrupts can be found in the provided AS7261 datasheet. The RESET line of the sensor is routed to the mikroBUS™ RST pin. If this line is pulled to a

LOW level for more than 100ms, it will reset the device. The sensor firmware is kept externally, on the auxiliary flash memory IC. The AT25SF041, an SPI serial flash memory is used for storing the firmware of the AS7261 sensor. The AT25SF041 IC communicates with the sensor via the SPI lines, internally routed on the Spectral click itself. UART and I2C lines of the AS7261 sensor are routed to the mikroBUS™ respective UART pins (RX/TX and SDA/SCL). To select which interface will be used to drive the sensor IC, three onboard SMD jumpers labeled as COM SEL need to be moved either to the left position (to enable UART) or to the right position (to enable I2C). It should be noted that all the SMD jumpers need to be moved at once - if some of them are set as UART and some as I2C, the communication might not be possible at all. There are two integrated programmable LED drivers on the AS7261 sensor. The first LED constant current driver can be programmed up to 10mA and it can be used as the status indicator. It is also activated during the sensor firmware programming. The second LED driver is intended for driving of the light source for the measurement surface illumination. It can drive high brightness LED with up to 100mA. Both of these LED drivers are available through the communication interfaces.

Spectral Click hardware overview image

Features overview

Development board

Clicker 2 for Kinetis is a compact starter development board that brings the flexibility of add-on Click boards™ to your favorite microcontroller, making it a perfect starter kit for implementing your ideas. It comes with an onboard 32-bit ARM Cortex-M4F microcontroller, the MK64FN1M0VDC12 from NXP Semiconductors, two mikroBUS™ sockets for Click board™ connectivity, a USB connector, LED indicators, buttons, a JTAG programmer connector, and two 26-pin headers for interfacing with external electronics. Its compact design with clear and easily recognizable silkscreen markings allows you to build gadgets with unique functionalities and

features quickly. Each part of the Clicker 2 for Kinetis development kit contains the components necessary for the most efficient operation of the same board. In addition to the possibility of choosing the Clicker 2 for Kinetis programming method, using a USB HID mikroBootloader or an external mikroProg connector for Kinetis programmer, the Clicker 2 board also includes a clean and regulated power supply module for the development kit. It provides two ways of board-powering; through the USB Micro-B cable, where onboard voltage regulators provide the appropriate voltage levels to each component on the board, or

using a Li-Polymer battery via an onboard battery connector. All communication methods that mikroBUS™ itself supports are on this board, including the well-established mikroBUS™ socket, reset button, and several user-configurable buttons and LED indicators. Clicker 2 for Kinetis is an integral part of the Mikroe ecosystem, allowing you to create a new application in minutes. Natively supported by Mikroe software tools, it covers many aspects of prototyping thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

Clicker 2 for Kinetis dimensions image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M4

MCU Memory (KB)

1024

Silicon Vendor

NXP

Pin count

121

RAM (Bytes)

262144

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Reset
PB11
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
PB13
INT
UART TX
PD3
TX
UART RX
PD2
RX
I2C Clock
PD8
SCL
I2C Data
PD9
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

Spectral Click Schematic schematic

Step by step

Project assembly

Clicker 2 for PIC32MZ front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Clicker 2 for Kinetis as your development board.

Clicker 2 for PIC32MZ front image hardware assembly
GNSS2 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
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

Track your results in real time

Application Output

1. Application Output - In Debug mode, the 'Application Output' window enables real-time data monitoring, offering direct insight into execution results. Ensure proper data display by configuring the environment correctly using the provided tutorial.

2. UART Terminal - Use the UART Terminal to monitor data transmission via a USB to UART converter, allowing direct communication between the Click board™ and your development system. Configure the baud rate and other serial settings according to your project's requirements to ensure proper functionality. For step-by-step setup instructions, refer to the provided tutorial.

3. Plot Output - The Plot feature offers a powerful way to visualize real-time sensor data, enabling trend analysis, debugging, and comparison of multiple data points. To set it up correctly, follow the provided tutorial, which includes a step-by-step example of using the Plot feature to display Click board™ readings. To use the Plot feature in your code, use the function: plot(*insert_graph_name*, variable_name);. This is a general format, and it is up to the user to replace 'insert_graph_name' with the actual graph name and 'variable_name' with the parameter to be displayed.

Software Support

Library Description

This library contains API for Spectral Click driver.

Key functions:

  • spectral_uart_read - Generic read function

  • spectral_send_command - Send Command

  • spectral_get_data - Read raw X, Y, Z and NIR data as well as two special internal registers D, & C.

Open Source

Code example

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.

/*!
 * \file 
 * \brief Spectral Click example
 * 
 * # Description
 * This example reads and processes data from Spectral 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
 * - spectral_process ( ) - The general process of collecting the sensor responses.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

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

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

#define SPECTRAL_CMD_DATA           "ATDATA"
#define SPECTRAL_CMD_AT             "AT" 
#define SPECTRAL_CMD_GAIN           "ATGAIN=2"
#define SPECTRAL_CMD_MODE           "ATTCSMD=2"

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

static spectral_t spectral;
static log_t logger;

static uint8_t current_parser_buf[ PROCESS_PARSER_BUFFER_SIZE ];

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

void spectral_process ( void )
{
    int32_t rsp_size = 0;
    uint16_t rsp_cnt = 0;
    
    uint8_t uart_rx_buffer[ PROCESS_RX_BUFFER_SIZE ] = { 0 };
    uint8_t check_buf_cnt = 0;
    uint8_t process_cnt = PROCESS_COUNTER;
    
    // Clear parser buffer
    memset( current_parser_buf, 0, PROCESS_PARSER_BUFFER_SIZE ); 
    
    while ( process_cnt )
    {
        rsp_size = spectral_uart_read( &spectral, 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( );
        }
    }
}

void parser_application ( )
{
    uint16_t read_data[ 6 ] = { 0 };
    spectral_send_command( &spectral, SPECTRAL_CMD_DATA );
    spectral_process( );
    
    spectral_get_data( current_parser_buf, read_data );
    
    log_printf( &logger, "-- X value: %d\r\n", read_data[ 0 ] );    
    log_printf( &logger, "-- Y value: %d\r\n", read_data[ 1 ] );  
    log_printf( &logger, "-- Z value: %d\r\n", read_data[ 2 ] ); 
    log_printf( &logger, "-- NIR value: %d\r\n", read_data[ 3 ] );
    log_printf( &logger, "-- D value: %d\r\n", read_data[ 4 ] );
    log_printf( &logger, "-- C value: %d\r\n", read_data[ 5 ] );
    log_printf( &logger, "-----------------\r\n" );
}

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

void application_init ( void )
{
    log_cfg_t log_cfg;
    spectral_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.
    spectral_cfg_setup( &cfg );
    SPECTRAL_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    spectral_init( &spectral, &cfg );

    spectral_module_reset( &spectral );
    Delay_ms ( 500 );

    log_printf( &logger, "Configuring the sensor...\r\n" );
    spectral_send_command( &spectral, SPECTRAL_CMD_AT );
    spectral_process( );
    spectral_send_command( &spectral, SPECTRAL_CMD_GAIN );
    spectral_process( );
    spectral_send_command( &spectral, SPECTRAL_CMD_MODE );
    spectral_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

Additional Support

Resources

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.