A CapSense sample using an Elephantech flex PCB electrode (CY8CKIT-044)

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

IMG_4798SS.JPG

最近、私の同僚が CapSense のデモ用に設計してエレファンテック社にオーダーしたフレキのセンサー電極を少し分けてもらうことができました。

https://www.elephantech.co.jp/

Recently one of my colleague gave me a few sensor electrode of flex PCB he designed and ordered to Elephantech.

https://www.elephantech.co.jp/en/

 

フレキと標準の変換は下記基板を入手して使いました。

I used an adapter from the URL below

https://www.aitendo.com/product/19419

 

最初、CY8CKIT-043 でも試してみたのですが、EZI2C を使用した CapSense Tuner と
KitProg 経由 UART の相性があまり良くない気がしたので、いつもの CY8CKIT-044 に乗り換えて
以前買ってあった Adafruit の TFT を使用しました。
※ ILI9341/SPI/QVGA タイプの TFT であれば他のものでも使えると思います。

https://learn.adafruit.com/adafruit-2-8-tft-touch-shield-v2

At first I tried with CY8CKIT-043, but I found that EZI2C used for the CapSense Tuner and UART via KitProg do not go well, so I changed the hourse to my trusty CY8CKIT-044 and used the Adafruit TFT, which I purchased before.
Note: Probably any TFT with ILI9341/SPI/QVGA can work, too.

https://learn.adafruit.com/adafruit-2-8-tft-touch-shield-v2

 

IMG_4799.JPGIMG_4800.JPGIMG_4805.JPG

 

Launching the CapSense Tuner / キャップセンス チューナーを起動します

003-launch_tuner.JPG

CapSense Tuner started / キャップセンス チューナーが立ち上がりました

004-Tuner_Started.JPG

 

Click "Connect" icon in the top left / 左上にある "Connect" ボタンを押します

接続されるとボタンは "Disconnect" という表示に変わります。

The button changes to "Disconnect" when connection is established.

005-connected.JPG

 

次に "Start" アイコンを押します。(私はいつもこれを忘れてしまいます。orz)

チューナーの動作が開始されると表示が "Stop" に変わります。

Then click "Start" icon. (Note: I always forget this >_< )

The button changes to "Stop" when the tuner started working.

006-Started.JPG

 

ボタン1にタッチした状態

When button1 is touched

007-button1.JPG

 

ボタン2にタッチした状態

When button2 is touched

008-button_2.JPG

 

ボタン3にタッチした状態

When button3 is touched

009-button_3.JPG

表示を GraphView タブに変えた時

Switching to the GraphView Tab

010-Graph_view.JPG

 

評価基板上のキャップセンス電極が機能するのは当然と言えるかも知れませんが、

他の電極を接続しても、殆ど手間いらずでボタンを検知できる SmartSense の機能は

ありがたいものだと思いました。

 

Although it is natural that EVB's on board electrodes work OK, when connecting other electrode and it works without any tuning nor hustle seems to be a great benefit of the SmartSense functionality.

 

schematic / トップレベル回路図

001-schematic.JPG

CapSense Configuration / キャップセンスの設定

各ボタン電極のチューニング実験をしてみたかったので

本来は一つのウィジェットで3つボタンの設定でも行けるのですが

あえて三つのウィジェットに各ボタンを割り振ってみました。

 

As I was planning to play with tuning each button electrode,

I assigned each button to different widgets.

It should work with one widget of 3 buttons, though.

001-capsense_config.JPG

Pins /  ピン設定

002-PIns.JPG

main.c

#include "project.h"
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "TFT.h"
#include "Arial12x12.h"
#include "Arial28x28.h"

#define USE_TUNER 1u

#define STR_BUF_LEN 64
char    str[STR_BUF_LEN+1] ;

typedef struct _button {
    int value ;
    int x ;
    int y ;
    int w ;
    int h ;
} Button_Type ;

#define BUTTON_WIDTH 70
#define BUTTON_HEIGHT 70

Button_Type button[3] = {
    { 0,  30, 70, 70, 70 },
    { 0, 130, 70, 70, 70 },
    { 0, 230, 70, 70, 70 }
} ;

typedef struct I2CRamBuffer
{
    uint16 u16_rawdata[CapSense_TOTAL_SENSORS];    
    uint16 u16_baseline[CapSense_TOTAL_SENSORS];    
    uint16 u16_signal[CapSense_TOTAL_SENSORS];     
    
    uint8  u8_sensorStatus;     
    
} I2CRamBuffer;	

