TOP Contributors

  1. MIKROE (2779 codes)
  2. Alcides Ramos (376 codes)
  3. Shawon Shahryiar (307 codes)
  4. jm_palomino (118 codes)
  5. Bugz Bensce (97 codes)
  6. S P (73 codes)
  7. dany (71 codes)
  8. MikroBUS.NET Team (35 codes)
  9. NART SCHINACKOW (34 codes)
  10. Armstrong Subero (27 codes)

Most Downloaded

  1. Timer Calculator (139563 times)
  2. FAT32 Library (72041 times)
  3. Network Ethernet Library (57255 times)
  4. USB Device Library (47615 times)
  5. Network WiFi Library (43219 times)
  6. FT800 Library (42563 times)
  7. GSM click (29930 times)
  8. mikroSDK (28292 times)
  9. PID Library (26930 times)
  10. microSD click (26309 times)
Libstock prefers package manager

Package Manager

We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]

< Back
mikroSDK Library

CapSense 2 Click

Rating:

0

Author: MIKROE

Last Updated: 2024-10-31

Package Version: 2.1.0.11

mikroSDK Library: 2.0.0.0

Category: Capacitive

Downloaded: 181 times

Not followed.

License: MIT license  

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.

No Abuse Reported

Do you want to subscribe in order to receive notifications regarding "CapSense 2 Click" changes.

Do you want to unsubscribe in order to stop receiving notifications regarding "CapSense 2 Click" changes.

Do you want to report abuse regarding "CapSense 2 Click".

  • Information
  • Comments (0)

mikroSDK Library Blog


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.

capsense2_click.png

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 );
  • capsense2_init Initialization function.

    err_t capsense2_init ( capsense2_t *ctx, capsense2_cfg_t *cfg );
  • capsense2_default_cfg Click Default Configuration function.

    err_t capsense2_default_cfg ( capsense2_t *ctx );

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 );
  • capsense2_get_alert_pin This function returns the alert pin logic state.

    uint8_t capsense2_get_alert_pin ( capsense2_t *ctx );
  • 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 );

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.


