0
\$\begingroup\$

I'm trying to use a 16-channel capacitive touch sensor named TTP229-BSF with an Arduino Uno. I use the following code it works correctly when i touch directly but when i place two 4 mm plexiglass pads on top and try to touch over them some times wrong numbers are printed out in the serial 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

What is the problem here?

Is there a better and more robust way to do this based on the timing diagram of the datasheet that I attached?

#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(300);
}


/* 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; 
}

enter image description here

enter image description here enter image description here

\$\endgroup\$
7
  • \$\begingroup\$ Where did you put the delay? It is important to know, to understand if it was in the right or wrong place. \$\endgroup\$
    – Justme
    Commented May 24, 2022 at 7:08
  • \$\begingroup\$ i put one delay after making SCL high and one delay after making SCL low @Justme \$\endgroup\$
    – salar1991
    Commented May 24, 2022 at 8:06
  • \$\begingroup\$ Are the wrong numbers printed close to the correct numbers or just random anywhere? The contact zone between both plexiglass plates may introduce distortion in the E fields, especially with fingerprints on them. \$\endgroup\$
    – Jens
    Commented May 25, 2022 at 14:17
  • \$\begingroup\$ @Jens the wrong numbers are random \$\endgroup\$
    – salar1991
    Commented May 26, 2022 at 3:40
  • 1
    \$\begingroup\$ @salar1991: I think touching this IC is a variation of touching GND. Your body then has a better GND connection and the sensor chip receives less noise and senses a higher capacitance. \$\endgroup\$
    – Jens
    Commented Jun 6, 2022 at 14:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.