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
- 3.5 TFT Resistive Touch Shield (SKU:DFR0348) × 1, Purchase Link: https://www.dfrobot.com/product-1268.html
- Arduino Compatible Board × 1, Purchase Link: https://www.arduino.cc/en/Guide/HomePage
Software Preparation
- Arduino IDE (Latest Version), Download Link: https://www.arduino.cc/en/software
- DmTftLibrary, Download Link: https://bitbucket.org/displaymodule/dmtftlibrary/get/master.zip
- Arduino Library Installation Guide: https://docs.arduino.cc/software/ide-v1/tutorials/installing-libraries
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.
Was this article helpful?
