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)
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)
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)
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)
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)
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.
{
log_cfg_t log_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
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.
{
#ifdef IR_TRANSMITTER_MODE
log_printf( &logger, " Sending message." );
for ( uint8_t cnt = 0; cnt < 8; 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;
{
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.