16 button 8229BSF touchpad sensor revisited.

http://forum.arduino.cc/index.php?topic=301382.0
The suggestion in this post is weird. Do I need to endage all the pins involved?

I saw this but I didn't find another good forum post on the subject.

My pad looks like this photo:

Are jumpers in the right places?

I would like to know if I can use this keypad with I2c and what other ways I can use it besides the direct parallel data input with 8 pins.

Does anybody have an experience where there small arduino-based device used such data input device?

Thank you.

1 Like

Try looking at this post

I don't see any defintions for the Data pins so it looks like he is uding a 2-wire interface.

http://forum.arduino.cc/index.php?topic=248748.0http://forum.arduino.cc/index.php?topic=248748.0

https://www.openimpulse.com/blog/products-page/product-category/ttp229-capacitive-touch-sensor-module-16-channels/

my post from the past
https://forum.arduino.cc/index.php?topic=387301.0

This code didn't work. Why?

Can this board function like an I2C device?

KeyToSerial.ino (4.03 KB)

The datasheet says it's an I2C device - why do you think it might not be?

Assuming you've wired things up correctly I would first of all test whether it can be detected on the I2C bus. In the 'playground' section of this very website there is an I2C scanner which will tell you whether it's working and what the address is (compare it against the manufacturer's datasheet). It will take you all of 10 minutes to try this.

http://playground.arduino.cc/Main/I2cScanner

If this returns a hex address as you would expect then the I2C part is certainly working. In which case... well, let's start with that bit.

I think the Scanner is a great suggestion. My only question is if it truly is I2C why is that pin called SDO instead of SDA ?

raschemmel:
I think the Scanner is a great suggestion. My only question is if it truly is I2C why is that pin called SDO instead of SDA ?

Thats the question really.
So I hooked it up to my Arduino and ran the sketch that finds I2C devices and nothing came up.
No devices detected.

Otherwise there are two or three devices detected (if I plug them in and work on my main project)

All the examples in the links above also present this touch pad as something different than I2C device.
There is no example where it is used like orthodox I2C.

SCL was wired to Pin3
SD0 was wired to Pin2 where SDA is usually wired.

Jumpers on the touchpad may hold an answer. This is why I soldered pins in there and can move jumpers back and forth. - Yes I did that extra work because there is no clear step by step on how to use this keypad. So I knew there will be trial and error involved.

Thank you.

4.7 k pullups ?

raschemmel:
4.7 k pullups ?

Maybe pullups are not included on this circuit board.

I think that this device is not I2C because it has to initiate communication with the microcontroller when someone triggers a capacitive "button" for the first time.

For this reason it uses some weird protocols that are somewhere between SPI and I2C.
http://hobbycomponents.com/home/585-ttp229-16-key-capacitive-keypad
http://hobbycomponents.com/home/585-ttp229-16-key-capacitive-keypad#idTab69

There is a good reason why this device is not that popular. It is weird and poorly documented.

http://forum.hobbycomponents.com/viewtopic.php?f=73&t=1781&hilit=hcmodu0079

I am fairly new to Arduino programming. It will likely not work the first time.

Am I correct about why it cannot use I2C protocol?

Take another look at Reply#1

It looks to me like he used the same product and posted his working code.

Did you READ Reply#1 and Reply#2 of THAT post ?

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).

YOU already have jumpers installed on your board so his code should work for you.

I read all posts. Not all code satisfies me. Some algorithms are just absurd.

So for code mentioned here:
http://forum.hobbycomponents.com/viewtopic.php?f=73&t=1781&hilit=hcmodu0079

I should use pins 2 and 3 on Arduino Micro Pro? (SDA vs SD0 or SDO)

Or some other pins because it is not exactly I2C and may interfere with other I2C devices?

I will run out of microcontroller memory long before I will run out of pins on Arduino Micro Pro.
There is some serious mathematics and logic in my project if I implement data logging.

I should use pins 2 and 3 on Arduino Micro Pro? (SDA vs SD0 or SDO)

NO . Because it is NOT I2C. If it was TRUE I2C, it would use A4 (SDA) and A5 (SCL).

You already proved this to yourself when you ran the scanner. If the scanner doesn't detect it, it is NOT an I2C device. That's all there is to it.

ie:
SDO means SDO and nothing else.

Digital pins 8 & 9 are OBVIOUSLY not I2C pins because I2C uses A4 & A5 (ALWAYS, NO EXCEPTIONS !).

