capslider2  2.0.0.0
Main Page

CAP Slider 2 click

CAP Slider 2 Click is a capacitive touch sensor with XY cross shaped electrodes integrated on a Click boardâ„¢. This click can sense touch even through plastic, wood, or other dielectric materials, which can be used to protect the surface of the PCB and the sensor pad trace itself

click Product page


Click library

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

Software Support

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

Standard key functions :

Example key functions :

  • Generic Write function

    uint8_t capsldr2_write_reg ( capslider2_t *ctx, uint8_t register_address, uint8_t *data_in, uint8_t n_bytes );

  • Generic Read function

    uint8_t capsldr2_read_reg ( capslider2_t *ctx, uint8_t register_address, uint8_t *data_out, uint8_t n_bytes );

  • Data Ready Check function

    uint8_t capsldr2_check_data_ready ( capslider2_t *ctx );

Examples Description

This application could be used for controlling various devices.

The demo application is composed of two sections :

Application Init

Initializes I2C interface, performs the device reset and configurations and sets the desired threshold value which determines sensor sensitivity.

void application_init ( void )
{
log_cfg_t log_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, "---- Application Init ----" );
// Click initialization.
CAPSLIDER2_MAP_MIKROBUS( cfg, MIKROBUS_1 );
capslider2_init( &capslider2, &cfg );
Delay_ms( 500 );
cnt = 0;
capsldr2_reset( &capslider2 );
Delay_ms( 500 );
capsldr2_config( &capslider2 );
capsldr2_set_threshold( &capslider2, 0x04 );
Delay_ms( 4000 );
log_printf( &logger, "CAP Slider 2 is initialized\r\n" );
}

Application Task

Checks for data ready and then read capacitance from all channels. There are two sliders on the clik board (X and Y). X slider selects which LEDs are being activated, while Y slider increases/decreases the LEDs intensity.

void application_task ( void )
{
uint16_t data_wheel1;
uint16_t data_wheel2;
uint8_t ready_check;
ready_check = capsldr2_check_data_ready( &capslider2 );
if (ready_check == CAPSLDR2_DATA_READY)
{
capsldr2_get_data( &capslider2, &data_wheel1, &data_wheel2 );
wheel_avrg1 += data_wheel1;
wheel_avrg2 += data_wheel2;
cnt++;
}
if (cnt == 1)
{
if ((wheel_avrg2 / cnt) > 1800)
{
}
else if (((wheel_avrg2 / cnt) < 1650) && ((wheel_avrg2 / cnt) > 1000))
{
}
cnt = 0;
}
}

Note

In some cases, the user will need to wait several seconds after the click initialization for the sensor to be stabilized.

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

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.


CAPSLDR2_CH2_EN
#define CAPSLDR2_CH2_EN
Definition: capslider2.h:148
wheel_avrg1
uint32_t wheel_avrg1
Definition: main.c:40
CAPSLDR2_CH7_EN
#define CAPSLDR2_CH7_EN
Definition: capslider2.h:153
out_val
uint16_t out_val
Definition: main.c:42
wheel_avrg2
uint32_t wheel_avrg2
Definition: main.c:41
vertical_check
void vertical_check()
Definition: main.c:52
CAPSLDR2_CH6_EN
#define CAPSLDR2_CH6_EN
Definition: capslider2.h:152
CAPSLDR2_DATA_READY
#define CAPSLDR2_DATA_READY
Definition: capslider2.h:179
capslider2_cfg_setup
void capslider2_cfg_setup(capslider2_cfg_t *cfg)
Config Object Initialization function.
application_task
void application_task(void)
Definition: main.c:102
capsldr2_enable_chann
uint8_t capsldr2_enable_chann(capslider2_t *ctx, uint16_t sel_chann)
Channel Enable function.
capslider2_cfg_t
Click configuration structure definition.
Definition: capslider2.h:231
CAPSLDR2_CH8_EN
#define CAPSLDR2_CH8_EN
Definition: capslider2.h:154
CAPSLDR2_CH5_EN
#define CAPSLDR2_CH5_EN
Definition: capslider2.h:151
cnt
uint8_t cnt
Definition: main.c:44
CAPSLDR2_CH0_PROX_EN
#define CAPSLDR2_CH0_PROX_EN
Definition: capslider2.h:146
CAPSLDR2_CH4_EN
#define CAPSLDR2_CH4_EN
Definition: capslider2.h:150
CAPSLDR2_CH1_EN
#define CAPSLDR2_CH1_EN
Definition: capslider2.h:147
capsldr2_reset
void capsldr2_reset(capslider2_t *ctx)
Reset function.
capsldr2_set_output
void capsldr2_set_output(capslider2_t *ctx, uint8_t input_data, uint8_t output_mode)
Output Set function.
capsldr2_config
void capsldr2_config(capslider2_t *ctx)
Config function.
CAPSLDR2_CH9_EN
#define CAPSLDR2_CH9_EN
Definition: capslider2.h:155
out_mode
uint8_t out_mode
Definition: main.c:43
capslider2_init
CAPSLIDER2_RETVAL capslider2_init(capslider2_t *ctx, capslider2_cfg_t *cfg)
Initialization function.
CAPSLDR2_CH3_EN
#define CAPSLDR2_CH3_EN
Definition: capslider2.h:149
application_init
void application_init(void)
Definition: main.c:59
horizontal_check
void horizontal_check()
Definition: main.c:46
CAPSLIDER2_MAP_MIKROBUS
#define CAPSLIDER2_MAP_MIKROBUS(cfg, mikrobus)
Definition: capslider2.h:63
capsldr2_get_data
void capsldr2_get_data(capslider2_t *ctx, uint16_t *wheel_data1, uint16_t *wheel_data2)
Data Get function.
capsldr2_check_data_ready
uint8_t capsldr2_check_data_ready(capslider2_t *ctx)
Data Ready Check function.
capsldr2_set_threshold
void capsldr2_set_threshold(capslider2_t *ctx, uint8_t thresh_value)
Threshold Set function.