I had a TTP229 capacitative keypad module lying around and thought it would be useful with Espruino. These can be picked up fairly cheaply online. Just be careful: There are actually two variants of this chip and it isn't always clear which is which!
The modules I see on ebay seem to have the TTP229-BSF version of the chip - this is what mine is and what this code works with. I think if the module has "SCL" and "SDO" pins on it things should be OK. The other version has an I2C interface and won't work with this code.
To explain the code: You can treat the chip as though it has an SPI interface, and read out 2 bytes of data from it. These contain the keypresses, but inverted - ie '1' means not set, and '0' means set.
I hope the code below makes sense and is useful to somebody!
// Espruino example for TTP229-BSF keypad
// Connect keypad SCL and SDO lines to these pins:
SCL = D14;
SDO = D15;
// Setup SPI interface but clock needs to be quite slow otherwise we get data errors
SPI1.setup({miso:SDO, sck:SCL, mode:integer=3,baud:integer=10000});
// Periodically read the keys and display on the console
setInterval(function() {
// Read 2 bytes of data from the device
data=SPI1.send([0,0]);
// Invert the data so that a '1' means button pressed. This gives us
// two bytes:
// Top = buttons 1-8 : Bits are Button 1,2,3,4,5,6,7,8
// Bottom = buttons 9-16 : Bits are Button 9,10,11,12,13,14,15,16
top=data[0]^0xff;
bottom=data[1]^0xff;
// Now display as binary
console.log("BTN1-8",top.toString(2),"BTN0-16",bottom.toString(2));
},500);
Thank you @ColinP for the code snippet and pics. Had just seen a few of these recently and started imagining what uses might result. Hex calculator maybe?
Post a reply
Bold
Italics
Link
Image
List
Quote
code
Preview
Formatting Help
Don't worry about formatting, just type in the text and we'll take care of making sense of it. We will auto-convert links, and if you put asterisks around words we will make them bold.
Tips:
Create headers by underlining text with ==== or ----
To *italicise* text put one asterisk each side of the word
To **bold** text put two asterisks each side of the word
Embed images by entering: ![](https://www.google.co.uk/images/srpr/logo4w.png) That's the hard one: exclamation, square brackets and then the URL to the image in brackets.
* Create lists by starting lines with asterisks
1. Create numbered lists by starting lines with a number and a dot
> Quote text by starting lines with >
Mention another user by @username
For syntax highlighting, surround the code block with three backticks:
```
Your code goes here
```
Just like Github, a blank line must precede a code block.
If you upload more than 5 files we will display all attachments as thumbnails.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hello,
I had a TTP229 capacitative keypad module lying around and thought it would be useful with Espruino. These can be picked up fairly cheaply online. Just be careful: There are actually two variants of this chip and it isn't always clear which is which!
The modules I see on ebay seem to have the TTP229-BSF version of the chip - this is what mine is and what this code works with. I think if the module has "SCL" and "SDO" pins on it things should be OK. The other version has an I2C interface and won't work with this code.
To explain the code: You can treat the chip as though it has an SPI interface, and read out 2 bytes of data from it. These contain the keypresses, but inverted - ie '1' means not set, and '0' means set.
I hope the code below makes sense and is useful to somebody!
1 Attachment