Intermediate
30 min

Discover true colors with pinpoint chromatic accuracy using AS7263 and ATmega324A

Experience the brilliance of true whites

Spectral 3 Click with EasyAVR v8

Published Jul 11, 2024

Click board™

Spectral 3 Click

Dev. board

EasyAVR v8

Compiler

NECTO Studio

MCU

ATmega324A

Count on our multispectral light sensing solution for accurate, reliable, and real-time chromatic white color detection, ensuring the highest standards of color quality

A

A

Hardware Overview

How does it work?

Spectral 3 Click is based on the AS7263, a 6 channel NIR Spectral_ID device with electronic shutter and smart Interface. This is a very advanced multispectral sensor, which incorporates 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 provide ranges for 6 near-IR spectral channels: R = 610nm, S = 680nm, T = 730nm, U = 760nm, V = 810nm and W = 860nm, each with 20nm FWHM. The filter characteristics are tested and measured with the diffused white light. This technology ensures minimal drift of the readings and 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° for the AS7263. The measurements from the photo elements are digitized by the 16bit ADC converter and processed by the Spectral_ID engine. Besides the raw values of the six color elements, the engine calculates all the calibrated values available on this device and outputs them as 32bit float values. After the specified integration time (2.8ms min), 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 AS7263 datasheet. The sensor data is organized in two banks. The first bank contains readings from the S, T, U and V photodiodes, while the second bank contains readings from the R, T, U, and W 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. The photodiode letter codes above, represent the channels of the respective wavelengths (Channel R, Channel S, Channel T, and more). An interrupt can be triggered when the data is ready to be read by the host, 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 is read. The DATA_RDY bit will be cleared whenever the measurement registers are read. The interrupt will be generated after one or more integrating cycles are completed, depending on the selected bank mode. The INT line of the AS7263 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 AS7263 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 AS7263 sensor. The AT25SF041 IC communicates with the sensor via the SPI lines, internally routed on the Spectral 3 click. UART and I2C lines of the AS7263 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 AS7263 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 3 Click hardware overview image

Features overview

Development board

EasyAVR v8 is a development board designed to rapidly develop embedded applications based on 8-bit AVR microcontrollers (MCUs). Redesigned from the ground up, EasyAVR v8 offers a familiar set of standard features, as well as some new and unique features standard for the 8th generation of development boards: programming and debugging over the WiFi network, connectivity provided by USB-C connectors, support for a wide range of different MCUs, and more. The development board is designed so that the developer has everything that might be needed for the application development, following the Swiss Army knife concept: a highly advanced programmer/debugger module, a reliable power supply module, and a USB-UART connectivity option. EasyAVR v8 board offers several different DIP sockets, covering a wide range of 8-bit AVR MCUs, from the smallest

AVR MCU devices with only eight pins, all the way up to 40-pin "giants". The development board supports the well-established mikroBUS™ connectivity standard, offering five mikroBUS™ sockets, allowing access to a huge base of Click boards™. EasyAVR v8 offers two display options, allowing even the basic 8-bit AVR MCU devices to utilize them and display graphical or textual content. One of them is the 1x20 graphical display connector, compatible with the familiar Graphical Liquid Crystal Display (GLCD) based on the KS108 (or compatible) display driver, and EasyTFT board that contains TFT Color Display MI0283QT-9A, which is driven by ILI9341 display controller, capable of showing advanced graphical content. The other option is the 2x16 character LCD module, a four-bit display module with an embedded character-based display controller. It

requires minimal processing power from the host MCU for its operation. There is a wide range of useful interactive options at the disposal: high-quality buttons with selectable press levels, LEDs, pull-up/pulldown DIP switches, and more. All these features are packed on a single development board, which uses innovative manufacturing technologies, delivering a fluid and immersive working experience. The EasyAVR v8 development board is also integral to the MIKROE rapid development ecosystem. Natively supported by the MIKROE Software toolchain, backed up by hundreds of different Click board™ designs with their number growing daily, it covers many different prototyping and development aspects, thus saving precious development time.

EasyAVR v8 horizontal image

Microcontroller Overview

MCU Card / MCU

default

Architecture

AVR

MCU Memory (KB)

32

Silicon Vendor

Microchip

Pin count

40

RAM (Bytes)

2048

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Reset
PA4
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
UART TX
PD1
TX
UART RX
PD0
RX
I2C Clock
PC0
SCL
I2C Data
PC1
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

Spectral 3 Click Schematic schematic

Step by step

Project assembly

EasyAVR v8 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the EasyAVR v8 as your development board.

EasyAVR v8 front image hardware assembly
Stepper 24 Click front image hardware assembly
EasyAVR v8 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

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 3 Click driver.

Key functions:

  • spectral3_module_reset - Reset module

  • spectral3_send_command - Send command

  • spectral3_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 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

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.