Communication with 16 key capacitive keyboard - TTP229-B

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
Post Reply
hrsales
Posts: 6
Joined: Mon May 06, 2019 1:59 pm

Communication with 16 key capacitive keyboard - TTP229-B

Post by hrsales » Mon May 06, 2019 2:34 pm

I've buyed some capacitive keyboards with the TTP229-B controller, but the I2C doesn't let me read from. I'm really new with micropython. I tryed with arduino mega and works on serial's (the hint - https://forum.arduino.cc/index.php?topi ... msg2252580)

I sawed that this chip has a version(TTP229-L) with native I2C, but I not so conffident with that. I alredy buyed some to test, but I wanna put the TTP229-B to work too, someone has an idea to solve this issue?

The pins of board are Vcc, Gnd, Scl and Sdo. I used D1 for Scl and D2 for Sdo, but the array from i2c.scan() returns empty.

Thanks! :)

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Communication with 16 key capacitive keyboard - TTP229-B

Post by jimmo » Mon May 06, 2019 9:09 pm

Which micropython board are you using? Do you have 10k pull-up resistors on the sda and scl lines? (Some of the Arduino boards have these built in, which might be why it works on your Mega)

hrsales
Posts: 6
Joined: Mon May 06, 2019 1:59 pm

Re: Communication with 16 key capacitive keyboard - TTP229-B

Post by hrsales » Thu May 09, 2019 12:05 am

[quote=jimmo post_id=36329 time=1557176979 user_id=3071]
Which micropython board are you using? Do you have 10k pull-up resistors on the sda and scl lines? (Some of the Arduino boards have these built in, which might be why it works on your Mega)
[/quote]

I'm using a generic nodemcu board, like a geekcreit with Esp12N. Yes, i've tested with and without the pull-up resistors. :'(

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Communication with 16 key capacitive keyboard - TTP229-B

Post by jimmo » Thu May 09, 2019 1:46 am

I read the datasheet https://www.sunrom.com/get/611100 and yeah this isn't i2c at all.

If you look at that Arduino code that you linked to you'll see how they do it:
- Register an interrupt on the SDO line.
- Then clock the SCL line N times to read the N key states from SDO.

The datasheet has a diagram showing this.

If you give that a try and it doesn't work, post your Python code here and we can take a look.

hrsales
Posts: 6
Joined: Mon May 06, 2019 1:59 pm

Re: Communication with 16 key capacitive keyboard - TTP229-B

Post by hrsales » Fri May 10, 2019 12:29 am

I'll try, and answer soon as i can. Thanks!

hrsales
Posts: 6
Joined: Mon May 06, 2019 1:59 pm

Re: Communication with 16 key capacitive keyboard - TTP229-B

Post by hrsales » Wed May 22, 2019 6:38 pm

Thanks for waiting! About your answer:

I've simulated this on micropython putting an IRQ_FALLING to wait a sda value change from a while True loop, but always returns 1, so... guess i'm wrong or the pcb always return wrong. The both TTP229(-L and -B) had same issue.

The convencional way on TTP229-L (with I2C) returns a empty list, even with PULL_UP instruction and frequency changed.

Code: Select all

import machine
scl = machine.Pin(5, machine.Pin.OUT)
sda = machine.Pin(5, machine.Pin.IN, machine.Pin.PULL_UP)
i2c = machine.I2C(scl=scl, sda=sda, freq=100000)
My pcb have the 10k pull-up resistors, but i maked tests withtout the PULL_UP instruction an put on both i2c lines 10k and 4,7k resistors. This doesn't work too.

I tested some other components with i2c (with and without the pull-ups) and they works fine, but the TTP229 don't (tested with nodemcu esp12N and esp32 wroom).

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Communication with 16 key capacitive keyboard - TTP229-B

Post by jimmo » Thu May 23, 2019 12:19 am

I think this is going to be easier to just not use machine.I2C at all. We're used to seeing "SDA" and "SCL" (i.e. "Serial DAta / Serial CLock") mean I2C, but in this case the protocol is not I2C, it's just a simple synchronous serial.

If you just use the pins directly, you can register an interrupt on the 'sda' pin, then toggle 'scl' on and off N times, each cycle reading one bit (i.e. one key state) from 'sda'.

hrsales
Posts: 6
Joined: Mon May 06, 2019 1:59 pm

Re: Communication with 16 key capacitive keyboard - TTP229-B

Post by hrsales » Mon May 27, 2019 2:13 pm

Hi! Me again.

I put some time delay, try rise the SDO pin for 93 microseconds before turn it on IN mode(like the docs show) before the loop, I also tried change pins and use another protoboard, but I can't had the value from interruption.
The code for serial read return the unchanged value from SDO pin:

Code: Select all

import utime
from machine import Pin
CLOCK_PIN = 5
DATA_PIN = 4

data = [0 for i in range(0, 15)]

scl = Pin(CLOCK_PIN, Pin.OUT)
sdo = Pin(DATA_PIN, Pin.IN)
scl.on()

for i in range(15):
  scl.off()
  utime.sleep_us(2)
  data[i] = self.sdo.value()
  scl.on()
  utime.sleep_us(2)
print(data)
returns [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

What I doing wrong?
Thanks!

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Communication with 16 key capacitive keyboard - TTP229-B

Post by dhylands » Mon May 27, 2019 2:39 pm

I not familiar with the device in question but in your code I noticed that they is no delay between your first on/off.

The on happens just before the for loop and the off happens immediately inside the for loop.

You should also measure your pulses on a scope or logic analyzer to see how close they are to what you expect.

I took a quick look at some Arduino code and it seems to capture the data just after the rising edge of SCL. Your code is capturing the data just before the rising edge.

hrsales
Posts: 6
Joined: Mon May 06, 2019 1:59 pm

Re: Communication with 16 key capacitive keyboard - TTP229-B

Post by hrsales » Thu May 30, 2019 12:02 am

It works!

Thanks jimmo and dhylands.

I appreciate your help with this question. The key of this mistery was time.

After frist scl.on() (outside loop), has a time.sleep_ms(5);
After scl.off() (inside loop), has a time.sleep_ms(1);
After last scl.off() (inside loop), has another time.sleep_ms(1);

I put some delay after the key pressed (200 ms) too, so i can avoid multiple careless touch.

But...

This works for the TTP229-B, I'til don't can get the values from sdo line of TTP229-L, guess it have an frist configuration of different delay of scl. Anyway, i'll look in docs and if get the answer, 'll put here.

datasheets:
TTP229: http://www.robotpark.com/image/data/PRO ... TTP229.pdf

TTP229-LSF: https://www.openimpulse.com/blog/wp-con ... asheet.pdf

Post Reply