These 2.8″ 240×320 pixel color TFT displays for $8-10 can be found on ALiExpress. There’s also an equivalent-looking one offered by AdaFruit for $30 if you want one fast – the pins are quite differently label, but I’m willing to be it’s virtually equivalent. I just LOVE AliExpress – stuff is SO CHEAP! But, as is usually the case, the Adafruit one is well-document..the Chinese version, not so much. There are a smattering of posts and github libraries out there, but none document very clearly exactly how to hook one of these up, so I will describe here how I got one working.
I first spent a bunch of time trying to get one of the libraries that was coming up a lot for the XPT2046 touch functionality to work. That XPT2046 library seems to be the “standard” out there, but there’s no clear documentation of the hookup and it uses a somewhat cumbersome library for the TFT display.
The key that finally got me going was this blog post – it was one of the most useful, since it has a good hookup diagram, which I’ll include here, in case the post goes away. That post also refers to the XPT2046 library for touch input, but uses the AdaFruit TFT Driver and even includes a zip file containing the AdaFruit driver and examples comprised of versions of the XPTCalibrate and XPTPaint sketchs modified to use the AdaFruit display library. With those samples and the help of the hookup diagram, I was able to get things working. The diagram is a big help, since the pin labels on the cheap Chinese board don’t really match what is referred to in sample sketches. Also, it isn’t completely intuitive that you need to connect the SPI pins (SCK, CS, MOSI & MISO) to the standard pins for those signals on the ESP8266. I include the diagram here, in case that post goes away.
Once I got the pin hookup figured out, I was also able to get the sketches included with the XPT2046 library working – they use a display driver (which you also have to install) authored by the same developer, but I wound up using the AdaFruit driver for the ILI9341 TFT. It is based on AdaFruit_GFX and offers a lot more functionality, including a conventient button-drawing-press-detection framework.
Overall, this is another one of those components that just blows me away for being so cheap (especially when you buy it from China), but giving you such impressive functionality. In my next post, I’ll outline how I incorporate this into a wrist-controller form my LightSuit Version 3.