lightranger13 2.2.0
Loading...
Searching...
No Matches
lightranger13


LightRanger 13 Click

LightRanger 13 Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.


Click Library

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

Software Support

Example Description

This application demonstrates the usage of the LightRanger 13 Click for distance measurement and monitoring.

Example Libraries

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.LightRanger13

Example Key Functions

Application Init

Initializes the logger and LightRanger 13 Click with default configuration, displays device information, performs factory calibration (if enabled), and sets up distance measurement thresholds (1mm-1000mm) with persistence (5 consecutive times) to ensure reliable readings. It then starts the measurement process.

void application_init ( void )
{
log_cfg_t log_cfg;
lightranger13_cfg_t lightranger13_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
lightranger13_cfg_setup( &lightranger13_cfg );
LIGHTRANGER13_MAP_MIKROBUS( lightranger13_cfg, MIKROBUS_1 );
if ( I2C_MASTER_ERROR == lightranger13_init( &lightranger13, &lightranger13_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( LIGHTRANGER13_ERROR == lightranger13_default_cfg ( &lightranger13 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_printf( &logger, "--- DEVICE INFO ---\r\n" );
log_printf( &logger, " App version: %u.%u.%u.%u\r\n",
( uint16_t ) lightranger13.info.app_ver[ 0 ],
( uint16_t ) lightranger13.info.app_ver[ 1 ],
( uint16_t ) lightranger13.info.app_ver[ 2 ],
( uint16_t ) lightranger13.info.app_ver[ 3 ] );
log_printf( &logger, " Chip version: %u.%u\r\n",
( uint16_t ) lightranger13.info.chip_ver[ 0 ],
( uint16_t ) lightranger13.info.chip_ver[ 1 ] );
log_printf( &logger, " Serial number: %.8LX\r\n\n", lightranger13.info.serial_num );
Delay_ms ( 1000 );
#ifndef FACTORY_CALIBRATION_DISABLE
log_printf( &logger, "--- FACTORY CALIBRATION ---\r\n" );
log_printf( &logger, " Calibration environment:\r\n" );
log_printf( &logger, " - Device has to be in the final (correct) optical stack\r\n" );
Delay_ms ( 10 );
log_printf( &logger, " - Cover glass (no smudge on the glass) in front of the device\r\n" );
log_printf( &logger, " - No target in front of the device within 40cm\r\n" );
log_printf( &logger, " - Dark room or low ambient light\r\n" );
log_printf( &logger, " Performing factory calibration in 5 seconds...\r\n" );
for ( uint8_t cnt = 5; cnt > 0; cnt-- )
{
log_printf( &logger, " %u\r\n", ( uint16_t ) cnt );
Delay_ms ( 1000 );
}
if ( LIGHTRANGER13_ERROR == lightranger13_factory_calib ( &lightranger13 ) )
{
log_error( &logger, " Factory calibration." );
for ( ; ; );
}
log_printf( &logger, " Factory calibration DONE.\r\n\n" );
Delay_ms ( 1000 );
#endif
log_printf( &logger, "--- THRESHOLD AND PERSISTANCE ---\r\n" );
log_printf( &logger, " Setting threshold: 1mm-1000mm; and persistance: 5 times\r\n" );
if ( LIGHTRANGER13_ERROR == lightranger13_set_threshold ( &lightranger13, 1, 1000, 5 ) )
{
log_error( &logger, " Set threshold." );
for ( ; ; );
}
log_printf( &logger, " Set threshold DONE.\r\n\n" );
Delay_ms ( 1000 );
log_printf( &logger, "--- STARTING MEASUREMENT ---\r\n" );
{
log_error( &logger, " Start measurement." );
for ( ; ; );
}
log_printf( &logger, " Measurement started.\r\n\n" );
Delay_ms ( 1000 );
log_info( &logger, " Application Task " );
}
#define LIGHTRANGER13_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition lightranger13.h:409
err_t lightranger13_factory_calib(lightranger13_t *ctx)
LightRanger 13 factory calib function.
@ LIGHTRANGER13_ERROR
Definition lightranger13.h:516
void application_init(void)
Definition main.c:40

Application Task

Waits for the data ready interrupt signal, indicating a new measurement is available. Upon receiving the signal, it reads the distance and temperature data from the sensor and logs the values to USB UART.

void application_task ( void )
{
// Wait for data ready interrupt
while ( lightranger13_get_int_pin ( &lightranger13 ) );
lightranger13_clear_interrupts ( &lightranger13 );
if ( LIGHTRANGER13_OK == lightranger13_read_result ( &lightranger13, &result ) )
{
log_printf( &logger, " Distance: %u mm\r\n", result.dist_peak );
log_printf( &logger, " Temperature: %d degC\r\n\n", ( int16_t ) result.temperature );
}
}
uint8_t lightranger13_get_int_pin(lightranger13_t *ctx)
LightRanger 13 get int pin function.
err_t lightranger13_clear_interrupts(lightranger13_t *ctx)
LightRanger 13 clear interrupts function.
@ LIGHTRANGER13_OK
Definition lightranger13.h:515
void application_task(void)
Definition main.c:130
uint16_t dist_peak
Definition lightranger13.h:456
int8_t temperature
Definition lightranger13.h:459

Note

The factory calibration step can be enabled or disabled by commenting/uncommenting the FACTORY_CALIBRATION_DISABLE macro.

Application Output

This Click board can be interfaced and monitored in two ways:

  • Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.
  • UART Terminal - Monitor data via the UART Terminal using a USB to UART converter. For detailed instructions, check out this tutorial.

Additional Notes and Information

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.