TTP223 touch capacitance buttons - debouncing required?

Edit - I realised this should perhaps have been posted to the elctronics forum, please move if needed - thanks!

It's probably obvious, but I wanted to check.

I have several TTP223 touch buttons like THIS.

  1. Do I need to be using the CapacitiveSensor library, or can it just be treated as a button?

  2. Is software debouncing required?

  3. If I wire two in parallel to an Arduino input (and 3.3V/GND supply), when one is pressed the other TP223 lights up. Do I need diode or similar?

Thanks

From that tutorial, treat it as a debounced button.

Bounce happens when contacts with voltage across them spark across a gap between them, however short.

Cap sense methods are all very different. The bought buttons connected to touch sense port pins work better than DIY sensors on digital pins.

  1. If I wire two in parallel to an Arduino input (and 3.3V/GND supply), when one is pressed the other TP223 lights up. Do I need diode or similar?

Yes. But a diode will drop the voltage and using 3.3v, plus the diode drop, may not give you a good enough high for a 5 volt Arduino's input. If you can, use the TTP233 on 5 volts.

Schottkey diodes drop about 0.3V.

Why not use 2 pins for 2 buttons and do the connecting in software?

877:
If I wire two in parallel to an Arduino input (and 3.3V/GND supply), when one is pressed the other TP223 lights up. Do I need diode or similar?

No, it's simple.

Do not wire two in parallel. :roll_eyes:

GoForSmoke:
Schottkey diodes drop about 0.3V.

Why not use 2 pins for 2 buttons and do the connecting in software?

That is an excellent and obvious idea! :slight_smile:
Thanks

Paul__B:
No, it's simple.

Do not wire two in parallel. :roll_eyes:

Now I know :slight_smile:

Hi,

Have you tried this Bounce2 library to software debounce your inputs?

Tom... :slight_smile:

Cap sense don't bounce.

Hi,

How do you know its bounce?

As this is a capacitive sensor, its input impedance will be high, have you got any wiring around the sensors that could contribute towards the effect of bounce?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Can you post a picture of your project so we can see your component layout?

Thanks.. Tom.. :slight_smile:

It's not a contact switch, there's no sparking. You're timing how long a probe takes to charge to see if it's sufficiently coupled with a field to call it a touch.

I used 2 of the Arduino Playground cap sense articles to make different cap sense probes work. The ones you buy that connect to touch sense port pins (Uno has none) work better in a more active fashion but basically the same. You want pictures from 6 or 7 years ago?

I don't get bounce from piezos as buttons or light reflect or beam break or ultrasonic ping or Hall sensing or much any except for switches that open and close contacts.

@GoForSmoke thanks for the info, I also thought there would be no bouncing, just wanted to check.

I've just finished building the circuit, with 2 x TTP223's going to different inputs, and a relay coil connected to another.

I've wired it with pull down resistors as it seemed good practice, not sure if they are required though?

I've just go a cheap oscilloscope so am interested to see how the response looks, if it actually works :slight_smile:

Here is the completed layout:

Wemos D1 mini
Dual base
Relay shield

Wiring:
Power to each switch - 3V and GND
Left switch (orange wire) to D5
Right switch (yellow wire) to D7
Relay - activates via D6 (soldered on rear of shield)

Also - damn you 5 minute delay between posts!!

Here is the code, works perfectly on a breadboard. Seems too simple!

Will be interesting to see how it works in real life (one switch would be aprox 6m away). I wonder if capacitance would cause an issue.

//v002 - 2 x TTP223 touch switches (pulled low), Wemos D1 mini, Relay shield.
//Credits to 3Dgeo for help with the code originally

const byte TOUCH1_Pin = D5; // define your buttons pins here
const byte RELAY_Pin = D6; // define your relay shield pin here
const byte TOUCH2_Pin = D7; // define your buttons pins here


void setup()
{
  pinMode(RELAY_Pin , OUTPUT);    //sets relay pin D6 as an output
  digitalWrite(RELAY_Pin, LOW);   //sets relay to OFF state
  pinMode(TOUCH1_Pin, INPUT);     //sets touch button 1 as an input
  pinMode(TOUCH2_Pin, INPUT);     //sets touch button 2 as an input
  
  attachInterrupt(digitalPinToInterrupt(TOUCH1_Pin), flipRelayOutput, HIGH); // making I/O pin as interrupt pin, triggers on high state
  attachInterrupt(digitalPinToInterrupt(TOUCH2_Pin), flipRelayOutput, HIGH); // making I/O pin as interrupt pin, triggers on high state
}


void loop()
{

}


void flipRelayOutput()  // a function to flip the relay output, is called from the physical button.
{
  digitalWrite(RELAY_Pin, !digitalRead(RELAY_Pin));    //writes the inverse value to the relay pin  (booleon NOT operator )
}

For anyone who cares, here is the oscilloscope screenshot, looks nice with no debouncing :slight_smile:

877:
I've just finished building the circuit, with 2 x TTP223's going to different inputs, and a relay coil connected to another.

You had me worried there - suggesting connecting a relay coil to a GPIO pin, but you are in fact using the correct relay module with its driver transistor and flyback diode.

877:
I've wired it with pull down resistors as it seemed good practice, not sure if they are required though?

They are not required and it is not "good practice". It is important to use components where they are specifically required.
Datasheet

Paul__B:
They are not required and it is not "good practice". It is important to use components where they are specifically required.

Consider me officially told off :slight_smile:

The datasheet link is to my imgur page, you must have copied it by mistake. But I can find it via google no probs.

Thanks

If the button module makes the signal pin either HIGH or LOW you don't need a pulldown, it just wastes current when the pin is HIGH.

AVR INPUT read takes 1 microamp according to the datasheets, that's all the flow an INPUT gets despite the name. I've used that 1 uA in a very fast loop to count how many reads it took to drain a wire of charge filled from a transistor during an event. The more reads it took to take the INPUT LOW, the longer the actually very short event took.

Pulldowns are to prevent input wiring from holding such a charge to get 1 read per event regardless of length.

Hi,
Redo your scope test with DC coupling, not AC.


Tom... :slight_smile:

GoForSmoke:
If the button module makes the signal pin either HIGH or LOW you don't need a pulldown, it just wastes current when the pin is HIGH.

AVR INPUT read takes 1 microamp according to the datasheets, that's all the flow an INPUT gets despite the name. I've used that 1 uA in a very fast loop to count how many reads it took to drain a wire of charge filled from a transistor during an event. The more reads it took to take the INPUT LOW, the longer the actually very short event took.

Pulldowns are to prevent input wiring from holding such a charge to get 1 read per event regardless of length.

Thanks for the explanation, very useful :slight_smile:

TomGeorge:
Redo your scope test with DC coupling, not AC.

Hi TomGeorge,

I should have tried that myself, here is is:

Looks more like it. The edges seem to switch nice and sharp, however I'm not sure how to get a much better view on this extremely budget scope :slight_smile: