color2  2.0.0.0
Main Page

Color 2 click

Color 2 click carries the ISL29125 RGB color light sensor. It detects red, green and blue in a variety of lighting conditions, outputting 16-bit resolution data in a measuring range from 5.7 m lux to 10,000 lux.

click Product page


Click library

  • Author : MikroE Team
  • Date : Dec 2019.
  • Type : I2C type

Software Support

We provide a library for the Color2 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 form compilers IDE(recommended way), or downloaded from our LibStock, or found on mikroE github account.

Library Description

This library contains API for Color2 Click driver.

Standard key functions :

  • Config Object Initialization function.

    void color2_cfg_setup ( color2_cfg_t *cfg );

  • Initialization function.

    COLOR2_RETVAL color2_init ( color2_t *ctx, color2_cfg_t *cfg );

  • Click Default Configuration function.

    void color2_default_cfg ( color2_t *ctx );

Example key functions :

Examples Description

Example demonstrates use of Color 2 click.

The demo application is composed of two sections :

Application Init

Initialization driver enable's - initialize ISL29125 RGB color light sensor and start write log.

void application_init ( void )
{
log_cfg_t log_cfg;
// Logger initialization.
log_cfg.level = LOG_LEVEL_DEBUG;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, "---- Application Init ----" );
// Click initialization.
COLOR2_MAP_MIKROBUS( cfg, MIKROBUS_1 );
color2_init( &color2, &cfg );
color2_default_cfg ( &color2 );
}

Application Task

This is a example which demonstrates the use of Color 2 Click board. ISL29125 RGB color light sensor on Color 2 Click, detects red, green and blue in a variety of lighting conditions and outputting 16-bit resolution data on the USBUART. Also read color and check which color is detected by the sensor. If the color is detected, the detected color message is logged on the USBUART. All data logs on usb uart for aproximetly every 3 sec.

void application_task ( void )
{
// Task implementation.
uint16_t value_red_color;
uint16_t value_green_color;
uint16_t value_blue_color;
uint8_t is_color;
float color_value;
color_value = color2_get_color_value( &color2 );
is_color = color2_get_color( color_value );
value_green_color = color2_read_green( &color2 );
value_red_color = color2_read_red( &color2 );
value_blue_color = color2_read_blue( &color2 );
switch(is_color)
{
case 1:
{
log_printf( &logger, " *** ORANGE ***");
break;
}
case 2:
{
log_printf( &logger, " *** RED ***");
break;
}
case 3:
{
log_printf( &logger, " *** PINK ***");
break;
}
case 4:
{
log_printf( &logger, " *** PURPLE ***");
break;
}
case 5:
{
log_printf( &logger, " *** BLUE ***");
break;
}
case 6:
{
log_printf( &logger, " *** CYAN ***");
break;
}
case 7:
{
log_printf( &logger, " *** GREEN ***");
break;
}
case 8:
{
log_printf( &logger, " *** YELLOW ***");
break;
}
default:
{
break;
}
}
log_printf( &logger, "----------------------");
log_printf( &logger, " Red value : %d", value_red_color);
log_printf( &logger, " Green value : %d", value_green_color);
log_printf( &logger, " Blue value : %d", value_blue_color);
log_printf( &logger, "----------------------");
Delay_1sec();
Delay_1sec();
Delay_1sec();
}

The full application code, and ready to use projects can be installed directly form compilers IDE(recommneded) or found on LibStock page or mikroE GitHub accaunt.

Other mikroE Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.Color2

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. The terminal available in all Mikroelektronika compilers, or any other terminal application of your choice, can be used to read the message.


color2_get_color_value
float color2_get_color_value(color2_t *ctx)
Functions for read color value.
color2_default_cfg
void color2_default_cfg(color2_t *ctx)
Click Default Configuration function.
color2_cfg_t
Click configuration structure definition.
Definition: color2.h:168
application_task
void application_task(void)
Definition: main.c:59
color2_cfg_setup
void color2_cfg_setup(color2_cfg_t *cfg)
Config Object Initialization function.
color2_get_color
uint8_t color2_get_color(float color_value)
Functions for detect colors.
application_init
void application_init(void)
Definition: main.c:38
COLOR2_MAP_MIKROBUS
#define COLOR2_MAP_MIKROBUS(cfg, mikrobus)
Definition: color2.h:53
color2_read_green
float color2_read_green(color2_t *ctx)
Function read green color data.
color2_read_blue
float color2_read_blue(color2_t *ctx)
Function read blue color data.
color2_init
COLOR2_RETVAL color2_init(color2_t *ctx, color2_cfg_t *cfg)
Initialization function.
color2_read_red
float color2_read_red(color2_t *ctx)
Function read red color data.