Simple tests¶
Ensure your device works with these simple tests.
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4"""
5Example for getting touch data from an FT6206 or FT6236 capacitive
6touch driver, over I2C
7"""
8
9import time
10import busio
11import board
12import adafruit_focaltouch
13
14# Create library object (named "ft") using a Bus I2C port
15i2c = busio.I2C(board.SCL, board.SDA)
16
17ft = adafruit_focaltouch.Adafruit_FocalTouch(i2c, debug=False)
18
19while True:
20 # if the screen is being touched print the touches
21 if ft.touched:
22 print(ft.touches)
23 else:
24 print("no touch")
25
26 time.sleep(0.15)
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4"""
5Simple painting demo that draws on an Adafruit capacitive touch shield with
6ILI9341 display and FT6206 captouch driver
7"""
8
9import busio
10import board
11import digitalio
12from adafruit_rgb_display import ili9341, color565
13import adafruit_focaltouch
14
15# Create library object using our Bus I2C & SPI port
16i2c = busio.I2C(board.SCL, board.SDA)
17spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)
18
19# Adafruit Metro M0 + 2.8" Capacitive touch shield
20cs_pin = digitalio.DigitalInOut(board.D10)
21dc_pin = digitalio.DigitalInOut(board.D9)
22
23# Initialize display
24display = ili9341.ILI9341(spi, cs=cs_pin, dc=dc_pin)
25# Fill with black!
26display.fill(color565(0, 0, 0))
27
28ft = adafruit_focaltouch.Adafruit_FocalTouch(i2c)
29
30while True:
31 if ft.touched:
32 ts = ft.touches
33 point = ts[0] # the shield only supports one point!
34 # perform transformation to get into display coordinate system!
35 y = 320 - point["y"]
36 x = 240 - point["x"]
37 display.fill_rectangle(x - 2, y - 2, 4, 4, color565(255, 255, 255))
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4"""
5Example for getting touch data from an FT6206 or FT6236 capacitive
6touch driver, over I2C. This version uses an interrupt to prevent
7read errors from the FocalTouch chip.
8"""
9
10import time
11import board
12from digitalio import DigitalInOut, Direction
13import adafruit_focaltouch
14
15
16IRQ_pin = board.IO39 # select a pin to connect to the display's interrupt pin ("IRQ")
17i2c = board.I2C()
18
19# Setup the interrupt (IRQ) pin for input
20irq = DigitalInOut(IRQ_pin)
21irq.direction = Direction.INPUT
22
23# Create library object (named "ft") using a Bus I2C port and using an interrupt pin (IRQ)
24ft = adafruit_focaltouch.Adafruit_FocalTouch(i2c, debug=False, irq_pin=irq)
25
26
27print("\n\nReady for touches...")
28
29while True:
30 # if the screen is being touched print the touches
31 if ft.touched:
32 print(ft.touches)
33 else:
34 print("no touch")
35
36 time.sleep(0.05)
Demos¶
These demos are a bit more complex.
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3"""
4Simple painting demo that draws on the Adafruit Qualia ESP32-S3 RGB666
5with the 4.0" square display and FT6206 captouch driver
6"""
7
8import displayio
9import busio
10import board
11import dotclockframebuffer
12from framebufferio import FramebufferDisplay
13import adafruit_focaltouch
14
15displayio.release_displays()
16
17# Initialize the Display
18tft_pins = dict(board.TFT_PINS)
19
20tft_timings = {
21 "frequency": 16000000,
22 "width": 720,
23 "height": 720,
24 "hsync_pulse_width": 2,
25 "hsync_front_porch": 46,
26 "hsync_back_porch": 44,
27 "vsync_pulse_width": 2,
28 "vsync_front_porch": 16,
29 "vsync_back_porch": 18,
30 "hsync_idle_low": False,
31 "vsync_idle_low": False,
32 "de_idle_high": False,
33 "pclk_active_high": False,
34 "pclk_idle_high": False,
35}
36
37init_sequence_tl040hds20 = bytes()
38
39board.I2C().deinit()
40i2c = busio.I2C(board.SCL, board.SDA, frequency=100_000)
41tft_io_expander = dict(board.TFT_IO_EXPANDER)
42# tft_io_expander['i2c_address'] = 0x38 # uncomment for rev B
43dotclockframebuffer.ioexpander_send_init_sequence(
44 i2c, init_sequence_tl040hds20, **tft_io_expander
45)
46
47fb = dotclockframebuffer.DotClockFramebuffer(**tft_pins, **tft_timings)
48display = FramebufferDisplay(fb, auto_refresh=False)
49
50# Main Program
51pixel_size = 6
52palette_width = 160
53palette_height = display.height // 8
54
55bitmap = displayio.Bitmap(display.width, display.height, 65535)
56
57# Create a TileGrid to hold the bitmap
58tile_grid = displayio.TileGrid(
59 bitmap,
60 pixel_shader=displayio.ColorConverter(input_colorspace=displayio.Colorspace.RGB565),
61)
62
63# Create a Group to hold the TileGrid
64group = displayio.Group()
65
66# Add the TileGrid to the Group
67group.append(tile_grid)
68
69# Add the Group to the Display
70display.root_group = group
71
72display.auto_refresh = True
73
74ft = adafruit_focaltouch.Adafruit_FocalTouch(i2c, address=0x48)
75
76current_color = displayio.ColorConverter().convert(0xFFFFFF)
77
78for i in range(palette_width):
79 color_index = i * 255 // palette_width
80 rgb565 = displayio.ColorConverter().convert(
81 color_index | color_index << 8 | color_index << 16
82 )
83 r_mask = 0xF800
84 g_mask = 0x07E0
85 b_mask = 0x001F
86 for j in range(palette_height):
87 bitmap[i, j + palette_height] = rgb565 & b_mask
88 bitmap[i, j + palette_height * 2] = rgb565 & (b_mask | g_mask)
89 bitmap[i, j + palette_height * 3] = rgb565 & g_mask
90 bitmap[i, j + palette_height * 4] = rgb565 & (r_mask | g_mask)
91 bitmap[i, j + palette_height * 5] = rgb565 & r_mask
92 bitmap[i, j + palette_height * 6] = rgb565 & (r_mask | b_mask)
93 bitmap[i, j + palette_height * 7] = rgb565
94
95while True:
96 if ft.touched:
97 try:
98 for touch in ft.touches:
99 x = touch["x"]
100 y = touch["y"]
101 if x < palette_width:
102 current_color = bitmap[x, y]
103 else:
104 for i in range(pixel_size):
105 for j in range(pixel_size):
106 x_pixel = x - (pixel_size // 2) + i
107 y_pixel = y - (pixel_size // 2) + j
108 if (
109 0 <= x_pixel < display.width
110 and 0 <= y_pixel < display.height
111 ):
112 bitmap[x_pixel, y_pixel] = current_color
113 except RuntimeError:
114 pass