Author Topic: Oak with a touch-enabled TFT LCD screen  (Read 11040 times)

postuma

  • Jr. Member
  • **
  • Posts: 64
Oak with a touch-enabled TFT LCD screen
« on: December 12, 2016, 03:39:08 pm »
I’ve just finished a tutorial on integrating the Oak with a basic TFT LCD display with touch functionality, using a popular, cheap screen off eBay. It uses 7 of the Oak’s pins: four for SPI to the display, plus two more to work the display, and a final pin for the touch screen’s chip select (it shares MOSI, MISO and CLK with the display). If you need to use the touch screen’s interrupt, that’s fine, but you’d sacrifice another pin.



The display screen is based on the ILI9341 controller, accessed using Adafruit’s GFX library. The touch screen uses the XPT2046 controller by way of Paul Stoffreger’s XPT2046_Touchscreen library.

Fritzing diagram:



Short video clip, showing screen in action:

If interested, have a look.

Note that the sample sketch provides the raw touch screen data, and not pixel position. This requires calibration of the touch screen with the display, which I will be posting about, soon.

postuma

  • Jr. Member
  • **
  • Posts: 64
Re: Oak with a touch-enabled TFT LCD screen
« Reply #1 on: December 18, 2016, 10:59:23 am »
So, the update: I've adapted Paul Stoffregen's library (https://github.com/PaulStoffregen/XPT2046_Touchscreen), adding a calibrate function to convert touch screen coordinates to pixel values.



The sample sketch used to derive calibration parameters, touch_XPT2046_digistump_oak_calibration.ino, is Oak-only, but should be easily adapted to other Arduino-type processors. Sketch touch_XPT2046_digistump_oak.ino, as is, displays raw touch values. Uncomment the

//  ts.calibrate(-.00114, -.0653, 254, -.0885, -.00125, 348, 320, 240, 1);

line and it will now show pixel coordinates. The calibration parameters above are particular to my test screen, but may work with other screens using the ILI9341 and XPT2046 controllers.

Usage: the first six parameters are the calibration values we get from touch_XPT2046_digistump_oak_calibration, and the next two are the screen width and height in the screen orientation you will be using. The final optional parameter sets the screen rotation; 0 gives the original unrotated orientation, 1 defines a 90 degree counter-clockwise rotation, 2 defines 180 degrees counter-clockwise, and 3 is 270 degrees. This matches most screens with most graphics libraries - but not all. Please check.

Again, the Oak's version of SPI.cpp may still be out of date, and may cause erroneous values. See more at http://www.ars-informatica.ca/eclectic/digistump-oak-with-a-touch-enabled-display-screen-circuit-and-code/. The entire project is described starting at http://www.ars-informatica.ca/eclectic/tutorial-digistump-oak-with-a-touch-enabled-display-screen/.

Three-point calibration has been implemented using Fang and Chang's Calibration in touch-screen systems, http://www.ti.com/lit/an/slyt277/slyt277.pdf, Analog Applications Journal, 2007.

The modified software is released under the same conditions as the original. Feel free to modify, share, etc.