If you have a display with touch, you can use the Adafruit_FT6206_Library or Adafruit_CST8XX_Library library to read the touch data. The Capacitive Touch controller is communicated to by I2C. If you're not sure if you have a touch display, just check if your includes a square IC connected off to the side of the main ribbon cable.
Determining the I2C Address
You can scan for I2C devices by running the WireScan example. You can find it by going to File → Examples → Wire → WireScan and uploading the sketch. Once it is running, open the serial monitor to see which devices it finds.
You should see a couple of devices listed. These will be the GPIO expander and the touch controller. The GPIO Expander is at 0x3F
by default, though it's possible to change the address with the solderable jumpers on the reverse side. The other address should be the touch controller. On most of the displays it should show up as 0x38
, but on other displays such as the TL040HDS20 4.0" square display, it shows up as 0x48
. On the 2.1" round display shows up as 0x15
and uses the CST826 chip instead.
FocalTouch Controllers
Initializing the Touch Controller
The FocalTouch controllers use Adafruit_FT6206_Library. In order to use the controller, it will need to first be initialized. You can use the following code to initialize it. If your I2C address differs, change it to the appropriate value.
#include <Wire.h> // this is needed for FT6206 #include <Adafruit_FT6206.h> #define I2C_TOUCH_ADDR 0x48 // often but not always 0x48! Adafruit_FT6206 ctp = Adafruit_FT6206(); // this library also supports FT5336U! Serial.begin(115200); // To print the output if (!ctp.begin(0, &Wire, I2C_TOUCH_ADDR)) { Serial.println("No touchscreen found"); }
Reading from the Touch Controller
To read from the controller, check if is has been touched
in the main loop and if so, read the x
and y
coordinates.
if (ctp.touched()) { TS_Point p = ctp.getPoint(0); Serial.printf("(%d, %d)\n", p.x, p.y); }
CST826 Touch Controller
Initializing the Touch Controller
The CST Touch controller uses Adafruit_CST8XX_Library. In order to use the controller, it will need to first be initialized. You can use the following code to initialize it. If your I2C address differs, change it to the appropriate value.
#include <Wire.h> #include <Adafruit_CST8XX.h> #define I2C_TOUCH_ADDR 0x15 Adafruit_CST8XX ctp = Adafruit_CST8XX(); Serial.begin(115200); // To print the output if (!ctp.begin(&Wire, I2C_TOUCH_ADDR)) { Serial.println("No touchscreen found"); }
Reading from the Touch Controller
To read from the controller, check if is has been touched
in the main loop and if so, read the x
and y
coordinates.
if (ctp.touched()) { CST_TS_Point p = ctp.getPoint(0); Serial.printf("(%d, %d)\n", p.x, p.y); }
Example
To see an example, check out the Arduino Rainbow Demo Page.
Text editor powered by tinymce.