void application_init ( void )
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    capsense2_cfg_t capsense2_cfg;  /**< Click config object. */

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, " Application Init " );

    // Click initialization.
    capsense2_cfg_setup( &capsense2_cfg );
    CAPSENSE2_MAP_MIKROBUS( capsense2_cfg, MIKROBUS_1 );
    if ( I2C_MASTER_ERROR == capsense2_init( &capsense2, &capsense2_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }

    if ( CAPSENSE2_ERROR == capsense2_default_cfg ( &capsense2 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }

    log_info( &logger, " Application Task " );
}

Application Task

Waits for an event interrupt and displays the event on the USB UART.

void application_task ( void )
{
    if ( capsense2_get_alert_pin ( &capsense2 ) )
    {
        uint8_t button_status = 0;
        if ( CAPSENSE2_OK == capsense2_read_register ( &capsense2, CAPSENSE2_REG_BUTTON_STATUS_1, &button_status ) )
        {
            static uint8_t button_press_state = 0;
            static uint8_t swipe_state = 0;
            if ( button_status & CAPSENSE2_BUTTON_STATUS_1_UP_SLIDER )
            {
                if ( CAPSENSE2_BUTTON_STATUS_1_UP_SLIDER != swipe_state )
                {
                    log_printf ( &logger, " Swipe UP \r\n\n" );
                    swipe_state = CAPSENSE2_BUTTON_STATUS_1_UP_SLIDER;
                }
            }
            if ( button_status & CAPSENSE2_BUTTON_STATUS_1_DOWN_SLIDER )
            {
                if ( CAPSENSE2_BUTTON_STATUS_1_DOWN_SLIDER != swipe_state )
                {
                    log_printf ( &logger, " Swipe DOWN \r\n\n" );
                    swipe_state = CAPSENSE2_BUTTON_STATUS_1_DOWN_SLIDER;
                }
            }
            if ( button_status & CAPSENSE2_BUTTON_STATUS_1_BUTTON_1 )
            {
                if ( !( button_press_state & CAPSENSE2_BUTTON_STATUS_1_BUTTON_1 ) )
                {
                    log_printf ( &logger, " Button 1 pressed \r\n\n" );
                    button_press_state |= CAPSENSE2_BUTTON_STATUS_1_BUTTON_1;
                }
            }
            if ( button_status & CAPSENSE2_BUTTON_STATUS_1_BUTTON_2 )
            {
                if ( !( button_press_state & CAPSENSE2_BUTTON_STATUS_1_BUTTON_2 ) )
                {
                    log_printf ( &logger, " Button 2 pressed \r\n\n" );
                    button_press_state |= CAPSENSE2_BUTTON_STATUS_1_BUTTON_2;
                }
            }
            capsense2_clear_interrupt ( &capsense2 );

            // check if buttons are released
            if ( CAPSENSE2_OK == capsense2_read_register ( &capsense2, CAPSENSE2_REG_BUTTON_STATUS_1, &button_status ) )
            {
                if ( ( button_press_state & CAPSENSE2_BUTTON_STATUS_1_BUTTON_1 ) && 
                    !( button_status & CAPSENSE2_BUTTON_STATUS_1_BUTTON_1 ) )
                {
                    log_printf ( &logger, " Button 1 released \r\n\n" );
                    button_press_state &= ~CAPSENSE2_BUTTON_STATUS_1_BUTTON_1;
                }
                if ( ( button_press_state & CAPSENSE2_BUTTON_STATUS_1_BUTTON_2 ) && 
                    !( button_status & CAPSENSE2_BUTTON_STATUS_1_BUTTON_2 ) )
                {
                    log_printf ( &logger, " Button 2 released \r\n\n" );
                    button_press_state &= ~CAPSENSE2_BUTTON_STATUS_1_BUTTON_2;
                }
            }

            // check if swipe event is finished and display the slider position
            uint8_t slider = 0;
            if ( CAPSENSE2_OK == capsense2_read_register ( &capsense2, CAPSENSE2_REG_SLIDER_POSITION_DATA, &slider ) )
            {
                if ( slider )
                {
                    log_printf ( &logger, " Slider position: %u \r\n\n", ( uint16_t ) slider );
                }
                else
                {
                    swipe_state = 0;
                }
            }
        }
        capsense2_clear_interrupt ( &capsense2 );
    }
}

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.


ALSO FROM THIS AUTHOR

Load Cell 7 Click

0

Load Cell 7 Click is a compact add-on board representing a weigh scale solution. This board features the ADS1230, a high-precision 20-bit delta-sigma analog-to-digital converter (ADC) with an outstanding noise performance from Texas Instruments. This SPI-configurable ADC (read-only) offers selectable gain and data rate values, supporting a full-scale differential input of ±39mV/±19.5mV and 10SPS/80SPS, respectively. It comes with an onboard low-noise programmable gain amplifier (PGA) and onboard oscillator providing a complete front-end solution.

[Learn More]

Clock Gen 3 click

5

Clock Gen 3 Click features a low power self-contained digital frequency source providing a precision frequency from 1kHz to 68MHz, set through a serial port.

[Learn More]

RTC 13 Click

0

RTC 13 Click is a compact add-on board that accurately keeps the time of a day. This board features the PCF2123, an SPI configurable real-time clock/calendar optimized for low power operations from NXP Semiconductors. The PCF2123 provides year, month, day, weekday, hours, minutes, and seconds based on a 32.768kHz quartz crystal. Data is transferred serially via an SPI interface with a maximum data rate of 6.25 Mbit/s. An alarm and timer function is also available, providing the possibility to generate a wake-up signal on an interrupt line, in addition to a programmable square-wave clock output. This Click board™ is suitable for various time-keeping applications, including high-duration timers, metering, daily alarms, low standby power applications, and many more.

[Learn More]