Intermediate
30 min

Create advanced optical sensning solution based on TMD37253 and ATmega328P

Precision in every shade: The future of light sensing

Light mix-sens Click with Arduino UNO Rev3

Published Feb 14, 2024

Click board™

Light mix-sens Click

Dev. board

Arduino UNO Rev3

Compiler

NECTO Studio

MCU

ATmega328P

Experience the ultimate in sensor fusion with our all-in-one solution, providing precise proximity, color, and ambient light measurements for enhanced user experiences

A

A

Hardware Overview

How does it work?

Light mix-sens Click is based on the TMD37253 slim module, from ams OSRAM, incorporates an IR LED and factory calibrated LED driver. The proximity detection feature provides object detection (e.g. mobile device screen to the user’s ear) by photodiode detection of reflected IR energy (sourced by the integrated LED). Detect/release events are interrupt-driven, and occur when proximity result crosses upper and/or lower threshold settings. The proximity engine features offset adjustment registers to compensate for unwanted IR energy reflection at the sensor. Proximity results are further improved by automatic ambient light subtraction. The ALS detection feature provides photopic light intensity data. The color photodiodes have UV and IR blocking filters and a dedicated data converters producing 16-bit data. This architecture allows applications to accurately measure ambient light which enables devices to calculate illuminance and color temperature to control display backlight and chromaticity. Proximity results are affected

by three fundamental factors: the integrated IR LED emission, IR reception, and environmental factors, including target distance and surface reflectivity. The IR reception signal path begins with IR detection from a photodiode and ends with the 8-bit proximity result in the PDATA register. A signal from the photodiode is amplified, and offset adjusted to optimize performance. Offset correction or cross-talk compensation is accomplished by adjustment to the POFFSET register. The analog circuitry of the device applies the offset value as a subtraction to the signal accumulation; therefore a positive offset value has the effect of decreasing the results. The color and ALS reception signal path begins as photodiodes receive filtered light and ends with 16-bit results. The IR photodiode primarily used for proximity sensing is multiplexed with the green channel’s ADC to measure the IR content of ambient light. The color photodiodes are filtered with UV and IR filters. The IR photodiode is filtered to receive only IR. A signal from the RGBC photodiodes

simultaneously accumulate for a period of time set by the value in ATIME before the results are available. Measurement of IR must be done in a separate integration because it shares the ADC with the green photodiode. Gain is adjustable from 1x to 128 x to facilitate the operation over a wide range of lighting conditions. Custom LUX equations are used to calculate the amount of ambient light, color temperature, as well as, determine the light type (e.g. LED, fluorescent, incandescent, etc.) using the ALS results. The TMD37253 module operates at 1.8V power supply with 1.8V I2C bus for reduced power consumption. For integration on Mikrobus, complete voltage regulation and logic level translation has been implemented. Therefore, this Click Board™ is designed to be operated only with a 3.3V logic level. A proper logic voltage level conversion should be performed before the Click board™ is used with MCUs with logic levels of 5V.

Light mix-sens Click top side image
Light mix-sens Click bottom side image

Features overview

Development board

Arduino UNO is a versatile microcontroller board built around the ATmega328P chip. It offers extensive connectivity options for various projects, featuring 14 digital input/output pins, six of which are PWM-capable, along with six analog inputs. Its core components include a 16MHz ceramic resonator, a USB connection, a power jack, an

ICSP header, and a reset button, providing everything necessary to power and program the board. The Uno is ready to go, whether connected to a computer via USB or powered by an AC-to-DC adapter or battery. As the first USB Arduino board, it serves as the benchmark for the Arduino platform, with "Uno" symbolizing its status as the

first in a series. This name choice, meaning "one" in Italian, commemorates the launch of Arduino Software (IDE) 1.0. Initially introduced alongside version 1.0 of the Arduino Software (IDE), the Uno has since become the foundational model for subsequent Arduino releases, embodying the platform's evolution.

Arduino UNO Rev3 double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

AVR

MCU Memory (KB)

32

Silicon Vendor

Microchip

Pin count

28

RAM (Bytes)

2048

You complete me!

Accessories

Click Shield for Arduino UNO has two proprietary mikroBUS™ sockets, allowing all the Click board™ devices to be interfaced with the Arduino UNO board without effort. The Arduino Uno, a microcontroller board based on the ATmega328P, provides an affordable and flexible way for users to try out new concepts and build prototypes with the ATmega328P microcontroller from various combinations of performance, power consumption, and features. The Arduino Uno has 14 digital input/output pins (of which six can be used as PWM outputs), six analog inputs, a 16 MHz ceramic resonator (CSTCE16M0V53-R0), a USB connection, a power jack, an ICSP header, and reset button. Most of the ATmega328P microcontroller pins are brought to the IO pins on the left and right edge of the board, which are then connected to two existing mikroBUS™ sockets. This Click Shield also has several switches that perform functions such as selecting the logic levels of analog signals on mikroBUS™ sockets and selecting logic voltage levels of the mikroBUS™ sockets themselves. Besides, the user is offered the possibility of using any Click board™ with the help of existing bidirectional level-shifting voltage translators, regardless of whether the Click board™ operates at a 3.3V or 5V logic voltage level. Once you connect the Arduino UNO board with our Click Shield for Arduino UNO, you can access hundreds of Click boards™, working with 3.3V or 5V logic voltage levels.

