I wanted to post quick small sketch I’ve put together today for working with the 16 channel capacitive touch sensor board TTP229 LSF from RobotDyn. I bought it from AliExpress and it will be part of an upcoming project.

I’ve been looking around for an example code ready made but I could only find examples for a similar board from aliexpress that is using a slightly different chip. So I will post my example in case somebody can benefit from it.
Here we can see the wiring connections for an arduino mega.

This particular board ( the TTP229 LSF) differs from other ones I’ve seen on the use of the i2C instead of a pulling mechanism. This makes the hole process much easier. Here we can see a screen capture from the oscilloscope with the actual I2C data transmission.

The first packet is the addressing where we tell the I2C bus we want to read from the sensor. The following 2 packets is the response, where each bit received is the status of each of the 16 capacitive sensors.
And, of course, a crude serial monitor output with the data of the sensors.

And finally the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
/* Created: Doctor Bit Date: 13 August 2017 Last update: 13 August 2017 Online: http://www.drbit.nl Tested with: Arduino IDE 1.8.3 */ ////////////////////////////////////////////////////////////////// // DrBit.ln // // Use this code as you want ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// // Connections // // Uno: SDA <-> A4 (SDA) // SCL <-> A5 (SCL) // // Mega: SDA <-> 20 (SDA) // SCL <-> 21 (SCL) // // Leo: SDA <-> 2 (SDA) // SCL <-> 3 (SCL) // ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// // Addressing of the TTP229 LSF // Slave Address : The identify code for the TTP229-LSF is〝 (1010) 〞. The device address B3 , B2 and // B1 are fixed〝 111 〞 // Read/Write : The final (eighth) bit of the slave address defines the type of operation to be performed. // If the R/W bit is〝 1 〞, a read operation is executed. If it is〝 0 〞, a write operation is executed. But // the TTP229-LSF only accepts read operation. // Slave Device Addressing // Device Identifier Device Address R/W Bit // B7 B6 B5 B4 B3 B2 B1 B0 // 1 0 1 0 1 1 1 R (0) ////////////////////////////////////////////////////////////////// #include "Wire.h" #define TTP229_LSF 0x57 // Device address (the addressing without the R/W bit) -> 01010111 = 57 void setup() { Wire.begin(); // wake up I2C bus Serial.begin(9600); Serial.println("*Sensor Num. 111111"); Serial.println(" 0123456789012345"); Serial.println(" ----------------"); } void getTTP229data(byte *a, byte *b) { Wire.requestFrom(TTP229_LSF, 2); // request 6 bytes from slave device #2 int dataN = 0; while(Wire.available()) // slave may send less than requested { char c = Wire.read(); // receive a byte as character if (dataN == 0) *a = c; if (dataN == 1) *b = c; dataN++; } } void showTTP229data() { byte aa,bb = 0; getTTP229data(&aa,&bb); Serial.print("data TTP229 = "); printByte(aa); printByte(bb); Serial.println(";"); delay(1000); } void loop() { showTTP229data(); } void printByte (byte bytePrint) { for (unsigned int mask = 0x80; mask; mask >>= 1) { if (mask & bytePrint) { Serial.print('1'); } else { Serial.print('0'); } } } |
Soon I will upload it in github.
Notice that in this particular chip there is a pin that signals when a sensors changes making it really economic to checking the sensors with the use of interrupts.
More on that soon.
Leave a comment if you like it.
FLavio
great explanation,
I have one this module and now I will continue in my touch project.
thank you
admin
Thanks Flavio
Anonymous
TTP229, not TTP299
admin
indeed! thanks anonymous person. Been fixed
Attila
Thank You! Best regards
Steph
nice job, many thanks, i get some time to test same
i order too the Capacitive Touch Disk, when i plug it with 20cm dupont wire, all pin go to 1 never go back 0
is somebody test it ?
regrds
Steph
no matter with Touch disk, only direct connect without wire and it’s fine
Stan
Thank you! I’ve tried some other example codes for this module but with yours I’m able to detect any of the button combinations with ease. And this is great! Awesome job!
Anonymous
The only code actualy works. Have You been thinking of library. Would be easy to use. Also I’m looking for single button solution..
Evan Perry
Thanks man. This is the only code I could find that actually works. I do have a question though. Do you or someone here know how to us the output data for a keypad?
Again THANKS.
Joko
Nice, I want to play .wav from sdcard ..where each button different sound. how is the code