ir 2.0.0.0
Main Page

IR click

‍IR Click is an add-on board in mikroBUS form factor. It’s a compact and easy solution for adding infrared (IR) remote control module to your design.

click Product page


Click library

  • Author : Stefan Ilic
  • Date : Oct 2021.
  • Type : UART type

Software Support

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

Standard key functions :

  • ir_cfg_setup Config Object Initialization function.
    void ir_cfg_setup ( ir_cfg_t *cfg );
    void ir_cfg_setup(ir_cfg_t *cfg)
    IR configuration object setup function.
    IR Click configuration object.
    Definition ir.h:156
  • ir_init Initialization function.
    err_t ir_init ( ir_t *ctx, ir_cfg_t *cfg );
    err_t ir_init(ir_t *ctx, ir_cfg_t *cfg)
    IR initialization function.
    IR Click context object.
    Definition ir.h:131

Example key functions :

  • ir_get_an_state IR get AN pin state function.
    uint8_t ir_get_an_state ( ir_t *ctx );
    uint8_t ir_get_an_state(ir_t *ctx)
    IR get AN pin state function.
  • ir_nec_send_command IR NEC send data function.
    void ir_nec_send_command ( ir_t *ctx, uint8_t address, uint8_t command );
    void ir_nec_send_command(ir_t *ctx, uint8_t address, uint8_t command)
    IR NEC send data function.
  • ir_nec_read_command IR NEC data reading function.
    err_t ir_nec_read_command ( ir_t *ctx, uint8_t *address, uint8_t *command );
    err_t ir_nec_read_command(ir_t *ctx, uint8_t *address, uint8_t *command)
    IR NEC data reading function.

Example Description

‍This is an example that demonstrates the use of the IR Click board.

The demo application is composed of two sections :

Application Init

‍Initialization driver enables - GPIO and Log.

void application_init ( void )
{
log_cfg_t log_cfg;
ir_cfg_t ir_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
ir_cfg_setup( &ir_cfg );
IR_MAP_MIKROBUS( ir_cfg, MIKROBUS_1 );
err_t error_flag = ir_init( &ir, &ir_cfg );
if ( ( UART_ERROR == error_flag ) || ( PWM_ERROR == error_flag ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
log_printf( &logger, "- - - - - - - - - - - - \r\n" );
#ifdef IR_TRANSMITTER_MODE
log_printf( &logger, "- Transmitter mode - \r\n" );
#else
log_printf( &logger, "- Receiver mode - \r\n" );
#endif
log_printf( &logger, "- - - - - - - - - - - - \r\n" );
}
#define IR_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition ir.h:106
void application_init(void)
Definition main.c:34

Application Task

‍This example contains two parts :

  • Transmitter mode - Sends data using NEC protocol.
  • Receiver mode - Reads data that is been sent using NEC protocol and displaying it on the UART terminal.
void application_task ( void )
{
#ifdef IR_TRANSMITTER_MODE
log_printf( &logger, " Sending message." );
for ( uint8_t cnt = 0; cnt < 8; cnt++ )
{
ir_nec_send_command( &ir, 0x00, tx_data[ cnt ] );
log_printf( &logger, "." );
Delay_ms ( 50 );
}
log_printf( &logger, "\r\n Message sent! \r\n" );
log_printf( &logger, "- - - - - - - - - - - - \r\n" );
Delay_ms ( 500 );
#else
uint8_t arr;
char rx_data;
err_t err_flag = ir_nec_read_command ( &ir, &arr, &rx_data );
if ( IR_OK == err_flag )
{
log_printf( &logger, "%c", rx_data );
}
else
{
log_printf( &logger, "Read ERROR! \r\n" );
}
Delay_ms ( 50 );
#endif
}
@ IR_OK
Definition ir.h:184
void application_task(void)
Definition main.c:73
uint8_t tx_data[8]
Definition main.c:30

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

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.