void draw_button(Button_Type *button, uint16_t color)
{
    TFT_fillrect(button->x, button->y, button->x + button->w, button->y+button->h, color) ;
}
    
void init_hardware(void)
{
    CyGlobalIntEnable; /* Enable global interrupts. */

#if USE_TUNER
    EZI2C_Start() ;
    EZI2C_EzI2CSetBuffer1(
        sizeof(CapSense_dsRam),
        sizeof(CapSense_dsRam),
        (uint8_t *)&(CapSense_dsRam)) ;
#endif
    
    TFT_CS_Write(1) ;
    TFT_DC_Write(0) ;
    TFT_BL_Write(0) ;
    
    SPI_Init() ;
    
    SPI_Start() ;

    TFT_BusEnable(1) ;
    TFT_Init() ;
    TFT_foreground(White) ;
    TFT_background(Black) ;
    TFT_BusEnable(1) ;
    TFT_cls() ;
    TFT_BusEnable(0) ;
    
    TFT_BL_Write(1) ;
    
    CapSense_Start() ;
    CapSense_ScanAllWidgets() ;   
}

int doCapSense(Button_Type *button)
{
    int result = 0 ;

    if (CapSense_NOT_BUSY == CapSense_IsBusy()) {
        CapSense_ProcessAllWidgets() ;
#if USE_TUNER
        CapSense_RunTuner() ;
#endif
        if (CapSense_IsWidgetActive(CapSense_BUTTON0_WDGT_ID)) {
            button[0].value = CapSense_IsSensorActive(CapSense_BUTTON0_WDGT_ID, CapSense_BUTTON0_SNS0_ID) ;
            result = 1 ;
        } else {
            if (button[0].value != 0) {
                button[0].value = 0 ;
                result = 1 ;
            }
        }
        if (CapSense_IsWidgetActive(CapSense_BUTTON1_WDGT_ID)) {
            button[1].value = CapSense_IsSensorActive(CapSense_BUTTON1_WDGT_ID, CapSense_BUTTON1_SNS0_ID) ;
            result = 2 ;
        } else {
            if (button[1].value != 0) {
                button[1].value = 0 ;
                result = 2 ;
            }
        }
        if (CapSense_IsWidgetActive(CapSense_BUTTON2_WDGT_ID)) {    
            button[2].value = CapSense_IsSensorActive(CapSense_BUTTON2_WDGT_ID, CapSense_BUTTON2_SNS0_ID) ;
            result = 4 ;
        } else {
            if (button[2].value != 0) {
                button[2].value = 0 ;
                result = 4 ;
            }
        }
    }

    CapSense_ScanAllWidgets() ;
    return( result ) ;
}

int prev_button[3] = { 0, 0, 0} ;

void draw_a_button(Button_Type *button)
{
    TFT_BusEnable(1) ;
    TFT_set_font(Arial12x12) ;   
    TFT_locate(button->x + 25, button->y + 30) ;
    if (button->value) {
        draw_button(button, Yellow) ;
        TFT_background(Yellow) ;
        TFT_foreground(Black) ;
        TFT_putstr("ON ") ;
    } else {
        draw_button(button, Blue) ;
        TFT_background(Blue) ;
        TFT_foreground(White) ;
        TFT_putstr("OFF") ;
    }
    CyDelay(10) ;
    TFT_BusEnable(0) ;
}
    
void draw_buttons(Button_Type *button)
{
    int i = 0 ;
    for (i = 0 ; i < 3  ; i++ ) {     
        draw_a_button(&button[i]) ;
    }
}

int main(void)
{
    int i ;
    
    init_hardware() ;
   
    draw_buttons(button) ;
            
    for(;;) {
        if (doCapSense(button)) {
            for (i = 0 ; i < 3 ; i++ ) {
                if (button[i].value != prev_button[i]) {
                    draw_a_button(&button[i]) ;
                    prev_button[i] = button[i].value ;
                }
            }
        }
    }
}

 

moto

 

 

 

 

 

 

2 Replies
Takashi_M
Moderator
Moderator
Moderator
1000 replies posted 500 solutions authored 750 replies posted

Hello Moto-san,
Thank you very much for your contribution on this.

 

regards

Yoshihiko
Level 1
Level 1
First like received First reply posted First like given

Excellent article!