CapSense 2 click
CapSense 2 Click is a compact add-on board that easily integrates projected capacitive touch into user's applications. This board features the CAP1114, a multi-channel capacitive touch sensor that takes human body capacitance as an input and directly provides the real-time sensor information via the I2C serial interface from Microchip. This board contains capacitive sensing elements, a 7-segment slider, two buttons, and four LED indicators that visually detect the activation on some of these parts. This Click boardâ„¢ offers reliable and accurate sensing for any application that uses capacitive touch sensing functions.
click Product page
Click library
- Author : Stefan Filipovic
- Date : Dec 2021.
- Type : I2C type
Software Support
We provide a library for the CapSense 2 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 CapSense 2 Click driver.
Standard key functions :
capsense2_cfg_setup
Config Object Initialization function.
void capsense2_cfg_setup(capsense2_cfg_t *cfg)
CapSense 2 configuration object setup function.
CapSense 2 Click configuration object.
Definition capsense2.h:366
capsense2_init
Initialization function.
err_t capsense2_init(capsense2_t *ctx, capsense2_cfg_t *cfg)
CapSense 2 initialization function.
CapSense 2 Click context object.
Definition capsense2.h:346
capsense2_default_cfg
Click Default Configuration function.
err_t capsense2_default_cfg(capsense2_t *ctx)
CapSense 2 default configuration function.
Example key functions :
capsense2_read_register
This function reads a data byte from the selected register by using I2C serial interface.
err_t capsense2_read_register(capsense2_t *ctx, uint8_t reg, uint8_t *data_out)
CapSense 2 read register function.
capsense2_get_alert_pin
This function returns the alert pin logic state.
uint8_t capsense2_get_alert_pin(capsense2_t *ctx)
CapSense 2 get alert pin function.
capsense2_clear_interrupt
This function clears the INT bit of the main status register if the interrupt pin is asserted.
err_t capsense2_clear_interrupt(capsense2_t *ctx)
CapSense 2 clear interrupt function.
Example Description
This example demonstrates the use of CapSense 2 click board by reading and displaying the sensor's events.
The demo application is composed of two sections :
Application Init
Initializes the driver and performs the click default configuration
which resets the click board and links the desired LEDs to buttons and swipe sensors.
{
log_cfg_t log_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
if ( I2C_MASTER_ERROR ==
capsense2_init( &capsense2, &capsense2_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}
@ CAPSENSE2_ERROR
Definition capsense2.h:385
#define CAPSENSE2_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition capsense2.h:332
void application_init(void)
Definition main.c:29
Application Task
Waits for an event interrupt and displays the event on the USB UART.
{
{
uint8_t button_status = 0;
{
static uint8_t button_press_state = 0;
static uint8_t swipe_state = 0;
{
{
log_printf ( &logger, " Swipe UP \r\n\n" );
}
}
{
{
log_printf ( &logger, " Swipe DOWN \r\n\n" );
}
}
{
{
log_printf ( &logger, " Button 1 pressed \r\n\n" );
}
}
{
{
log_printf ( &logger, " Button 2 pressed \r\n\n" );
}
}
{
{
log_printf ( &logger, " Button 1 released \r\n\n" );
button_press_state &= ~CAPSENSE2_BUTTON_STATUS_1_BUTTON_1;
}
{
log_printf ( &logger, " Button 2 released \r\n\n" );
button_press_state &= ~CAPSENSE2_BUTTON_STATUS_1_BUTTON_2;
}
}
uint8_t slider = 0;
{
if ( slider )
{
log_printf ( &logger, " Slider position: %u \r\n\n", ( uint16_t ) slider );
}
else
{
swipe_state = 0;
}
}
}
}
}
@ CAPSENSE2_OK
Definition capsense2.h:384
#define CAPSENSE2_REG_SLIDER_POSITION_DATA
Definition capsense2.h:77
#define CAPSENSE2_REG_BUTTON_STATUS_1
Definition capsense2.h:74
#define CAPSENSE2_BUTTON_STATUS_1_DOWN_SLIDER
Definition capsense2.h:226
#define CAPSENSE2_BUTTON_STATUS_1_UP_SLIDER
CapSense 2 button status 1 register values.
Definition capsense2.h:225
#define CAPSENSE2_BUTTON_STATUS_1_BUTTON_1
Definition capsense2.h:228
#define CAPSENSE2_BUTTON_STATUS_1_BUTTON_2
Definition capsense2.h:227
void application_task(void)
Definition main.c:65
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.CapSense2
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.