Using one 16-key capacitive keypad (TTP229 or 8229) with Arduino Uno and SPI
First of all, verify that your keypad's TTP229- or 8229-chip is marked with "B something", like 8229BSF. This means that you have the SPI version. Some people have been trying to connect to BSF chips with I2C which will not work.
I first tried one of the known-to-work bitbanging methods:
http://forum.hobbycomponents.com/viewtopic.php?f=73&t=1781&hilit=hcmodu0079
since so many people seem to have problems communicating with these keypads. It worked as expected, but all it does is standard SPI communication, in a less efficient way than the SPI bus. (Also it doesn't work for multiple keys.) So I went on to implement the same protocol using the Arduino <SPI.h> library.
The TTP229-BSF or 8229BSF don't accept any incoming data through SPI, so there's no use connecting MOSI (pin 11 on Uno) at all. The obvious drawback of using the SPI bus is that pin 11 can't be used for arbitrary stuff, it's still occupied by the SPI library.
/*
Scanning a 16 key capacitive TTP229-BSF / 8229BSF keypad with SPI
Free to use, 2019 Andreas Gaunitz, 9bit.se
Arduino Keypad
5v Vcc
Gnd Gnd
12 MISO SDO (Data out)
13 SCK SCL (Clock in)
*/
#include <SPI.h>
uint16_t key_map_8229;
void setup()
{
Serial.begin(115200);
SPI.begin();
SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE3));
delay(500); // Allow 500ms for the 8229BSF to get ready after turn-on
}
void loop()
{
spi_scan_8229();
Serial.println(key_map_8229, BIN);
delay(100);
}
void spi_scan_8229() {
key_map_8229 = SPI.transfer16(0);
}
Serial monitor output for one, two and three keys pressed simultaneously:
1111011111111111
1111011111111111
1111011111111111
1111011111101111
1111011111101111
1111011111101110
1111011111101110
1111011111101110
TTP229_keypad_scanner_SPI.ino (612 Bytes)