Skip to content

Commit aff2def

Browse files
authored
Update README.md
1 parent 13614d4 commit aff2def

File tree

1 file changed

+71
-1
lines changed

1 file changed

+71
-1
lines changed

README.md

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,71 @@
1-
# micropython-TTP229-BSF
1+
# MicroPython ESP8266/ESP32 Driver for TTP229-BSF 16-key Capacitive Keypad in Serial Interface Mode
2+
3+
This MicroPython driver is for TTP229-BSF capacitive keypad on ESP8266/ESP3. Tested on both ESP8266 and ESP32 v1.11 firmware.
4+
5+
The serial interface of TTP229-BSF <b>is not I2C</b> but it allows you to control this keypad via only 2 wires. Not to be confused with TTP229-LSF, which is a real I2C device.
6+
7+
## Hardware Configuration
8+
9+
TTP229-BSF's serial interface supports either 8 or 16 key mode, as well as single/multiple key mode. For some of the settings hardware configuration is required:
10+
11+
![11-1035x1200](https://user-images.githubusercontent.com/44191076/69064016-6ec49c00-0a58-11ea-9b46-c10f4f1a9cdf.jpg)
12+
13+
* TP2 not connected: 8 keys
14+
* TP2 connected (pulled low): 16 keys
15+
16+
* TP3 and TP4 not connected: single key mode
17+
* TP3 and TP4 both connected (pulled low): multiple key mode
18+
19+
Without any modification the TTP229-BSF is in 8-key/single mode. Connect the pins by wires or soldering to enable these options.
20+
21+
## Wiring
22+
23+
* VCC: 3.3V or 5V
24+
* GND: GND
25+
* SCL: scl pin (output)
26+
* SDO (not SDA): sdo pin (input)
27+
28+
## Example
29+
30+
```python
31+
from machine import Pin
32+
from TTP229_BSF import Keypad
33+
34+
scl_pin = Pin(5, Pin.OUT)
35+
sdo_pin = Pin(4, Pin.IN)
36+
37+
keypad = Keypad(scl=scl_pin, sdo=sdo_pin, inputs=16, multi=False)
38+
39+
while True:
40+
print(keypad.read())
41+
# return a index number like 15 in single mode
42+
# return a list like [0, 1, 14, 15] in multiple mode
43+
```
44+
45+
<b>input</b> parameter:
46+
47+
* input=8 (default): 8 key mode
48+
* input=16: 16 key mode
49+
50+
<b>multi</b> parameter:
51+
52+
* multi=False: single mode
53+
* multi=True: multiple mode
54+
55+
In single mode keypad.read() will return the index of the pressed key (0~15). Return -1 when no key is pressed.
56+
57+
In multiple mode keypad.read() will return a list containing all the indexes of pressed keys. Return an empty list when no key is pressed.
58+
59+
If the TTP229-BSF is configured to multiple mode, read it in single mode will return the lowest index of all pressed keys. Read in multiple mode for a keypad configured in single mode, you'll get a list containing only one key index if any key is pressed.
60+
61+
There's also a <b>raw</b> parameter. When set as True, keypad.read() will return the raw 8 or 16 key list indicating all keys' status (1=not pressed, 0=pressed).
62+
63+
```python
64+
keypad = Keypad(scl=scl_pin, sdo=sdo_pin, inputs=16, multi=False, raw=True)
65+
# return a list like [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
66+
67+
while True:
68+
print(keypad.read())
69+
```
70+
71+
If the keypad is configured to multiple mode and you read it in single/raw mode, you'll still get a list which shows multiple key pressing results.

0 commit comments

Comments
 (0)