Click Shield for Arduino UNO accessories 1 image

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
PC3
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PC5
SCL
I2C Data
PC4
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

Light mix-sens Click Schematic schematic

Step by step

Project assembly

Click Shield for Arduino UNO front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Arduino UNO Rev3 as your development board.

Click Shield for Arduino UNO front image hardware assembly
Arduino UNO Rev3 front image hardware assembly
Charger 27 Click front image hardware assembly
Prog-cut hardware assembly
Board mapper by product8 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
Arduino UNO 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 Light mix-sens Click driver.

Key functions:

  • lightmixsens_write_byte - Generic Write Byte function

  • lightmixsens_read_byte - Generic Read Byte function

  • lightmixsens_switch_ir_to_prox - Switch IR To Proximity function

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 LightMixSens Click example
 * 
 * # Description
 * This example show usage of Light Mix Sens Click. It switches the IR light for separate and 
 * measure sectar of RGB lights. Click also measure proximity from the object using light source.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes all necessary peripherals and pins, initializes I2C driver and performs 
 * the Click board default configuration to allow ALS/Color and Proximity measurements.
 * 
 * ## Application Task  
 * Waits until ALS/Color integration cycle was done and then reads the entire measurement.
 * The all results will be sent to the selected UART terminal.
 * 
 * ## Additional Functions :
 * - prox_app - This is application function which determines the proximity results.
 * 
 *
 * @author MikroE Team
 *
 */

#include "board.h"
#include "log.h"
#include "lightmixsens.h"


static lightmixsens_t lightmixsens;
static log_t logger;
lightmixsens_data_obj lightmixsens_data;
char prox_str[ 20 ];

// ------------------------------------------------------- ADDITIONAL FUNCTIONS

/**
 * @brief Light mix sens proximity function.
 * @details This is function which determines the proximity results.
 */
void prox_app ( void );

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;
    lightmixsens_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.

    lightmixsens_cfg_setup( &cfg );
    LIGHTMIXSENS_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    lightmixsens_init( &lightmixsens, &cfg );

    lightmixsens_default_cfg( &lightmixsens );

    lightmixsens_data.lightmixsens_cdata = LIGHTMIXSENS_DUMMY_DATA;
    lightmixsens_data.lightmixsens_rdata = LIGHTMIXSENS_DUMMY_DATA;
    lightmixsens_data.lightmixsens_gdata = LIGHTMIXSENS_DUMMY_DATA;
    lightmixsens_data.lightmixsens_bdata = LIGHTMIXSENS_DUMMY_DATA;
    lightmixsens_data.lightmixsens_pdata = LIGHTMIXSENS_DUMMY_DATA;

    log_printf( &logger, "*  Light mix-sens Click initialization done.  *\r\n" );
}

void application_task ( void )
{
    lightmixsens_wait_atime( &lightmixsens );
    
    lightmixsens_read_word( &lightmixsens, LIGHTMIXSENS_REG_CDATA, 
                            &lightmixsens_data.lightmixsens_cdata );
    lightmixsens_read_word( &lightmixsens, LIGHTMIXSENS_REG_RDATA, 
                            &lightmixsens_data.lightmixsens_rdata );
    lightmixsens_read_word( &lightmixsens, LIGHTMIXSENS_REG_GDATA_IRDATA, 
                            &lightmixsens_data.lightmixsens_gdata );
    lightmixsens_read_word( &lightmixsens, LIGHTMIXSENS_REG_BDATA, 
                            &lightmixsens_data.lightmixsens_bdata );
    lightmixsens_read_byte( &lightmixsens, LIGHTMIXSENS_REG_PDATA, 
                            &lightmixsens_data.lightmixsens_pdata );
    
    log_printf( &logger, "- Clear light:  %.3d lx\r\n", lightmixsens_data.lightmixsens_cdata );
    log_printf( &logger, "- Red light:    %.3d lx\r\n", lightmixsens_data.lightmixsens_rdata );
    log_printf( &logger, "- Green light:  %.3d lx\r\n", lightmixsens_data.lightmixsens_gdata );
    log_printf( &logger, "- Blue light:   %.3d lx\r\n", lightmixsens_data.lightmixsens_bdata );
    
    prox_app( );
    log_printf( &logger, "** Proximity:   %s\r\n", prox_str );
    
    log_printf( &logger, "\r\n" );
    Delay_ms ( 1000 );
}

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

void prox_app ( void )
{
    float prox;
    uint8_t cnt;
    
    prox = lightmixsens_data.lightmixsens_pdata;
    prox /= 255;
    prox *= 16;
    
    for ( cnt = 0; cnt < ( uint8_t ) prox; cnt++ ) {
        prox_str[ cnt ] = '|';
    }
    
    prox_str[ cnt ] = 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.