Skip to content

Latest commit

 

History

History
153 lines (110 loc) · 4.34 KB

README.md

File metadata and controls

153 lines (110 loc) · 4.34 KB

IR Sense 2 Click

IR Sense 2 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 : MikroE Team
  • Date : Jan 2020.
  • Type : I2C type

Software Support

Example Description

This application enables usage of IR sensor for presence detection.

Example Libraries

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.IrSense2

Example Key Functions

  • irsense2_cfg_setup Config Object Initialization function.
void irsense2_cfg_setup ( irsense2_cfg_t *cfg );
  • irsense2_init Initialization function.
err_t irsense2_init ( irsense2_t *ctx, irsense2_cfg_t *cfg );
  • irsense2_default_cfg Click Default Configuration function.
void irsense2_default_cfg ( irsense2_t *ctx );
  • irsense2_get_ir_data This function reads and returns 16bit value from the IR senor.
int16_t irsense2_get_ir_data ( irsense2_t *ctx );
  • This function calculates differences in read IR sensor data and
  • irsense_human_detected determines if there was a presence that tireggered a change.
uint8_t irsense_human_detected ( irsense2_t *ctx, float ir_data );
  • irsense2_get_int This function reads from interrupt factor information register.
void irsense2_get_int ( irsense2_t *ctx );

Application Init

Driver initialization.

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

    irsense2_cfg_setup( &cfg );
    IRSENSE2_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    irsense2_init( &irsense2, &cfg );

    Delay_us( 100 );
    
    irsense2_default_cfg ( &irsense2 );
}

Application Task

Fetches IR and temperature sensor data and prints them on terminal.

void application_task ( void )
{
    //  Task implementation.

    float temperature;
    float ir_data;
    uint8_t flag;

    Delay_ms ( 400 );

    irsense2_data_read( &irsense2, &ir_data, &temperature );

    flag = irsense_human_detected( &irsense2, ir_data );
    
    if( flag == 1 )
    {   log_printf( &logger, " \r\n----------------------------- \r\n");
        log_printf( &logger, "\r\n Person detected!!! \r\n" );
        log_printf( &logger, " \r\n----------------------------- \r\n");
        Delay_ms ( 300 );
    }

    log_printf( &logger, "\r\n\r\nIR Value:       %.2f  pA ", ir_data );
    log_printf( &logger, " \r\n----------------------------- \r\n");
    log_printf( &logger, "Temperature: %.8f  C \r\n", temperature );

    Delay_ms ( 1000 );
}
 

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.