Example Code for Arduino-Touch Screen Interaction

Last revision 2026/01/24

This example demonstrates how to read touch input from the resistive touch screen and display calibration points on the 2.8 TFT Touch Shield.

Hardware Preparation

Software Preparation

Other Preparation Work

  1. First download our DmTftLibrary from dmtftlibrary

  2. Extract the content to your Arduino library folder. In Windows this is usually located in Arduino IDE folder\libraries. Check Arduino's official guide if you want more information on how to install the Arduino Library. The official guide of Arduino

  3. Start Arduino IDE, open the sample code, click "File--> Examples-> DmTftLibraries", select the right board and COM port: DM-TFT28-105

  4. Open the Example and upload to your Arduino board.

Sample Code

 #include <SPI.h>
 #include <DmTftIli9341.h>
 #include <DmTouch.h>
 #include <utility/DmTouchCalibration.h>
 DmTftIli9341 tft = DmTftIli9341(10,9);
 DmTouch dmTouch = DmTouch(DmTouch::DM_TFT28_105);
 DmTouchCalibration calibration = DmTouchCalibration(&tft, &dmTouch);
 bool calibrated = false;
 uint16_t x=0, y=0 ;
 void setup() {
  dmTouch.setCalibrationMatrix(calibration.getDefaultCalibrationData((int)DmTouch::DM_TFT28_105));
  tft.init();
  dmTouch.init();
 }
 void loop() {
  bool touched = true;
  if (dmTouch.isTouched()) {
    dmTouch.readTouchData(x,y,touched);//(x, y) coordinates read contacts
    calibration.drawCalibPoint(x, y);//In a display of contact
  }
 }

Result

DFR0347 2.8 TFT Touch Shield with 4MB Flash for Arduino and mbed Touch Screen Sample Code

Was this article helpful?

TOP