spectrometer2  2.0.0.0
Main Page

Spectrometer 2 click

Spectrometer 2 Click is a compact add-on board that collects light waves. This board features the VD6283TX, a color sensor with advanced light flicker extraction from STMicroelectronics. The VD6283TX performs fast and accurate light measurements thanks to an individual ADC and a readout for each color channel - red, green, blue, IR, clear, and visible. It uses hybrid color filters with precise responses allowing accurate computation of the correlated color temperature (CCT) and Lux information. Its patented architecture and a high-performance photodiode design can also extract light-flickering frequencies to avoid banding effects or check that they are safe for the human eye.

click Product page


Click library

  • Author : Stefan Filipovic
  • Date : Apr 2022.
  • Type : I2C type

Software Support

We provide a library for the Spectrometer 2 Click as well as a demo application (example), developed using MikroElektronika compilers. The demo can run on all the main MikroElektronika development boards.

Package can be downloaded/installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Library Description

This library contains API for Spectrometer 2 Click driver.

Standard key functions :

Example key functions :

Example Description

This example demonstrates the use of Spectrometer 2 click board by reading data from 6 ALS channels and

converting them to HSL color and displaying those data as well as the detected color name on the USB UART.

The demo application is composed of two sections :

Application Init

Initializes the driver and performs the click default configuration.

void application_init ( void )
{
log_cfg_t log_cfg;
spectrometer2_cfg_t spectrometer2_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
spectrometer2_cfg_setup( &spectrometer2_cfg );
SPECTROMETER2_MAP_MIKROBUS( spectrometer2_cfg, MIKROBUS_1 );
if ( I2C_MASTER_ERROR == spectrometer2_init( &spectrometer2, &spectrometer2_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( SPECTROMETER2_ERROR == spectrometer2_default_cfg ( &spectrometer2 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}

Application Task

Waits for the data ready interrupt, then reads the values of all ALS channels and converts

them to HSL color and displays those data as well as the detected color name on the USB UART every 200ms approximately.

void application_task ( void )
{
// Wait for the data ready interrupt indication
while ( !spectrometer2_get_int_pin ( &spectrometer2 ) );
if ( ( SPECTROMETER2_OK == spectrometer2_clear_interrupt ( &spectrometer2 ) ) &&
( SPECTROMETER2_OK == spectrometer2_get_data ( &spectrometer2, &als_channels ) ) )
{
spectrometer2_rgbc_to_hsl( &als_channels, &hsl );
log_printf ( &logger, "\r\n Hue: %.1f deg\r\n", hsl.hue );
log_printf ( &logger, " Saturation: %.1f %%\r\n", hsl.saturation );
log_printf ( &logger, " Lightness: %.1f %%\r\n", hsl.lightness );
switch ( spectrometer2_get_color ( &hsl ) )
{
{
log_printf( &logger, " Color: RED\r\n" );
break;
}
{
log_printf( &logger, " Color: YELLOW\r\n" );
break;
}
{
log_printf( &logger, " Color: GREEN\r\n" );
break;
}
{
log_printf( &logger, " Color: CYAN\r\n" );
break;
}
{
log_printf( &logger, " Color: BLUE\r\n" );
break;
}
{
log_printf( &logger, " Color: MAGENTA\r\n" );
break;
}
{
log_printf( &logger, " Color: WHITE\r\n" );
break;
}
{
log_printf( &logger, " Color: BLACK\r\n" );
break;
}
default:
{
log_printf( &logger, " Color: UNKNOWN\r\n" );
break;
}
}
}
}

The full application code, and ready to use projects can be installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Other Mikroe Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.Spectrometer2

Additional notes and informations

Depending on the development board you are using, you may need USB UART click, USB UART 2 Click or RS232 Click to connect to your PC, for development systems with no UART to USB interface available on the board. UART terminal is available in all MikroElektronika compilers.


SPECTROMETER2_YELLOW_COLOR
#define SPECTROMETER2_YELLOW_COLOR
Definition: spectrometer2.h:206
spectrometer2_hsl_t
Spectrometer 2 HSL color data object.
Definition: spectrometer2.h:328
SPECTROMETER2_GREEN_COLOR
#define SPECTROMETER2_GREEN_COLOR
Definition: spectrometer2.h:207
spectrometer2_t
Spectrometer 2 Click context object.
Definition: spectrometer2.h:278
SPECTROMETER2_WHITE_COLOR
#define SPECTROMETER2_WHITE_COLOR
Definition: spectrometer2.h:211
spectrometer2_get_data
err_t spectrometer2_get_data(spectrometer2_t *ctx, spectrometer2_als_channels_t *als_channels)
Spectrometer 2 get data function.
spectrometer2_rgbc_to_hsl
void spectrometer2_rgbc_to_hsl(spectrometer2_als_channels_t *rgbc, spectrometer2_hsl_t *hsl)
Spectrometer 2 rgbc to hsl function.
SPECTROMETER2_BLACK_COLOR
#define SPECTROMETER2_BLACK_COLOR
Definition: spectrometer2.h:212
application_task
void application_task(void)
Definition: main.c:67
SPECTROMETER2_RED_COLOR
#define SPECTROMETER2_RED_COLOR
Definition: spectrometer2.h:205
SPECTROMETER2_ERROR
@ SPECTROMETER2_ERROR
Definition: spectrometer2.h:342
SPECTROMETER2_CYAN_COLOR
#define SPECTROMETER2_CYAN_COLOR
Definition: spectrometer2.h:208
SPECTROMETER2_BLUE_COLOR
#define SPECTROMETER2_BLUE_COLOR
Definition: spectrometer2.h:209
spectrometer2_get_color
uint8_t spectrometer2_get_color(spectrometer2_hsl_t *hsl)
Spectrometer 2 get color function.
spectrometer2_hsl_t::hue
float hue
Definition: spectrometer2.h:329
spectrometer2_hsl_t::lightness
float lightness
Definition: spectrometer2.h:331
spectrometer2_default_cfg
err_t spectrometer2_default_cfg(spectrometer2_t *ctx)
Spectrometer 2 default configuration function.
spectrometer2_get_int_pin
uint8_t spectrometer2_get_int_pin(spectrometer2_t *ctx)
Spectrometer 2 get int pin function.
SPECTROMETER2_MAP_MIKROBUS
#define SPECTROMETER2_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: spectrometer2.h:264
application_init
void application_init(void)
Definition: main.c:31
SPECTROMETER2_MAGENTA_COLOR
#define SPECTROMETER2_MAGENTA_COLOR
Definition: spectrometer2.h:210
spectrometer2_als_channels_t
Spectrometer 2 ALS channels data object.
Definition: spectrometer2.h:313
spectrometer2_hsl_t::saturation
float saturation
Definition: spectrometer2.h:330
spectrometer2_init
err_t spectrometer2_init(spectrometer2_t *ctx, spectrometer2_cfg_t *cfg)
Spectrometer 2 initialization function.
spectrometer2_clear_interrupt
err_t spectrometer2_clear_interrupt(spectrometer2_t *ctx)
Spectrometer 2 clear interrupt function.
spectrometer2_cfg_t
Spectrometer 2 Click configuration object.
Definition: spectrometer2.h:296
spectrometer2_cfg_setup
void spectrometer2_cfg_setup(spectrometer2_cfg_t *cfg)
Spectrometer 2 configuration object setup function.
SPECTROMETER2_OK
@ SPECTROMETER2_OK
Definition: spectrometer2.h:341