Intermediate
30 min

Master the language of color like never before with MK64FN1M0VDC12

A palette of possibilities: Journey into the world of advanced color sensing

Color 13 Click with Clicker 2 for Kinetis

Published Sep 24, 2023

Click board™

Color 13 Click

Dev. board

Clicker 2 for Kinetis

Compiler

NECTO Studio

MCU

MK64FN1M0VDC12

Discover how our solution brings accuracy and clarity to color analysis in various applications

A

A

Hardware Overview

How does it work?

Color 13 Click is based on the APDS-9999, an RGB and proximity sensor with 940nm VCSEL from Broadcom Limited. The APDS-9999 uses four individual channels of red, green, blue, and IR in a specially designed matrix arrangement, allowing the device to have an optimal angular response and accurate RGB spectral response with high Lux accuracy over various light sources. The device detects light intensity under multiple lighting conditions and through different attenuation materials, including dark glass. The APDS-9999 is configurable as an ambient light and RGB sensor. It is also fast enough to provide proximity detection (PS) information at a high repetition rate, operating well from bright sunlight to dark

rooms. PS resolution can be varied from 8 to 11 bits, with the measurement rate from 6.25ms to 400ms. To offset unwanted reflected light from the cover glass, a PS intelligent cancellation level register allows for an on-chip subtraction of the ADC count contributed by any unwanted reflected light from the cover glass. Adding the micro-optic lenses within the module provides highly efficient transmission and reception of infrared energy, lowering overall power dissipation. In addition, the APDS-9999 can be put into a low-power standby mode, providing low average power consumption. Color 13 Click communicates with MCU using the standard I2C 2-Wire interface to read data and configure settings, supporting Fast Mode

operation with a clock frequency of up to 400kHz. It also features an intelligent interrupt function that generates independent light and proximity interrupt signals, available on the INT pin of the mikroBUS™ socket, which reduces power consumption by eliminating polling communication traffic between the sensor and MCU. This Click board™ can be operated only with a 3.3V logic voltage level. The board must perform appropriate logic voltage level conversion before using MCUs with different logic levels. Also, it comes equipped with a library containing functions and an example code that can be used as a reference for further development.

Color 13 Click top side image
Color 13 Click bottom side 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
NC
NC
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
NC
NC
TX
NC
NC
RX
I2C Clock
PD8
SCL
I2C Data
PD9
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

Color 13 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 Color 13 Click driver.

Key functions:

  • color13_get_rgb_ir - Read color data from device

  • color13_get_als - Read lux data from device.

  • color13_get_proximity - Read proximity data from device

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 main.c
 * @brief Color13 Click example
 *
 * # Description
 * This application showcases ability of Click board to read RGB and IR data
 * from device. Also it can be configured to read proximity data and
 * ALS data in lux units.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initialization of host communication modules (UART, I2C) and additonal pin.
 * Read and check device ID, selects example and configures device for it.
 *
 * ## Application Task
 * Depending of selected example in task proximity and als data will be read from
 * device, or it will show ADC value for red, green, blue and ir data from device.
 * 
 * ### Additioal function
 * static void color13_proximity_als_example ( void );
 * static void color13_rgb_example ( void );
 *
 * @author Luka Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "color13.h"

#define COLOR13_EXAMPLE_PS_LS   3
#define COLOR13_EXAMPLE_RGB     6

static color13_t color13;
static log_t logger;

static uint8_t example_type;

/**
 * @brief Proximity and Als data reading.
 * @details Example function for reading proximity and als data.
 * @return Nothing
 */
static void color13_proximity_als_example ( void );

/**
 * @brief RGB data reading.
 * @details Example function for reading rgb and ir data.
 * @return Nothing
 */
static void color13_rgb_example ( void );

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    color13_cfg_t color13_cfg;  /**< Click config object. */

    /** 
     * 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.
    color13_cfg_setup( &color13_cfg );
    COLOR13_MAP_MIKROBUS( color13_cfg, MIKROBUS_1 );
    err_t init_flag = color13_init( &color13, &color13_cfg );
    if ( I2C_MASTER_ERROR == init_flag ) 
    {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }

    uint8_t temp_data = 0;
    init_flag = color13_generic_read( &color13, COLOR13_REG_PART_ID, &temp_data, 1 );
    log_printf( &logger, " > ID: 0x%.2X\r\n", ( uint16_t )temp_data );
    
    if ( ( COLOR13_OK != init_flag ) && ( COLOR13_ID != temp_data ) )
    {
        log_error( &logger, " ID" );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }
    
    //Select example
    example_type = COLOR13_EXAMPLE_RGB;
    color13_generic_write( &color13, COLOR13_REG_MAIN_CTRL, &example_type, 1 );
    
    if ( COLOR13_EXAMPLE_PS_LS == example_type )
    {
        //Configure proximity data to 11 bit
        color13_generic_read( &color13, COLOR13_REG_PS_MEASRATE, &temp_data, 1 );
        temp_data |= 0x18;
        color13_generic_write( &color13, COLOR13_REG_PS_MEASRATE, &temp_data, 1 );
    }
    
    Delay_ms ( 1000 );
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    switch ( example_type )
    {
        case COLOR13_EXAMPLE_PS_LS:
        {
            color13_proximity_als_example( );
            break;
        }
        case COLOR13_EXAMPLE_RGB:
        {
            color13_rgb_example( );
            break;
        }
        default:
        {
            log_error( &logger, " Select example!" );
            break;
        }
    }
    Delay_ms ( 500 );
}

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;
}

static void color13_proximity_als_example ( void )
{
    //Proximity data
    uint16_t ps_data = 0;
    err_t error_flag = color13_get_proximity( &color13, &ps_data );
    log_printf( &logger, " > PS: %u\r\n", ps_data );
    if ( COLOR13_ERROR_OVF == error_flag )
    {
        log_error( &logger, " Overflow" );
    }
    //ALS data
    float lux = 0;
    color13_get_als( &color13, &lux );
    log_printf( &logger, " > LS[ lux ]: %.2f\r\n", lux );
    log_printf( &logger, "**********************************\r\n" );
}

static void color13_rgb_example ( void )
{
    color13_color_t color_data;

    color13_get_rgb_ir( &color13, &color_data );
    
    log_printf( &logger, " > R: %u\r\n", color_data.red );
    log_printf( &logger, " > G: %u\r\n", color_data.green );
    log_printf( &logger, " > B: %u\r\n", color_data.blue );
    log_printf( &logger, " > IR: %u\r\n", color_data.ir );
    log_printf( &logger, "**********************************\r\n" );
}

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