lightranger10  2.0.0.0
Main Page

LightRanger 10 click

PRVIH_PAR_RECENICA_SA_PRODUCT_PAGE_DA_ISPRATE_CELINU

[click Product page](CLICK_PRODUCT_PAGE_LINK)


Click library

  • Author : Stefan Filipovic
  • Date : May 2022.
  • Type : I2C type

Software Support

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

Standard key functions :

Example key functions :

Example Description

This example demonstrates the use of LightRanger 10 click board by reading and displaying the target object distance in millimeters.

The demo application is composed of two sections :

Application Init

Initializes the driver, performs the click default configuration, and then calibrates the sensor to the object positioned at 200mm distance from the sensor.

void application_init ( void )
{
log_cfg_t log_cfg;
lightranger10_cfg_t lightranger10_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
lightranger10_cfg_setup( &lightranger10_cfg );
LIGHTRANGER10_MAP_MIKROBUS( lightranger10_cfg, MIKROBUS_1 );
if ( I2C_MASTER_ERROR == lightranger10_init( &lightranger10, &lightranger10_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( LIGHTRANGER10_ERROR == lightranger10_default_cfg ( &lightranger10 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_printf( &logger, " --- Sensor calibration --- \r\n" );
log_printf( &logger, " Place an object at 200mm distance from sensor in the next 5 seconds.\r\n" );
Delay_ms( 5000 );
log_printf( &logger, " Sensor calibration is in progress...\r\n" );
if ( LIGHTRANGER10_ERROR == lightranger10_calibrate_distance ( &lightranger10, 200 ) )
{
log_error( &logger, " Sensor calibration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}

Application Task

Waits for the data ready interrupt, then clears the interrupt and reads the target distance in millimeters and displays the results on the USB UART every 200ms approximately.

void application_task ( void )
{
while ( lightranger10_get_int_pin ( &lightranger10 ) );
uint16_t distance_mm;
if ( ( LIGHTRANGER10_OK == lightranger10_clear_interrupts ( &lightranger10 ) ) &&
( LIGHTRANGER10_OK == lightranger10_get_distance ( &lightranger10, &distance_mm ) ) )
{
log_printf ( &logger, " Distance: %u mm \r\n\n", distance_mm );
}
}

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

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.


lightranger10_default_cfg
err_t lightranger10_default_cfg(lightranger10_t *ctx)
LightRanger 10 default configuration function.
LIGHTRANGER10_ERROR
@ LIGHTRANGER10_ERROR
Definition: lightranger10.h:236
LIGHTRANGER10_MAP_MIKROBUS
#define LIGHTRANGER10_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: lightranger10.h:183
application_task
void application_task(void)
Definition: main.c:76
lightranger10_cfg_t
LightRanger 10 Click configuration object.
Definition: lightranger10.h:217
lightranger10_cfg_setup
void lightranger10_cfg_setup(lightranger10_cfg_t *cfg)
LightRanger 10 configuration object setup function.
lightranger10_calibrate_distance
err_t lightranger10_calibrate_distance(lightranger10_t *ctx, uint16_t target_distance_mm)
LightRanger 10 calibrate distance function.
lightranger10_get_int_pin
uint8_t lightranger10_get_int_pin(lightranger10_t *ctx)
LightRanger 10 get int pin function.
LIGHTRANGER10_OK
@ LIGHTRANGER10_OK
Definition: lightranger10.h:235
lightranger10_get_distance
err_t lightranger10_get_distance(lightranger10_t *ctx, uint16_t *distance_mm)
LightRanger 10 get distance function.
application_init
void application_init(void)
Definition: main.c:30
lightranger10_t
LightRanger 10 Click context object.
Definition: lightranger10.h:197
lightranger10_clear_interrupts
err_t lightranger10_clear_interrupts(lightranger10_t *ctx)
LightRanger 10 clear interrupts function.
lightranger10_init
err_t lightranger10_init(lightranger10_t *ctx, lightranger10_cfg_t *cfg)
LightRanger 10 initialization function.