Go Down

Topic: Wiring and using the 16 channel digital touch sensor keyboard [TTP229-BSF]? (Read 8496 times) previous topic - next topic

David1337

Hey there!

I'm having difficulties by wiring the 16 channel digital touch sensor keyboard.
I went through the datasheet of TTP229-BSF but I couldn't really understand
much since I'm still a beginner, haha. :D

As I have noticed, there are multiple options on how you can use this keyboard.
Basically, I want the keyboard to work like buttons. You press a key, you get a
signal on the output pin. How do I set it up?

This is the keyboard I'm talking about:


Thanks!

Stumpy842

I've written a short sketch to demonstrate how to use this touchpad without the need to constantly poll it for a (possible) input, as most of the other examples I have seen are doing. Here instead I'm using an external interrupt generated by the touchpad to get the key value.

If you examine the datasheet for the TTP229B you will note that the timing diagrams for 2-wires serial interface show the SDO pin generating a pulse of width DV (typ. 93uS) to signal data available. So all I do is wire SDO to INT1 and in the ISR (interrupt service routine) wait for the pulse to end, then clock the SCL pin 16 times and record the value on SDO for each clock pulse, ORing the values together.

The touchVal is a volatile global variable in the sketch used in the ISR to store the value of the touchpad key(s). Because it might change at any time, I copy it to another variable, touchValc in an atomic block to avoid it changing during the time its being accessed. Then touchValc (the copy) can be used freely in the main loop to process the key value.

Code: [Select]
/*
 * touchpad16_interrupt.ino
 *
 * Created: 5/27/2015 9:02:08 PM
 * Author: Steve Stover
 *
 * 16 Key Capacitive Touchpad using TTP229B IC
 * http://www.ebay.com/itm/371304274498
 *
 * The Touchpad has a jumper on TP1/SAHL for active high serial out
 *   and a jumper on TP2/KYSEL for 16-keys operation
 *
 * Processing the input via external interrupt INT1
 *   on an Arduino Nano v3.0
*/

#include <util/atomic.h>

#define CLR(x,y) (x&=(~(1<<y)))
#define SET(x,y) (x|=(1<<y))

#define clock_Pin 2
#define sdo_Pin 3

// Touchpad value
volatile uint16_t touchVal;  // var for ISR access
uint16_t touchValc;          // copy var for main loop

void setup() {
  Serial.begin(9600);
  pinMode(clock_Pin, OUTPUT);
  pinMode(sdo_Pin, INPUT);
  // set up INT1 on digital pin 3
  EICRA = (1 << ISC11) | (1 << ISC10);  // external INT1 on rising edge
  EIMSK = (1 << INT1);  // External Interrupt Request 1 Enable
  sei();
}

void loop() {
  ATOMIC_BLOCK(ATOMIC_FORCEON) {
    touchValc = touchVal;
  }
  if (touchValc) {
    Serial.print(touchValc, DEC);
    for (byte b=0; b<=15; b++) {
      if ((touchValc >> b) & 1) {
        Serial.print('\t'); Serial.print("bit "); Serial.print(b);
        Serial.print('\t'); Serial.print("pad "); Serial.print(b+1);
      }
    }
    Serial.println();
  }
}

ISR(INT1_vect) {
  touchVal = 0;
  delayMicroseconds(100);
  for (byte i=0; i<=15; i++) {
    SET(PORTD, clock_Pin);
    delayMicroseconds(50);
    touchVal |= (digitalRead(sdo_Pin) << i);
    CLR(PORTD, clock_Pin);
    delayMicroseconds(50);
  }
}

Stumpy842

I should also mention the datasheet refers to the pins starting with TP0, but the breakout board you've pictured starts numbering at one. So to jumper TP1 & TP2 as per the sketch above, solder jumpers across the pads as shown below (2 & 3 jumpered).

VT91

Hello David1337 ,
Did you get that touch pad to work. I got one. I want to use one to interface a project in a hermetically sealed box.
I cannot get it to work.
Thank you.

EasyGoing1

I hate to drudge up such an old post, but I wanted to add some information to make this thorough and to help anyone who might be struggling with this.

If you use the sketch that Stumpy842 created and posted just two posts above ... and if you use this image as the reference for which pins to connect to the Arduino, I marked the pins and labeled them to match the sketch so that there is no confusion there. Also don't forget to connect VCC to 3.3 and GND to ground ...  and jumper the two pin pairs that are in red (you'll have to solder them), then it will work perfectly!


Go Up