With this project we will manage a Touch Sensor (Tontek TTP223-BA6), using the FTDI FT232H development board (of which there is a dedicated page on this site).
This Touch sensor must be connected to the FTDI FT232H development board. The connection connectors are listed below:
Image | Board FT232H | Touch sensor |
---|---|---|
AD0 | SIG | |
+5V | VCC | |
GND | GND |
To manage this Touch Sensor, the presence of the "PyFTDI" library is required.
The following Python code example displays if touch on Touch Sensor is detected:
from os import environ from pyftdi.gpio import GpioAsyncController import time _ctrl = GpioAsyncController() url = environ.get('FTDI_DEVICE', 'ftdi:///1') _ctrl.configure(url, direction=0b0, frequency=None, initial=0x0) _gpio = _ctrl.get_gpio() print("GPIO.pins = ", _gpio.pins, "(", bin(_gpio.pins), ")") print("GPIO.all_pins = ", bin(_gpio.all_pins)) print("GPIO.width = ", _gpio.width) direction = _gpio.direction print("GPIO.direction (Old) = ", bin(direction)) _gpio.set_direction(0b1, 0b0) print("GPIO.direction (New) = ", bin(_gpio.direction)) tmp = 0 try: while True: pins = _gpio.read() pins &= ~0xfe if pins != tmp: if pins == 0: print('* Sensor = untouched *') if pins == 1: print('* Sensor = touched *') tmp = pins time.sleep(0.25) """Close the connection""" except KeyboardInterrupt: # Capture keyboard ^C to exit the program print('\nYou terminated the program. The program ends!') _ctrl.close()