Adafruit FT6206: capacitive touch on the 2.8 inch TFT
Yes. You can use the Adafruit FT6206 Library online in Mokxi with nothing to install, and the sketch runs in your browser against the simulated part (Touch TFT, 2.8 inch ILI9341 with FT6206). The example below, "Cap touch", runs on the Arduino Uno R3.
Built in on Mokxi: #include <Adafruit_FT6206.h> and it builds, with nothing to install. Free, and no account needed.
What Adafruit FT6206 Library does
The FT6206 is the FocalTech chip that reads the capacitive glass on Adafruit’s 2.8 inch cap-touch shield and the many ILI9341 modules modeled on it. The library talks to it over I2C at address 0x38, so the touch panel and the SPI display share no wires: the screen is drawn with Adafruit_ILI9341 and the finger is read with this.
Unlike a resistive panel and its XPT2046, there is nothing to calibrate. getPoint() returns the touch in pixels of the glass. The film is laminated the other way up from the display memory, though, so the usual first step is to flip both axes with map(), exactly as the runnable paint project does before it draws a dot under your finger.
In Mokxi the touch layer reports one finger. touched() says 1 while the pointer is down, and asking for the second point returns an empty one; gestures are not reported.
| Library Manager name | Adafruit FT6206 Library |
|---|---|
| Author | Adafruit |
| Include | #include <Adafruit_FT6206.h> |
| Boards | every board Mokxi compiles for but ATtiny85 |
| In the simulator | Simulated: it runs against the part the way it does on the bench. |
| Parts it drives | Touch TFT, 2.8 inch ILI9341 with FT6206 |
Install it
It builds on every board Mokxi compiles for but ATtiny85.
In Mokxi it is built in: #include <Adafruit_FT6206.h> and the sketch compiles, with no download, no zip and no Library Manager.
On a real board, install "Adafruit FT6206 Library" by Adafruit from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add Adafruit FT6206 Library to lib_deps in PlatformIO. Mokxi follows the calls of release 1.1.1, so a sketch written here builds there too.
What to know in the simulator: One finger: the second point always reads as not touched, and gestures are not reported.
- ESP32-C3
- Arduino Uno
- Arduino Nano
- Arduino Mega 2560
- Arduino Leonardo
- SparkFun Pro Micro
- Arduino Micro
- ESP32-C6
- WCH CH32V003
- Raspberry Pi Pico
- Raspberry Pi Pico W
- Seeed XIAO SAMD21
- STM32
- STM32 Nucleo-F411RE
- STM32 Blue Pill
- micro:bit V2
- Arduino Uno R4
- ESP32 DevKit
- ESP32-S3-DevKitC-1
- ESP8266 NodeMCU
- Arduino Pro Mini 3.3 V
- Seeed XIAO ESP32-C3
- ESP32-C3 SuperMini
- Seeed XIAO ESP32-C6
- ESP32-DevKitC V4
- LOLIN32 Lite
- Wemos D1 R32
- Cheap Yellow Display
- TTGO T-Display
- Seeed XIAO ESP32-S3
- ESP32-S3-CAM
- Arduino Nano ESP32
- Arduino Nano RP2040 Connect
- Seeed XIAO RP2040
- Waveshare RP2040-Zero
- Arduino Uno R4 WiFi
The calls you will use
In the order a sketch meets them.
Adafruit_FT6206 ctp
Makes the touch controller object. It needs no pins, since it is on the I2C bus at 0x38.
ctp.begin(40)
Checks the vendor and chip IDs and sets the touch threshold (lower is more sensitive). Returns false when no FT6206, FT6236 or FT6336U answers.
if (!ctp.begin(40)) {
Serial.println("Couldn't start FT6206 touchscreen controller");
while (1) {}
}ctp.touched()
How many fingers are on the glass: 0, 1 or 2. Use it as a true or false test before reading the point.
TS_Point p = ctp.getPoint()
The first touch, with p.x and p.y in glass pixels and p.z set to 1 while it is down. getPoint(1) asks for a second finger.
p.x = map(p.x, 0, 240, 240, 0)
Flips the x axis so it matches the display in its default rotation. Do the same for y with 320.
Example: Cap touch
On the Arduino Uno R3. It runs in the browser exactly as printed.
// Cap touch: draw on the 2.8 inch ILI9341 with its FT6206 capacitive touch
// panel, the Adafruit way.
//
// display CS -> 10 DC -> 9 RST -> 8 MOSI -> 11 SCK -> 13 LED -> 5 V
// touch SCL -> A5 SDA -> A4
//
// Press on the picture while it runs, and drag.
//
// The display is an SPI device and the touch controller an I2C one, so the
// two never share a wire. The FT6206 reports the point in pixels of the
// glass, but its film is laminated the other way up from the display's
// memory, so the first thing the sketch does with a point is turn it round:
// the two map() lines, straight from Adafruit's example.
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <Adafruit_FT6206.h>
Adafruit_ILI9341 tft(10, 9, 8);
Adafruit_FT6206 ctp;
void setup() {
Serial.begin(9600);
tft.begin();
tft.fillScreen(ILI9341_BLACK);
if (!ctp.begin(40)) {
Serial.println("Couldn't start FT6206 touchscreen controller");
while (1) {
}
}
Serial.println("Capacitive touchscreen started");
}
void loop() {
if (!ctp.touched()) return;
TS_Point p = ctp.getPoint();
// Flip it around to match the screen.
p.x = map(p.x, 0, 240, 240, 0);
p.y = map(p.y, 0, 320, 320, 0);
tft.fillCircle(p.x, p.y, 3, ILI9341_YELLOW);
Serial.print("touch ");
Serial.print(p.x);
Serial.print(" ");
Serial.println(p.y);
delay(50);
}Open it in the editor, wired and ready to run · Cap touch: the project page
Common errors and how to fix them
Couldn't start FT6206 touchscreen controller
begin() got no answer at 0x38. Check SDA and SCL (A4 and A5 on an Uno) and power to the touch board, and that the module really is capacitive: a resistive screen has an XPT2046 on SPI instead.
The dot appears in the mirror-image corner from the finger
The axes have not been flipped. Apply the two map() lines after getPoint(), and if you call setRotation() on the display, swap or flip x and y to match that rotation too.
A tap draws a line of dots instead of one
touched() stays true for as long as the finger is down, so loop() reads it many times. Act on the change from not touched to touched, or add a short delay after drawing.
Questions and answers
Can I use the FT6206 with a display library other than Adafruit_ILI9341?
Yes. The touch chip is independent of the screen; any library can draw while this one reads the I2C touch data.
Keep going
Learn
Try Adafruit FT6206 Library without installing anything
Open the example, change the sketch, and keep your version in a free account.