TTP229 (capacitive touchpad) and I2C

Hi,
I just got myself a TTP229- based 16 button touchpad [datasheet + schematic]. I found a few tutorials online [1] [2] [3] [4] but in all of these tutorials the communication is done "manually" instead of using the I2C library (which the TTP229 supports).

I tried to implement communication via I2C. My code:

#include <Wire.h>
#include <Arduino.h>

//identify code: 1010, device address: 111, read: 1
//10101111 = 0xAF
#define I2C_ADDRESS 0xAF  

uint8_t btn_state;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  
  Wire.begin();
}

void loop() {
  // put your main code here, to run repeatedly:
  
  Wire.requestFrom(I2C_ADDRESS, 1, true);
  
  btn_state = Wire.read();
  Serial.println(btn_state, BIN);
  
  delay(200);
}

what should happen:
when no button is pressed the Arduino should receive 11111111.
when a button (1 - 8 ) is pressed the Arduino should receive a byte with one bit set to 0, depending on the button pressed (for example: button 1 - 11111110, button 8 - 01111111)
when any of the other buttons is pressed (9 - 16) the Arduino should receive 11111111 (because only buttons 1 - 8 are currently enabled).

what actually happens:
when no button is pressed, the Arduino receives 11111111.
when button 1 is pressed, the Arduino receives 11111110.
when button 3 is pressed, the Arduino receives nothing.
when button 2 or 4 - 8 is pressed, Wire.requestFrom() blocks the code.
when any other button is pressed (9 - 16) the Arduino receives 11111111.

the sketch in link #4 above works as expected (reversed bit order: 1 = 01111111, 8 = 11111110).

can someone help me with this?

push no one?

http://forum.arduino.cc/index.php?topic=301382.msg2252580#msg2252580

Uses external interrupt, no polling needed :wink:

originally i was hoping to integrate this touchpad in an i2c environment, but all i got so far was weird behaviour :frowning: some buttons work, some don't, some make the arduino lock up until i reset...

your solution looks interresting. if i decide to integrate this touchpad into my project i will probably use your code, but chances are i will get myself a touchpad that actually works as advertised :smiley:

#define SCL_PIN 8
#define SDO_PIN 9
/* Used to store the key state /
byte Key;
void setup()
{
/
Initialise the serial interface /
Serial.begin(9600);
/
Configure the clock and data pins /
pinMode(SCL_PIN, OUTPUT);
pinMode(SDO_PIN, INPUT);
}
/
Main program /
void loop()
{
/
Read the current state of the keypad /
Key = Read_Keypad();
/
If a key has been pressed output it to the serial port /
if (Key)
Serial.println(Key);
/
Wait a little before reading again
so not to flood the serial port*/
delay(100);
}
/* Read the state of the keypad /
byte Read_Keypad(void)
{
byte Count;
byte Key_State = 0;
/
Pulse the clock pin 16 times (one for each key of the keypad)
and read the state of the data pin on each pulse /
for(Count = 1; Count <= 16; Count++)
{
digitalWrite(SCL_PIN, LOW);
/
If the data pin is low (active low mode) then store the
current key number */
if (!digitalRead(SDO_PIN))
Key_State = Count;
digitalWrite(SCL_PIN, HIGH);
}

return Key_State;
}

same source code i uploaded but iam not able to get values it is sensing some random value