Example Code for Arduino-Touch Screen Calibration

This article offers a detailed guide on calibrating an Arduino touch screen using example code, including hardware setup, software downloads, wiring, and results.

Hardware Preparation

Software Preparation

Wiring Diagram

The 3.5 TFT Resistive Touch Shield connects directly on top of an Arduino pin compatible device (no additional wiring required).

Sample Code

 #include <SPI.h>
 #include <DmTftSsd2119.h>
 #include <DmTouch.h>
 #include <utility/DmTouchCalibration.h>
 DmTftSsd2119 tft = DmTftSsd2119();
 DmTouch dmTouch = DmTouch(DmTouch::DM_TFT35_107);
 DmTouchCalibration calibration = DmTouchCalibration(&tft, &dmTouch);
 bool calibrated = false;
 void setup() {
 dmTouch.setCalibrationMatrix(calibration.getDefaultCalibrationData((int)DmTouch::DM_TFT35_107));
 tft.init();
 dmTouch.init();
 }
 void loop()
 {
  uint16_t x, y ;
  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

You can write by touching the screen.

DFR0348 3.5 TFT Resistive Touch Shield Result

Was this article helpful?

TOP