proximity10  2.0.0.0
Main Page

Proximity 10 click

Proximity 10 Click is a versatile proximity detection device on a Click boardâ„¢. It can detect a foreign object distanced up to 20cm.

click Product page


Click library

  • Author : MikroE Team
  • Date : jan 2020.
  • Type : I2C type

Software Support

We provide a library for the Proximity10 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 form compilers IDE(recommended way), or downloaded from our LibStock, or found on mikroE github account.

Library Description

This library contains API for Proximity10 Click driver.

Standard key functions :

Example key functions :

  • This function checks the desired interrupt flags status.

    uint8_t proximity10_check_int_status ( proximity10_t *ctx, uint8_t bit_mask, uint8_t clear_en );

  • This function allows user to execute a desired command and checks the response.

    uint8_t proximity10_send_command ( proximity10_t *ctx, uint8_t prox_command );

  • This function sets the selected parameter to the desired value, and checks the response.

    uint8_t proximity10_param_set ( proximity10_t *ctx, uint8_t param_addr, uint8_t param_value );

Examples Description

This application enables proximity sensor to detect objects from distance up to 20cm.

The demo application is composed of two sections :

Application Init

Initializes I2C serial interface and performs a device wake up, reset and all necessary configurations. The device will wake up and performs measurements every 10 milliseconds.

void application_init ( void )
{
log_cfg_t log_cfg;
uint8_t w_temp;
uint8_t cmd_resp;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, "---- Application Init ----" );
// Click initialization.
PROXIMITY10_MAP_MIKROBUS( cfg, MIKROBUS_1 );
proximity10_init( &proximity10, &cfg );
Delay_ms( 500 );
proximity10_generic_write( &proximity10, PROXIMITY10_HW_KEY_REG, &w_temp, 1 );
cmd_resp = proximity10_send_command( &proximity10, PROXIMITY10_NOP_CMD );
check_response( cmd_resp );
cmd_resp = proximity10_send_command( &proximity10, PROXIMITY10_RESET_CMD );
check_response( cmd_resp );
Delay_ms( 200 );
check_response( cmd_resp );
check_response( cmd_resp );
check_response( cmd_resp );
check_response( cmd_resp );
proximity10_default_cfg ( &proximity10 );
check_response( cmd_resp );
//Sound_Init( &GPIOE_ODR, 14 ); //??
log_printf( &logger, "** Proximity 10 is initialized **\r\n" );
log_printf( &logger, "**************************************\r\n" );
Delay_ms( 500 );
}

Application Task

Reads the proximity PS1 data value and sends result to the uart terminal. If measured proximity value is greater than selected proximity threshold value, the interrupt will be generated and the message will be showed on the uart terminal. When interrupt is generated the Sound function will make an alarm sound with determined duration depending on the > detected proximity value, how much is object away or close from the sensor.

void application_task ( void )
{
// Task implementation.
uint32_t proximity;
uint8_t temp_read[ 2 ];
uint8_t int_status;
uint16_t alarm_dur;
proximity10_generic_read( &proximity10, PROXIMITY10_PS1_DATA_REG, &temp_read, 2 );
proximity = temp_read[ 1 ];
proximity <<= 8;
proximity |= temp_read[ 0 ];
log_printf( &logger, "** Proximity PS1 : %u \r\n", proximity );
if ( int_status == PROXIMITY10_PS1_INT_FLAG )
{
log_printf( &logger, "** Object is detected **\r\n" );
alarm_dur = proximity / 100;
alarm_dur = alarm_dur + 35;
alarm_dur = ( float )( alarm_dur * 0.30928 );
alarm_dur = 180 - alarm_dur;
// Sound_Play( 1400, alarm_dur ); //??
Delay_ms( 100 );
}
else
{
Delay_ms( 200 );
}
log_printf( &logger, "**************************************\r\n" );
}

Note

Additional Functions :

  • checkResponse - Sends an error code message to the uart terminal if error code is detected in the response.

The full application code, and ready to use projects can be installed directly form compilers IDE(recommneded) or found on LibStock page or mikroE GitHub accaunt.

Other mikroE Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.Proximity10

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. The terminal available in all Mikroelektronika compilers, or any other terminal application of your choice, can be used to read the message.


