I'm trying to use a 16-channel capacitive touch sensor named TTP229-BSF with an Arduino Uno. I use the following code that doesn't work. When I touch the keys it detects the keysworks correctly when i touch directly but also prints outwhen i place two 4 mm plexiglass pads on top and try to touch over them some times wrong keys before and after detectingnumbers are printed out in the touched keyserial terminal. I linked the required jumper as shown in the attached picture. i used 22p capacitors instead of the existing 33p sensitivity capacitors for increasing sensitivity
Is there a better and more robust way to do this based on the timing diagram of the datasheet that I attached? i tried using interrupts but it didn't work
#define SCL_PIN 98
#define SDO_PIN 3
byte Count;9
byte Key_State = 0;
/* Used to store the key state */
intbyte Key1;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 */
Key1Key = Read_Keypad();
/* If a key has been pressed output it to the serial port */
if (Key1Key)
{
Serial.println(Key1Key);
}
/* Wait a little before reading again
so not to flood the serial port*/
delay(300);
}
/* Read the state of the keypad */
byte Read_Keypad(void)
{
pinMode(SDO_PIN, OUTPUT);
digitalWrite(SDO_PIN, LOW);
delayMicroseconds(100);
digitalWrite(SDO_PIN, HIGH);
byte delayMicroseconds(100);Count;
digitalWrite(SDO_PIN,byte LOW);
Key_State = delayMicroseconds(20);0;
pinMode(SDO_PIN, INPUT);
/* 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 */
digitalWrite(SCL_PIN, HIGH);
delayMicroseconds(100);
if (!digitalRead(SDO_PIN))
Key_State = Count;
digitalWrite(SCL_PIN, LOW);
delayMicrosecondsdigitalWrite(100SCL_PIN, HIGH);
}
}
return Key_State;
}