Built-in project · Arduino Uno R3

Cap touch on an Arduino Uno

Draw on the 2.8 inch ILI9341 with its FT6206 capacitive touch panel, read with Adafruit’s library over I2C, and turn the film’s point round to match the screen. The whole build, an Arduino Uno and 1 more part, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Intermediate Runs in your browser. Free, and no account needed.

The parts retail for about $45. On Mokxi they're free.

Cap touch · Arduino Uno R3live0.000 s 0.00x
Click to open it in the editor
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · Arduino Uno R3
// 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);
}

Parts list

3 parts, plus the jumper wires. They retail for about $45; on Mokxi they're free.

How it is wired

9 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.

  • Arduino Uno R3 pin 13; Touch TFT, 2.8 inch ILI9341 with FT6206 pin SCK
  • Arduino Uno R3 pin 11; Touch TFT, 2.8 inch ILI9341 with FT6206 pin MOSI
  • Arduino Uno R3 pin 10; Touch TFT, 2.8 inch ILI9341 with FT6206 pin CS
  • Arduino Uno R3 pin 9; Touch TFT, 2.8 inch ILI9341 with FT6206 pin DC
  • Arduino Uno R3 pin 8; Touch TFT, 2.8 inch ILI9341 with FT6206 pin RST
  • Arduino Uno R3 pin 5V; Touch TFT, 2.8 inch ILI9341 with FT6206 pin VCC; Touch TFT, 2.8 inch ILI9341 with FT6206 pin LED
  • Ground: Arduino Uno R3 pin GND; Touch TFT, 2.8 inch ILI9341 with FT6206 pin GND
  • Arduino Uno R3 pin A4; Touch TFT, 2.8 inch ILI9341 with FT6206 pin SDA
  • Arduino Uno R3 pin A5; Touch TFT, 2.8 inch ILI9341 with FT6206 pin SCL

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.