PROXIMITY10_EN_ALS_VIS
#define PROXIMITY10_EN_ALS_VIS
Definition: proximity10.h:226
proximity10_generic_read
uint8_t proximity10_generic_read(proximity10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
proximity10_cfg_setup
void proximity10_cfg_setup(proximity10_cfg_t *cfg)
Config Object Initialization function.
PROXIMITY10_RESET_CMD
#define PROXIMITY10_RESET_CMD
Definition: proximity10.h:281
PROXIMITY10_NOP_CMD
#define PROXIMITY10_NOP_CMD
Definition: proximity10.h:280
PROXIMITY10_ADC_CLOCK_DIV_4
#define PROXIMITY10_ADC_CLOCK_DIV_4
Definition: proximity10.h:247
application_task
void application_task(void)
Definition: main.c:149
proximity10_cfg_t
Click configuration structure definition.
Definition: proximity10.h:342
PROXIMITY10_MAP_MIKROBUS
#define PROXIMITY10_MAP_MIKROBUS(cfg, mikrobus)
Definition: proximity10.h:53
PROXIMITY10_NORMAL_SIGNAL_RANGE
#define PROXIMITY10_NORMAL_SIGNAL_RANGE
Definition: proximity10.h:254
PROXIMITY10_PS_ADC_GAIN_PARAM
#define PROXIMITY10_PS_ADC_GAIN_PARAM
Definition: proximity10.h:202
proximity10_generic_write
uint8_t proximity10_generic_write(proximity10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
PROXIMITY10_INT_CLEAR_DIS
#define PROXIMITY10_INT_CLEAR_DIS
Definition: proximity10.h:298
PROXIMITY10_HW_KEY_REG
#define PROXIMITY10_HW_KEY_REG
Definition: proximity10.h:87
PROXIMITY10_EN_ALS_IR
#define PROXIMITY10_EN_ALS_IR
Definition: proximity10.h:225
PROXIMITY10_NORMAL_PROX_MEAS_MODE
#define PROXIMITY10_NORMAL_PROX_MEAS_MODE
Definition: proximity10.h:257
PROXIMITY10_PS_AUTO_CMD
#define PROXIMITY10_PS_AUTO_CMD
Definition: proximity10.h:289
PROXIMITY10_PSLED12_SEL_PARAM
#define PROXIMITY10_PSLED12_SEL_PARAM
Definition: proximity10.h:194
PROXIMITY10_HW_KEY
#define PROXIMITY10_HW_KEY
Definition: proximity10.h:141
proximity10_init
PROXIMITY10_RETVAL proximity10_init(proximity10_t *ctx, proximity10_cfg_t *cfg)
Initialization function.
PROXIMITY10_PS_ADC_MISC_PARAM
#define PROXIMITY10_PS_ADC_MISC_PARAM
Definition: proximity10.h:203
proximity10_check_int_status
uint8_t proximity10_check_int_status(proximity10_t *ctx, uint8_t bit_mask, uint8_t clear_en)
Check INT Flags function.
application_init
void application_init(void)
Definition: main.c:90
proximity10_param_set
uint8_t proximity10_param_set(proximity10_t *ctx, uint8_t param_addr, uint8_t param_value)
Parameter Set function.
proximity10_default_cfg
void proximity10_default_cfg(proximity10_t *ctx)
Click Default Configuration function.
PROXIMITY10_CHLIST_PARAM
#define PROXIMITY10_CHLIST_PARAM
Definition: proximity10.h:193
PROXIMITY10_LED1_DRIVE_EN
#define PROXIMITY10_LED1_DRIVE_EN
Definition: proximity10.h:232
check_response
void check_response(uint8_t cmd_resp)
Definition: main.c:42
proximity10_send_command
uint8_t proximity10_send_command(proximity10_t *ctx, uint8_t prox_command)
Command Send function.
PROXIMITY10_PS1_INT_FLAG
#define PROXIMITY10_PS1_INT_FLAG
Definition: proximity10.h:179
PROXIMITY10_EN_AUX
#define PROXIMITY10_EN_AUX
Definition: proximity10.h:224
PROXIMITY10_PS1_DATA_REG
#define PROXIMITY10_PS1_DATA_REG
Definition: proximity10.h:104
PROXIMITY10_EN_PS1
#define PROXIMITY10_EN_PS1
Definition: proximity10.h:229