Skip to content

Instantly share code, notes, and snippets.

@auckenox
Last active February 6, 2018 23:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save auckenox/71d95789859b20b6133f2e57e606be95 to your computer and use it in GitHub Desktop.
Save auckenox/71d95789859b20b6133f2e57e606be95 to your computer and use it in GitHub Desktop.
ttp229 python i2c raspberry pi pins K0-K7
"""
you will need smbus, install it:
apt install python-smbus
only keys 0-7 are covered by this script
this script will show you which keys you touched
tested with a: 16 Keys I2C Capacitive Touch TTP229 Module
"""
import smbus,time
bus = smbus.SMBus(1)
adress = 0x57
knames = {0: "nothing", 128: "K0", 64: "K1", 32: "K2", 16: "K3", 8: "K4", 4: "K5", 2: "K6", 1: "K7", 192: "K0+K1"}
while True:
byte = bus.read_byte(adress)
try:
print knames[byte]
except Exception as e:
print "Unknown Key: %i (did you press more than one key?)" %byte
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment