TouchClamp click is a touch board that caries the MPR121 second generation NXP capacitive touch controller. The board uses a very well known capacitive sensing technology, one we have already described in the CapSense article. Now this technology is starting to find its way into several innovative products such as the devices that change your desk into a PC interface device. Devices like these open up a physical interaction world as wide as your imagination.
TouchClamp has seven electrodes and one button to extend its functionality. All electrodes can be configured independently from each other. This allows a wide range of possibles and implementation choices. Including:
- General Purpose Capacitive Detection
- Switch Replacements
- Touch Buttons
- Touch Keypad
- Touch Slide bar
- Touch Wheel
- Touchpad
- Touch Panel
- Near Proximity Detection
Communication with host MCU is achieved through I2C and a interrupt signal from the MPR121. Power consumption is 29 μA at 16 ms sampling rate interval period. Just amazing.
TouchClamp Measurement Description
Total measurable sensing channels available is 13 channels, including 12 physical electrode inputs and one multiplexed 13 channel for proximity detection. A multiplexer is included internally at the front end, so the 13 channels are measured sequentially in time. Capacitance is measured, noise filtered and finally touch / release status is determined. Keep on mind, that in the case of our click board, you have 7 electrodes available and one pre-configured as a button in the H electrode.
The capacitance measured on each sensing channel, is the total capacitance to ground which can be the combination of background parasitic capacitance to ground ( Cb ) and finger touch induced capacitance to ground ( Cx ). This ground refers to the common ground when the device is not electrically floated, and refers to the MPR121 device ground when the device is floated for example powered by batteries.
The ADC raw data outputs run through 3 levels of digital filtering to filter out the high frequency and low frequency noise. The first level filter is a simple running average filter configured by FFI which is the number of samples used for the filter. The second level filter result is 10 bit and stored in the output data registers ( 0x04 ~ 0x1D ) as the immediate capacitance of each sensing input. The filter control parameter are SFI and ESI. The third level filter result is an even lower frequency content of signal change using the second level filter output, and is mainly used as the baseline value representing the capacitance variation over the long term and slow environment change such as atmospheric moisture and dirt for touch detection. There are two sets of filter control parameters, all the 7 electrodes baseline share the same set of parameters. The third level filtered result is internally 10 bit but only high 8 bits are readable from registers 0x1E~0x2A as the baseline value output for each channel.
Example
The idea for an example was to make something like the store where a customer can get information about product by touching it. In this example we have used the supplies placed inside jars. Click board electrodes are connected with clamp to the metal lids. Keep on mind that you can make connections between electrodes and any kind of object that is electric conductive( fruit, vegetables, tin etc ).
First of all click boards require proper bus initialization. After that a call to execute tc_hal_init with I2C address provided, which depends on jumper position on the board front side. Finally, you can configure the click board using tc_default_config or you can configure it on your own way depend on usage.
#include "touch_clamp_hw.h" #include "touch_clamp_hal.h" #include "resources.h" unsigned int TFT_DataPort at GPIOE_ODR; sbit TFT_RST at GPIOE_ODR.B8; sbit TFT_RS at GPIOE_ODR.B12; sbit TFT_CS at GPIOE_ODR.B15; sbit TFT_RD at GPIOE_ODR.B10; sbit TFT_WR at GPIOE_ODR.B11; sbit TFT_BLED at GPIOE_ODR.B9; uint8_t status = 0; uint8_t status_last = 0; void system_init() { I2C1_Init_Advanced( 100000, &_GPIO_MODULE_I2C1_PB67 ); Delay_ms( 200 ); } static void display_init() { TFT_Init_ILI9341_8bit( 320, 240 ); TFT_Set_Pen( CL_WHITE, 1 ); TFT_Set_Brush( 1, CL_WHITE, 0, 0, 0, 0 ); TFT_Set_Font( TFT_defaultFont, CL_BLACK, FO_HORIZONTAL ); TFT_Fill_Screen( CL_WHITE); TFT_Set_Pen( CL_Black, 1 ); TFT_Line( 20, 220, 300, 220 ); TFT_LIne( 20, 46, 300, 46 ); TFT_Set_Font( &HandelGothic_BT21x22_Regular, CL_RED, FO_HORIZONTAL); TFT_Write_Text( "TouchClamp click", 75, 14 ); TFT_Set_Font( &Verdana12x13_Regular, CL_BLACK, FO_HORIZONTAL ); TFT_Write_Text( "EasyMx PRO v7 for STM32", 19, 223); TFT_Set_Font( &Verdana12x13_Regular, CL_RED, FO_HORIZONTAL ); TFT_Write_Text( "www.mikroe.com", 200, 223 ); TFT_Set_Font( &Tahoma15x16_Bold, CL_BLUE, FO_HORIZONTAL ); TFT_Set_Pen( CL_WHITE, 1 ); } void main() { system_init(); display_init(); tc_hal_init( 0x5A ); tc_default_config(); Delay_ms( 200 ); while( 1 ) { status = tc_get_reg_ts(); if( status != status_last ) { TFT_Rectangle( 30, 50, 310, 210 ); if( status & ( 1 << ELE_A ) ) { TFT_Write_Text( "Ajvar", 135, 60 ); TFT_Image_Jpeg( 40, 90, ajvar_jpg ); } if( status & ( 1 << ELE_C ) ) { TFT_Write_Text( "Coffee", 135, 60 ); TFT_Image_Jpeg( 40, 90, coffee_jpg ); } if( status & ( 1 << ELE_E ) ) { TFT_Write_Text( "Sugar", 135, 60 ); TFT_Image_Jpeg( 40, 90, sugar_jpg ); } if( status & ( 1 << ELE_G ) ) { TFT_Write_Text( "Muesli", 135, 60 ); TFT_Image_Jpeg( 40, 90, muesli_jpg ); } } status_last = status; } }
Summary
TouchClamp is a cost and energy effective solution that gives you a wide choice of possible implementations for all your ideas. Libraries for our compilers can be downloaded from Libstock or you can use the source found at GitHub.