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
- 2.8 TFT Touch Shield with 4MB Flash (SKU: DFR0347), Quantity: 1, Purchase Link: 2.8 TFT Touch Shield with 4MB Flash for Arduino and mbed(SKU:DFR0347)
- Arduino pin compatible device (e.g., Arduino Uno), Quantity: 1, Purchase Link: Arduino
Software Preparation
- Arduino IDE (download link: Arduino IDE)
- DmTftLibrary (download link: dmtftlibrary)
- Installation guide for Arduino libraries: The official guide of Arduino
Other Preparation Work
-
First download our DmTftLibrary from dmtftlibrary
-
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
-
Start Arduino IDE, open the sample code, click "File--> Examples-> DmTftLibraries", select the right board and COM port: DM-TFT28-105
-
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
Was this article helpful?
