color16  2.1.0.0
Main Page

Color 16 click

PRVIH_PAR_RECENICA_SA_PRODUCT_PAGE_DA_ISPRATE_CELINU

[click Product page](CLICK_PRODUCT_PAGE_LINK)


Click library

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

Software Support

We provide a library for the Color 16 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 Color 16 Click driver.

Standard key functions :

Example key functions :

  • color16_read_data This function checks if the spectral measurement data is ready and then reads data from all channels along with the STATUS and ASTATUS bytes.
    err_t color16_read_data ( color16_t *ctx, color16_data_t *data_out );
  • color16_set_wait_time_ms This function sets the wait time in milliseconds by setting the WTIME register.
    err_t color16_set_wait_time_ms ( color16_t *ctx, float wait_time_ms );
  • color16_set_integration_time_ms This function sets the integration time in milliseconds by setting the ATIME and ASTEP registers.
    err_t color16_set_integration_time_ms ( color16_t *ctx, float int_time_ms );

Example Description

This example demonstrates the use of Color 16 click by reading and displaying the values from all 14 channels.

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;
color16_cfg_t color16_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
color16_cfg_setup( &color16_cfg );
COLOR16_MAP_MIKROBUS( color16_cfg, MIKROBUS_1 );
if ( I2C_MASTER_ERROR == color16_init( &color16, &color16_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( COLOR16_ERROR == color16_default_cfg ( &color16 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}

Application Task

Waits for the spectral measurement complete flag and then reads data from all 14 channels

in 3 cycles, and displays the results on the USB UART every 300ms approximately.

void application_task ( void )
{
color16_data_t color_data;
if ( COLOR16_OK == color16_read_data ( &color16, &color_data ) )
{
log_printf ( &logger, " STATUS: 0x%.2X\r\n", ( uint16_t ) color_data.status );
log_printf ( &logger, " ASTATUS: 0x%.2X\r\n", ( uint16_t ) color_data.astatus );
log_printf ( &logger, " ------- Cycle 1 -------\r\n" );
log_printf ( &logger, " Channel FZ: %u\r\n", color_data.ch_fz );
log_printf ( &logger, " Channel FY: %u\r\n", color_data.ch_fy );
log_printf ( &logger, " Channel FXL: %u\r\n", color_data.ch_fxl );
log_printf ( &logger, " Channel NIR: %u\r\n", color_data.ch_nir );
log_printf ( &logger, " Channel 2xVIS_1: %u\r\n", color_data.ch_2x_vis_1 );
log_printf ( &logger, " Channel FD_1: %u\r\n", color_data.ch_fd_1 );
log_printf ( &logger, " ------- Cycle 2 -------\r\n" );
log_printf ( &logger, " Channel F2: %u\r\n", color_data.ch_f2 );
log_printf ( &logger, " Channel F3: %u\r\n", color_data.ch_f3 );
log_printf ( &logger, " Channel F4: %u\r\n", color_data.ch_f4 );
log_printf ( &logger, " Channel F6: %u\r\n", color_data.ch_f6 );
log_printf ( &logger, " Channel 2xVIS_2: %u\r\n", color_data.ch_2x_vis_2 );
log_printf ( &logger, " Channel FD_2: %u\r\n", color_data.ch_fd_2 );
log_printf ( &logger, " ------- Cycle 3 -------\r\n" );
log_printf ( &logger, " Channel F1: %u\r\n", color_data.ch_f1 );
log_printf ( &logger, " Channel F5: %u\r\n", color_data.ch_f5 );
log_printf ( &logger, " Channel F7: %u\r\n", color_data.ch_f7 );
log_printf ( &logger, " Channel F8: %u\r\n", color_data.ch_f8 );
log_printf ( &logger, " Channel 2xVIS_3: %u\r\n", color_data.ch_2x_vis_3 );
log_printf ( &logger, " Channel FD_3: %u\r\n", color_data.ch_fd_3 );
log_printf ( &logger, " -----------------------\r\n\n" );
Delay_ms ( 300 );
}
}

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.Color16

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.


color16_data_t::ch_fd_3
uint16_t ch_fd_3
Definition: color16.h:330
COLOR16_ERROR
@ COLOR16_ERROR
Definition: color16.h:378
color16_data_t::status
uint8_t status
Definition: color16.h:311
color16_cfg_t
Color 16 Click configuration object.
Definition: color16.h:359
color16_data_t::ch_f3
uint16_t ch_f3
Definition: color16.h:320
color16_read_data
err_t color16_read_data(color16_t *ctx, color16_data_t *data_out)
Color 16 read data function.
color16_data_t::ch_fxl
uint16_t ch_fxl
Definition: color16.h:315
application_task
void application_task(void)
Definition: main.c:65
color16_data_t
Color 16 Click data object.
Definition: color16.h:310
color16_init
err_t color16_init(color16_t *ctx, color16_cfg_t *cfg)
Color 16 initialization function.
color16_data_t::ch_2x_vis_2
uint16_t ch_2x_vis_2
Definition: color16.h:323
color16_data_t::ch_f4
uint16_t ch_f4
Definition: color16.h:321
color16_set_integration_time_ms
err_t color16_set_integration_time_ms(color16_t *ctx, float int_time_ms)
Color 16 set integration time ms function.
color16_data_t::ch_f6
uint16_t ch_f6
Definition: color16.h:322
color16_data_t::ch_f2
uint16_t ch_f2
Definition: color16.h:319
color16_t
Color 16 Click context object.
Definition: color16.h:339
color16_data_t::ch_fd_1
uint16_t ch_fd_1
Definition: color16.h:318
COLOR16_OK
@ COLOR16_OK
Definition: color16.h:377
color16_data_t::ch_f7
uint16_t ch_f7
Definition: color16.h:327
color16_data_t::ch_nir
uint16_t ch_nir
Definition: color16.h:316
color16_set_wait_time_ms
err_t color16_set_wait_time_ms(color16_t *ctx, float wait_time_ms)
Color 16 set wait time ms function.
application_init
void application_init(void)
Definition: main.c:29
COLOR16_MAP_MIKROBUS
#define COLOR16_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: color16.h:296
color16_data_t::ch_f8
uint16_t ch_f8
Definition: color16.h:328
color16_data_t::ch_f5
uint16_t ch_f5
Definition: color16.h:326
color16_data_t::ch_fz
uint16_t ch_fz
Definition: color16.h:313
color16_default_cfg
err_t color16_default_cfg(color16_t *ctx)
Color 16 default configuration function.
color16_data_t::ch_fy
uint16_t ch_fy
Definition: color16.h:314
color16_data_t::ch_2x_vis_1
uint16_t ch_2x_vis_1
Definition: color16.h:317
color16_data_t::ch_fd_2
uint16_t ch_fd_2
Definition: color16.h:324
color16_cfg_setup
void color16_cfg_setup(color16_cfg_t *cfg)
Color 16 configuration object setup function.
color16_data_t::ch_2x_vis_3
uint16_t ch_2x_vis_3
Definition: color16.h:329
color16_data_t::astatus
uint8_t astatus
Definition: color16.h:312
color16_data_t::ch_f1
uint16_t ch_f1
Definition: color16.h:325