TOP Contributors

  1. MIKROE (2784 codes)
  2. Alcides Ramos (392 codes)
  3. Shawon Shahryiar (307 codes)
  4. jm_palomino (123 codes)
  5. Bugz Bensce (97 codes)
  6. S P (73 codes)
  7. dany (71 codes)
  8. MikroBUS.NET Team (35 codes)
  9. NART SCHINACKOW (34 codes)
  10. Armstrong Subero (27 codes)

Most Downloaded

  1. Timer Calculator (140544 times)
  2. FAT32 Library (73037 times)
  3. Network Ethernet Library (58043 times)
  4. USB Device Library (48215 times)
  5. Network WiFi Library (43826 times)
  6. FT800 Library (43295 times)
  7. GSM click (30359 times)
  8. mikroSDK (28990 times)
  9. PID Library (27116 times)
  10. microSD click (26722 times)
Libstock prefers package manager

Package Manager

We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]

< Back
mikroSDK Library

LightRanger 5 Click

Rating:

0

Author: MIKROE

Last Updated: 2024-10-31

Package Version: 2.1.0.15

mikroSDK Library: 2.0.0.0

Category: Optical

Downloaded: 223 times

Not followed.

License: MIT license  

LightRanger 5 Click is a compact add-on board that contains a ranging sensor with multi-target detection. This board features the TMF8801, a dToF (direct time of flight) optical distance sensor achieving up to 2500mm target detection distance from company AMS-TAOS.

No Abuse Reported

Do you want to subscribe in order to receive notifications regarding "LightRanger 5 Click" changes.

Do you want to unsubscribe in order to stop receiving notifications regarding "LightRanger 5 Click" changes.

Do you want to report abuse regarding "LightRanger 5 Click".

  • Information
  • Comments (0)

mikroSDK Library Blog


LightRanger 5 Click

LightRanger 5 Click is a compact add-on board that contains a ranging sensor with multi-target detection. This board features the TMF8801, a dToF (direct time of flight) optical distance sensor achieving up to 2500mm target detection distance from company AMS-TAOS.

lightranger_5_click.png

Click Product page


Click library

  • Author : Nenad Filipovic
  • Date : Mar 2021.
  • Type : I2C type

Software Support

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

Standard key functions :

  • lightranger5_cfg_setup Config Object Initialization function.

    void lightranger5_cfg_setup ( lightranger5_cfg_t *cfg );
  • lightranger5_init Initialization function.

    LIGHTRANGER5_RETVAL lightranger5_init ( lightranger5_t *ctx, lightranger5_cfg_t *cfg );
  • lightranger5_default_cfg Click Default Configuration function.

    void lightranger5_default_cfg ( lightranger5_t *ctx );

Example key functions :

  • lightranger5_get_status LightRanger 5 get status function.

    err_t lightranger5_get_status ( lightranger5_t *ctx, uint8_t *status );
  • lightranger5_set_factory_calib_data LightRanger 5 set factory calib data function.

    err_t lightranger5_set_factory_calib_data ( lightranger5_t *ctx, uint8_t *factory_calib_data );
  • lightranger5_measure_distance LightRanger 5 measure distance function.

    uint16_t lightranger5_measure_distance ( lightranger5_t *ctx );

Example Description

This is an example that demonstrates the use of the LightRanger 5 Click board. This demo application shows an example of distance measurement.

The demo application is composed of two sections :

Application Init

Initialization of I2C module, log UART and additional pins. After driver initialization and default settings, the app performs and check factory calibrationa and check and wait for OK status. This process takes a few seconds, so please wait. After current status is OK, app performs the configuration of the TMF8801 sensor: read and write calibration data, set algorithm state and command data.