If the code says use D8 & D9 , then those are the pins you need to use. If you have already committed those pins I don't see why you can't redefine them.

I don't know why you don't see that.

What's missing from this post is not your opinion of the sketch in question but rather you saying :
"I tried the sketch, exactly as given ( with NO changes) and...."

The sketch gives me number 3 in serial communication window - which matches the button 3 - with no changes.

When I accidentally confused two wires SD0 and SCL, the output was always 16.

Why should there be output at all if nothing is touched?

It looks like either the code has a glitch or have a jumper in the wrong place or the board is damaged.

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

So you used the above code as is and the keypad does not work ? ( no key reported )

The sketch gives me number 3 in serial communication window - which matches the button 3 - with no changes.

What do you mean ? (It reports key 3 when it is not pressed ?)

Why should there be output at all if nothing is touched?

You can't swap clock & data pins on anything without bizarre results.

I used this code and nothing worked. Or I got my 16 and 3 result.
I hope that I didn't burn anything by confusing the clock and data pin.

Now I will try your example. Your example uses pins 2 and 3 which are I2C pins (?).

/* FILE:    TTP229_16_Key_Capacitive_Touch_Example
   DATE:    25/02/15
   VERSION: 0.1
   
REVISIONS:

25/02/15 Created version 0.1

This is an example of how to use the Hobby Components 16 key capacitive touch
keypad (HCMODU0079). This example sketch will read the current state of the 
of the keypad and if a key is pressed output its key number to the serial port.

The sketch assumes that the keypad is configured to 16 key active low mode
by shorting pads P1-3 and P1-P4 together (see schematic or sport forum for more 
information). Connect the keypad to your Arduino as follows:

Keypad......Arduino
VCC.........+5V
GND.........GND
SCL.........Digital pin 8
SDO.........Digital pin 9

You may copy, alter and reuse this code in any way you like, but please leave
reference to HobbyComponents.com in your comments if you redistribute this code.

This software may not be used directly for the purpose of promoting products that
directly compete with Hobby Components Ltd's own range of products.

THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, 
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR
LACK OF NEGLIGENCE. HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE
FOR ANY DAMAGES INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR 
CONSEQUENTIAL DAMAGES FOR ANY REASON WHATSOEVER. */



/* Define the digital pins used for the clock and data */
#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(1000);
}


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

I tried your code. Changed pins for convenience. Tried it with pins 2 and 3 as well.

I get a result where serial monitor gets filled with random BS without me touching any keys. WHY?

Did I burn something?

/*
 * 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 8
#define sdo_Pin 9

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

For some reason when I unplug the keypad this program still generates stuff in Serial Monitor.
Maybe there is an interference with another USB device (3D printer that is printing) ?

Changed pins for convenience. Tried it with pins 2 and 3 as well.

I2C pins are always A4 & A5 analog pins. So it didn't work using the digital pins 8 & 9 ?

Did I burn something?

No any digital pin can be connected to any other digital pin. It is not a good idea to connect two outputs together but there is nothing wrong with connecting two inputs together. You didn't do either.
All you did is use different pins, which won't damage anything.
I don't know why it doesn't work and I don't have one so there is not much I can do.

I can buy a new arduino and new keypad and see if they would play well together.
But I suspect that if anything, it is the keypad that went bad or was defective.

http://www.aliexpress.com/item/MPR121-Breakout-V12-Capacitive-Touch-Sensor-Controller-Module-I2C-W-12-keypad/1729953044.html?spm=2114.01010208.3.110.hqkL2K&ws_ab_test=searchweb201556_0,searchweb201602_2_10037_10017_10034_10021_507_10022_10032_10009_10020_10008_10018_10019,searchweb201603_9&btsid=1481552e-711b-4d8e-b080-18c65ce9e4db

Would this keypad work better?
It uses a different IC in it. Maybe
It is a little pricy. Yes, I buy every piece of hardware from Aliexpress and nothing gave me as much trouble as this pseudo - I2C keypad. Everything worked well before.

Can I use 3.3V logic with Arduino Micro Pro?

From the datasheet:

Low power operation
• 1.71 V to 3.6 V supply operation

Low power operation or low voltage operation?
Improper definitions are given deliberately to sell more crap?

I doubt it. ( that keypad is bad) The arduino is simple to test using a meter or leds. As far as the keypad I don't see how you could damaged it.

I don't know about using the Micro at 3.3 V. Check the specs on the arduino product page. If the crystal is 16 MHz I don't know how it will react to 3.3V.