Thursday, June 11, 2020

TFT Touch Screen shield (ILI9341 8 bit) + Uno, calibration and simple touch drawing example.


Last post how to drive 2.8" 320*240 TFT Touch Screen shield (ILI9341 8 bit interface) on Uno, using MCUFRIEND_kbv/Adafruit GFX Libraries on Platform IO. Now show how to calibrate the touch x-y, and run a simple touch drawing with MCUFRIEND_kbv examples.


The MCUFRIEND_kbv examples can be found here: https://github.com/prenticedavid/MCUFRIEND_kbv/tree/master/examples.

Make sure libraries of MCUFRIEND_kbv, Adafruit GFX and Adafruit TouchScreen are installed in your VS Code/Platform IO IDE.

Calibration:

Create a new Project in Platform IO IDE for Calibration, target Arduino Uno.

From MCUFRIEND_kbv TouchScreen_Calibr_native example:
- Copy the code of TouchScreen_Calibr_native.ino to your main.cpp.
- Copy TouchScreen_kbv.cpp and TouchScreen_kbv.h to your project.

As you try Arduino example on PlatformIO. PlatformIO may throw many "not declared in this scope" errors. Because PlatformIO require Forward Declaration of function.  To fix it, copy to define the function prototype before the functions called, as show in the video.

Edit platformio.ini to add "lib_deps = Wire" to fix the error of "Wire.h: No such file or directory". And specify upload_port if the IDE cannot detect your port.

Build and upload the program to Uno, then open Platform IO Serial Monitor. Once calibration finished, the calibration data will be show in Serial Monitor, copy it.

Here is the result of my board:
*** COPY-PASTE from Serial Terminal:
const int XP=8,XM=A2,YP=A3,YM=9; //240x320 ID=0x9341
const int TS_LEFT=169,TS_RT=941,TS_TOP=176,TS_BOT=927;

Simple Touch to draw example:

Create another Project in Platform IO IDE for simple Touch to draw example, target Arduino Uno.

Copy the code of MCUFRIEND_kbv Touch_shield_new example to main.cpp.

Replace the calibrate data (copy from the above program) in the code:



Edit platformio.ini to add "lib_deps = Wire" to fix the error of "Wire.h: No such file or directory". And specify upload_port if the IDE cannot detect your port.

Build and upload, and DONE.




No comments:

Post a Comment