void application_init ( void ) {
    log_cfg_t log_cfg;                    /**< Logger config object. */
    lightranger5_cfg_t lightranger5_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_printf( &logger, "\r\n" );
    log_info( &logger, " Application Init " );

    // Click initialization.

    lightranger5_cfg_setup( &lightranger5_cfg );
    LIGHTRANGER5_MAP_MIKROBUS( lightranger5_cfg, MIKROBUS_1 );
    err_t init_flag = lightranger5_init( &lightranger5, &lightranger5_cfg );
    if ( init_flag == I2C_MASTER_ERROR ) {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }

    lightranger5_default_cfg( &lightranger5 );
    log_info( &logger, " Application Task " );
    Delay_ms ( 100 );

    if ( !lightranger5_check_factory_calibration( &lightranger5 ) ) {
        log_info( &logger, " Factory calibration success." );
    } else {
        log_info( &logger, " Factory calibration FAILED." );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }

    do {
        lightranger5_get_status( &lightranger5, &status );

        if ( status_old != status ) {
            if ( status < LIGHTRANGER5_STATUS_OK ) {
                display_status_no_error( );    
            } else {
                display_status_error( );   
            }  
            status_old = status;
        }
        Delay_ms ( 100 );
    } while ( status );

    lightranger5_get_factory_calib_data( &lightranger5, factory_calib_data );

    log_printf( &logger, "------------------------------\r\n" );
    log_printf( &logger, " factory_calib_data[ 14 ] =\r\n { " );

    for ( uint8_t n_cnt = 0 ; n_cnt < 14 ; n_cnt++ ) {
        log_printf( &logger, "0x%.2X, ", factory_calib_data[ n_cnt ] );
    }

    log_printf( &logger, "};\r\n" );
    log_printf( &logger, "------------------------------\r\n" );

    lightranger5_set_command( &lightranger5, LIGHTRANGER5_CMD_DL_CALIB_AND_STATE );

    lightranger5_set_factory_calib_data( &lightranger5, factory_calib_data );

    lightranger5_set_algorithm_state_data( &lightranger5, tmf8801_algo_state );

    lightranger5_set_command_data( &lightranger5, command_data );

    lightranger5_get_status( &lightranger5, &status );

    if ( status_old != status ) {
        if ( status < LIGHTRANGER5_STATUS_OK ) {
            display_status_no_error( );    
        } else {
            display_status_error( );   
        }  
        status_old = status;
    }

    lightranger5_get_currently_run_app( &lightranger5, &appid_data );

    if ( appid_data == LIGHTRANGER5_APPID_MEASUREMENT ) {
        log_printf( &logger, " Measurement app running.\r\n" );
    }
    else if ( appid_data == LIGHTRANGER5_APPID_BOOTLOADER ) {
        log_printf( &logger, " Bootloader running.\r\n" );
    } else {
        log_printf( &logger, " Result: 0x%X\r\n", appid_data );    
    }

    log_printf( &logger, "------------------------------\r\n" );
}

Application Task

This is an example that shows the use of a LightRanger 5 Click board. A new data ready is checked as soon as possible which signals the time required for the ranging sensor to perform the distance measurement. Results are being sent to the Usart Terminal where you can track their changes.


void application_task ( void ) {

    if ( lightranger5_check_data_ready( &lightranger5 ) == LIGHTRANGER5_DATA_IS_READY ) {
        uint16_t distance_mm = lightranger5_measure_distance( &lightranger5 );

        if ( distance_mm ) {
            log_printf( &logger, "       Distance : %ld mm\r\n", distance_mm );    
        } else {
            log_printf( &logger, "         Out of range    \r\n", distance_mm );    
        }

        log_printf( &logger, "------------------------------\r\n" );
    }

    Delay_ms ( 1000 );
}

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

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.


ALSO FROM THIS AUTHOR

Spectral click

5

Spectral click is a light multispectral sensing device, which uses the state-of-the-art sensor IC for a very accurate true-color sensing. Spectral click provides a direct reading of the XYZ color coordinates, consistent with the CIE 1931 2. standard color space.

[Learn More]

Hall Switch 3 Click

0

Hall Switch 3 Click is a compact add-on board representing a magnetic field-activated switch. This board features the NMH1000, a Hall-effect magnetic switch from NXP Semiconductor. It is a low-voltage, low-current, and low-output data rate device with a very small size. The switch is most sensitive to a vertical field passing through the top-bottom surfaces, orthogonal to the plane of the Hall Switch 3 Click board™.

[Learn More]

AnyNet 3G-EA Click

0

AnyNet 3G-EA Click is a cellular to AWS gateway device, which provides developers with the complete solution for various IoT applications, by using the AWS IoT and Cloud Storage services for the data storage, analyzing and processing. AnyNet Click board™ provides a secure connection with the AWS over the air (OTA), by utilizing the Quectel UG95-EA 3G module, offering worldwide UMTS/HSPA and GSM/GPRS/EDGE coverage Eseye ES4623 embedded SIM card, that can work with more than 235 cellular operators from all over the world. An Eseye embedded sim card can work with more than 235 cellular operators from all over the world. The AnyNet 3G Click can be used as an AWS IoT button with almost no configuration.

[Learn More]