proximity22 2.2.0
Loading...
Searching...
No Matches
proximity22


Proximity 22 Click

Proximity 22 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 : Stefan Filipovic
  • Date : Mar 2025.
  • Type : I2C type

Software Support

Example Description

This example demonstrates the use of the Proximity 22 Click board by reading and displaying proximity, ambient light (ALS), and temperature measurements. The data is read only when a new measurement is ready, indicated by an interrupt.

Example Libraries

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.Proximity22

Example Key Functions

Application Init

Initializes the logger and the Proximity 22 Click driver, then sets the default configuration.

void application_init ( void )
{
log_cfg_t log_cfg;
proximity22_cfg_t proximity22_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
proximity22_cfg_setup( &proximity22_cfg );
PROXIMITY22_MAP_MIKROBUS( proximity22_cfg, MIKROBUS_1 );
if ( I2C_MASTER_ERROR == proximity22_init( &proximity22, &proximity22_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( PROXIMITY22_ERROR == proximity22_default_cfg ( &proximity22 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}
#define PROXIMITY22_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition proximity22.h:432
void application_init(void)
Definition main.c:31
@ PROXIMITY22_ERROR
Definition proximity22.h:485

Application Task

Waits for a data ready interrupt and then reads the proximity, temperature, and ALS data (red, green, blue, and clear channels), displaying the results via UART approximately every 200 ms.

void application_task ( void )
{
proximity22_data_t meas_data;
// Wait for a data ready interrupt
while ( proximity22_get_int_pin ( &proximity22 ) );
if ( PROXIMITY22_OK == proximity22_read_data ( &proximity22, &meas_data ) )
{
log_printf ( &logger, " Proximity: %u\r\n", meas_data.proximity );
log_printf ( &logger, " Temperature: %.1f degC\r\n", meas_data.temperature );
log_printf ( &logger, " ALS data (RGBC): %u;%u;%u;%u\r\n\n", meas_data.als.red,
meas_data.als.green,
meas_data.als.blue,
meas_data.als.clear );
}
}
void application_task(void)
Definition main.c:67
@ PROXIMITY22_OK
Definition proximity22.h:484
uint16_t clear
Definition proximity22.h:495
uint16_t blue
Definition proximity22.h:498
uint16_t green
Definition proximity22.h:497
uint16_t red
Definition proximity22.h:496
proximity22_als_t als
Definition proximity22.h:510
uint16_t proximity
Definition proximity22.h:508
float temperature
Definition proximity22.h:509

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.