2.8" TFT Touchscreen: Created by Lady Ada
2.8" TFT Touchscreen: Created by Lady Ada
Guide Contents 2
Overview 3
Connection Options 7
Mounting Options 11
Backlight Wiring 12
TFT Wiring 14
LCD Test 17
Graphics Library 20
Touchscreen 27
Download Library 28
Bitmaps 31
Downloads 33
Support Forums 34
Add some jazz & pizazz to your project with a color touchscreen LCD. This TFT display is big
(2.8" diagonal) bright (4 white-LED backlight) and colorful (16-bit 262,000 different shades)!
240x320 pixels with individual pixel control, this has way more resolution than a black and
white 128x64 display. As a bonus, this display has a resistive touchscreen attached to it
already, so you can detect finger presses anywhere on the screen.
Of course, we wouldn't just leave you with a datasheet and a "good luck!" - we've written a
full open source graphics library that can draw pixels, lines, rectangles, circles and
text (http://adafru.it/aHk) . We also have a touch screen library that detects x, y and z
(pressure) (http://adafru.it/aT1) and example code to demonstrate all of it. The code is
written for Arduino but can be easily ported to your favorite microcontroller!
Specificatio ns:
The TFT LCD requires a lot of pins to use with your processor. We have two breakouts
available which you can use depending on your application.
The first (right hand side) is a single 1x20 header strip with 0.1" spacing. This is perfect for
breadboard use or if you have to do some hand wiring. You can use 'straight' header or 'right
angle' header so that it stands up straight (although it may be harder to touch if its soldered
this way).
To solder the header, we suggest placing a 20pin strip of header, long pins down into a
breadboard.
This cable is a 2x5 not 2x10 but its what the larger cable will look like
You can pick up a socket-socket cable from digikey for $2 - they're also available from any
other electronics shop (http://adafru.it/aLu).
We wanted to make sure that you could easily put this display in a box. There are four
mounting holes on tabs. If you really don't need the tabs they can be cut off with a hacksaw
or tin-snips. The holes are 2.25" apart in the short direction and 2.95" apart in the long
direction. The drill holes are 0.125" and will easily take a #4 imperial or M3 (3mm) screw. The
PCB is 0.063" thick.
The backlight is the first. It is made of 4 white LEDs in parallel with a transistor to control
them. The LEDs can draw as much as 80mA all together, but you can PWM the backlight to
dim it - the transistor makes it easy to connect any kind of microcontroller output. You can
also connect the backlight pin directly to a 3 or 5V pin to turn it on all the way.
We'll begin by assuming you'll be using the 1x20 connector and an Arduino. Wiring may be
different for your microcontroller.
Start by connecting the first pin Gro und of the LCD to ground and the second pin 3-5V to
5V (you can use 3-5V, this pin will power the TFT and backlight so be sure it can supply
100mA). Then skip 5 pins and connect pin #8 Backlite to 5V.
Power up your set, and you'll see the 4 white LED backlight. If this isn't working, something is
amiss with your power supply. Go back and fix the wiring!
Now that the backlight is working, we can get the TFT LCD working. There are many pins
required, and to keep the code running fairly fast, we have 'hardcoded' Arduino digital pins
#2-#9 for the 8 data lines.
Start at the end of the TFT (other side than the power pins) and in order connect the pins to
digital 7 thru 2. If you're using a mega, connect the TFT Data Pins #0-7 to Mega pins #22-29,
in that order. Those Mega pins are on the 'double' header.
If you're using a mega, connect the TFT Data Pins #0-7 to Mega pins #22-29, in that order.
Those Mega pins are on the 'double' header.
We have example code ready to go for use with these TFTs. It's written for Arduino, which
should be portable to any microcontroller by adapting the C++ source.
In the TFTLCD Library folder, you will need to edit TFTLCD.h. On about line 12, you will see
"#define USE_ADAFRUIT_SHIELD_PINOUT". Comment out this line and save the file.
After restarting the Arduino software, you should see a new example folder called
Adafruit_TFTLCD and inside, an example called graphicstest. Upload that sketch to your
Arduino. You may need to press the Reset button to reset the arduino and TFT. You should
see a collection of graphical tests draw out on the TFT.
The graphics library has a few ready to go functions that should help you start out with your
project. Its not exhaustive and we'll try to update it if we find a really useful function.
First thing to note is that color is 16-bit, and that includes Red, Green and Blue in a 16-bit
variable. The way the color is packed in is the top 5 bits are red, the middle 6 bits are green
and the bottom 5 bits are blue.
For solid colors, we have this handy cheat-sheet. Of course, you can pick any of 262,000
colors but while starting out, this might be helpful.
// Color definitions
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
The Adafruit GFX library is what draws all the dots, lines, shapes, and text. Its fairly detailed
and has lots of cool stuff, for lots of info, check out http://learn.adafruit.com/adafruit-gfx-
graphics-library (http://adafru.it/aPx)
Here is a basic introduction to the GFX lib, it doesn't cover everything but it shows you what
some of the most popular shapes look like
First up is the most basic pixel pusher. You can call this with two coordinates and a color and
it will make a dot:
void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
If your lines are vertical or horizontal, you can call an optimized drawing function that doesn't
do all the angular calculations.
First start with setCurso r(x, y) this will place the top right corner of the text where-ever
you please. Initially, its set to (0, 0). Then set the text color with setTextCo lo r(co lo r) by
default its white. Then set the 'size' with setTextSize(size) this will 'multiply' the text by a
scaling factor. Above you can see scales of 1 (default), 2 and 3. This is because we only
ship the library with a simple font, to save space. You can just scale it to get bigger text
without requiring a new font.
Finally, you can use print() or println() just like you do with Serial! For example, to print a
string, use print("Hello wo rld") - that's the first line of the image above. To print
variables, you can also use print() the second line isprint(1234.56) and the third line is
You can also rotate your drawing. Note that this will not rotate what you already drew, but it
will relocate any new drawing.
The rotation variable can be 0, 1, 2 or 3. Rotation 0 makes it so that the display is in portrait
mode, with the USB jack in the top right. Rotation 2 is portrait, with the USB jack in the
bottom left. Rotation 1 is landscape mode, with the USB jack in the bottom right and rotation
3 is also landscape, with the USB jack in the top left.
When you rotate, the origin point moves with you. You may need to reference the size of
the screen, which changes between portrait and landscape, use width() and height()! To
get the size.
uint16_t width();
uint16_t height();
The LCD has a 2.8" 4-wire resistive touch screen glued onto it. You can use this for detecing
finger-presses, stylus', etc. You'll need 4 pins to talk to the touch panel but you can reuse
some of the pins for the TFT LCD! This is because the resistance of the panel is high enough
that it doesn't interfere with the digital input/output and we can query the panel in between
TFT accesses, when the pins are not being used.
You can wire up the 4 remaining pins as follows. the one on the very left (Y- orange) can
connect to digital 9, the next one over (X- green) connects to Analo g 2, The next one over
(Y+ blue) connects to Analo g 3 and the last one (X+ gray) connects to digital 8. The X-
and Y+ pins pretty much have to connect to those analog pins (or to analog 4/5) but Y-/X+
can connect to any digital or analog pins.
Uncompress the zip file and rename the folder To uchScreen (make sure it contains
To uchscreen.cpp and To uchscreen.h) then install in your libraries folder just like you
did for the TFT library
Now start up the tftpaint example in the Arduino library. The right hand side will have 'color
boxes' you can press to select which color you want to draw with. If you press the area to
the left where the screen ends, it will erase the screen.
We have an example sketch in the library showing how to display full color bitmap images
stored on an SD card. You'll need an SD or microSD breakout board such as this
one (http://adafru.it/aIH).
Modern versions of the Arduino software (0023, or 1.0 or later) already include an SD
card library. If you're holding out with an old version of the Arduino IDE, you can download
our library here (http://adafru.it/aP6). Click the Do wnlo ad ZIP button, uncompress the
archive and rename the resulting folder to “SD”. Move this folder into your Arduino libraries
folder (usually [home]/Documents/Arduino/Libraries) and restart the IDE.
Wire up the TFT as we have before (see previous page) and then wire up the microSD card
breakout.
On an Uno/Duemilanove you will want to use the following connections: Connect the SD card
with DI going to pin 11, DO going to pin 12 and SCK going to pin 13 (this is standard on all
our shields) Then pin 10 goes to CS. For MEGA, check the SPI connections go to the Mega's
SPI pins (not 10-13)
Copy the wo o f.bmp and miniwo o f.bmp files to a microSD card and insert it into the
breakout. Run the tftbmp example sketch in the TFTLCD library, you should see the images
show up. If not, check the serial monitor for hints as to why it may not be working.