light3  2.1.0.0
Main Page

Light 3 Click

Light 3 Click is a compact add-on board for precise ambient light measurement in automotive applications. This board features the OPT4003-Q1, an automotive-grade digital ambient light sensor from Texas Instruments. This digital ambient light sensor excels in detecting both visible and near-infrared light with high accuracy, thanks to its dual-channel functionality and filters that mimic the human eye's response while efficiently segregating NIR light.

Click Product page


Click library

  • Author : Stefan Ilic
  • Date : Jan 2024.
  • Type : I2C type

Software Support

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

Standard key functions :

Example key functions :

  • light3_sw_reset This function is used to perform software reset.
    err_t light3_sw_reset ( light3_t *ctx );
  • light3_write_reg This function writes a desired data into the selected register by using I2C serial interface.
    err_t light3_write_reg ( light3_t *ctx, uint8_t reg, uint16_t data_in );
  • light3_get_ch0_data This function reads ambient light data from the Channel 0 and performs the calculatios from raw data to Lux.
    err_t light3_get_ch0_data ( light3_t *ctx, float *lux );

Example Description

This example demonstrates the use of Light 3 Click board by measuring the ambient light level in Lux.

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;
light3_cfg_t light3_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
light3_cfg_setup( &light3_cfg );
LIGHT3_MAP_MIKROBUS( light3_cfg, MIKROBUS_1 );
if ( I2C_MASTER_ERROR == light3_init( &light3, &light3_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( LIGHT3_ERROR == light3_default_cfg ( &light3 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}

Application Task

Reading channel 0 ambient light level in lux as soon as it is available ( once in 1.6 seconds ) and displaying it on the UART terminal.

void application_task ( void )
{
float lux_data = 0;
{
light3_get_ch0_data( &light3, &lux_data );
log_printf( &logger, "Light level: %f lux \r\n", ( float ) lux_data );
}
}

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

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.


light3_cfg_setup
void light3_cfg_setup(light3_cfg_t *cfg)
Light 3 configuration object setup function.
light3_get_ch0_data
err_t light3_get_ch0_data(light3_t *ctx, float *lux)
Light 3 read CH0 data function.
light3_default_cfg
err_t light3_default_cfg(light3_t *ctx)
Light 3 default configuration function.
light3_init
err_t light3_init(light3_t *ctx, light3_cfg_t *cfg)
Light 3 initialization function.
application_task
void application_task(void)
Definition: main.c:65
light3_cfg_t
Light 3 Click configuration object.
Definition: light3.h:228
light3_t
Light 3 Click context object.
Definition: light3.h:211
light3_sw_reset
err_t light3_sw_reset(light3_t *ctx)
Light 3 software reset function.
LIGHT3_MAP_MIKROBUS
#define LIGHT3_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: light3.h:198
LIGHT3_PIN_STATE_LOW
#define LIGHT3_PIN_STATE_LOW
Light 3 pin states setting.
Definition: light3.h:164
LIGHT3_ERROR
@ LIGHT3_ERROR
Definition: light3.h:246
application_init
void application_init(void)
Definition: main.c:29
light3_write_reg
err_t light3_write_reg(light3_t *ctx, uint8_t reg, uint16_t data_in)
Light 3 register writing function.
light3_get_int_pin
uint8_t light3_get_int_pin(light3_t *ctx)
Light 3 get INT pin state function.