Is this not the cutest little display for the Raspberry Pi? It features a 2.8″ display with 320×240 16-bit color pixels and a resistive touch overlay. The plate uses the high speed SPI interface on the Pi and can use the mini display as a console, X window port, displaying images or video etc. Best of all it plugs right in on top!
It’s designed to fit nicely onto the Pi Model A or B but also works perfectly fine with the Pi 2 or Model B+ as long as you don’t mind the PCB overhangs the USB ports by 5mm
This design uses the hardware SPI pins (SCK, MOSI, MISO, CE0, CE1) as well as GPIO #25 and #24. All other GPIO are unused. Since we had a tiny bit of space, there’s 4 spots for optional slim tactile switches wired to four GPIOs, that you can use if you want to make a basic user interface. For example, you can use one as a power on/off button.
We bring out GPIO #23, #22, #21, and #18 to the four switch locations!
The PiTFT requires kernel support and a couple other things to make it a nice stand-alone display. We have a detailed step-by-step setup for hackers who want to tweak, customize or understand the PiTFT setup. If you just want to get going, check out the following for easy-install instructions!
Ready to go image
If you want to start with a fresh image, we have one for Raspbian – click here to download it and install into a new SD card. Unzip and follow the classic SD card burning tutorial
DIY Installer script
If you don’t want to download an image, you can run our installation package helper from inside your existing Raspbian install. It will download the kernel add-ons, and configure your Pi for PiTFT joy
The helper is available for perusal here if you are interested in how it works
To download and run it, simply run the following commands:
- curl –SLs https://apt.adafruit.com/add | sudo bash
- sudo apt–get install –y adafruit–pitft–helper
The first command adds apt.adafruit.com to your repository list, so you can grab code directly from adafruit’s servers
The second does the actual download and installation, it’ll take a while because there’s a lot of software to replace for PiTFT support
OK now the kernel is installed, all you have to do is run the helper which will configure the kernel device tree overlays and add the few configurations to make the console show up, etc.
- sudo adafruit–pitft–helper –t 28r
This will install the “2.8 Resistive” type of PiTFT into the current install. This is the same as the 2.4″ Resistive screen too (same resolution, pinout, etc.)
At the end you will be prompted on whether you want the text console to appear on the PiTFT. Answer Y or N depending on your personal desires!
You will also be prompted on whether you want one of the tactile buttons to act as an ‘on off’ switch. Answer Y or N depending on your personal desires!
Run sudo reboot to try out your fancy new PiTFT 🙂
In the next few steps we’ll cover the detailed installation procedure. Chances are, you should grab the Easy Install image or script. If you have some interest in the details of how we install the PiTFT setup, read on!
In order to add support for the 2.4″ or 2.8″ TFT and touchscreen, we’ll need to install a new Linux Kernel. Lucky for you, we created a kernel package that you can simply install over your current Raspbian (or Raspbian-derived) install instead of needing a whole new image. This makes it easier to keep your install up-to-date.
To use our kernel .deb files you must be using Raspbian or derivative. This wont work with Arch or other Linux flavors. As Raspbian is the official OS for the Pi, that’s the only Linux we will support! Others can recompile their own kernel using our patchfile, but we have no tutorial or support or plans for such.
Before you start
You’ll need a working install of Raspbian with network access. If you need help getting that far, check out our collection of Pi tutorials.
We’ll be doing this from a console cable connection, but you can just as easily do it from the direct HDMI/TV console or by SSH’ing in. Whatever gets you to a shell will work!
Also, run sudo apt-get update !
Download & Install Kernel
The only way we’re distributing the PiTFT kernel packages right now is thru apt.adafruit.com so you’ll still need to run:
- curl –SLs https://apt.adafruit.com/add | sudo bash
To add apt.adafruit.com to your list of software sources
hen install the kernel with
- sudo apt–get install –y adafruit–pitft–helper
This will take a up to 20 minutes so go make a sandwich or coffee. It takes longer than it used to because there’s now 2 kernels (v6 and v7 arm) and 2 kernel module directories.
The rotate= variable tells the driver to rotate the screen 0 90 180 or 270 degrees.
is portrait, with the bottom near theUSB jacks
90 is landscape, with the bottom of the screen near the headphone jack
180 is portrait, with the top near the USB jacks
270 is landscape, with the top of the screen near the headphone jack.
You can change this file with nano and reboot to make the change stick.
The speed= variable tells the driver how to fast to drive the display. 32MHz (32000000) is a good place to start but if your screen is acting funny, try taking it down to 16MHz (16000000) especially if you’re doing something like using a GPIO extender to put the screen away from the Pi.
Save the file. Now we’ll just reboot to let it all sink in.
sudo shutdown -h now (if you don’t have the TFT installed, shutdown, place the TFT on the Pi and re-power)
sudo reboot (if you have the TFT plate installed already)
When the Pi restarts, the attached PiTFT should start out all white and then turn black. That means the kernel found the display and cleared the screen. If the screen did not turn black, that means that likely there’s something up with your connection or kernel install. Solder anything that needs resoldering!
Now that you’re rebooted, log back in on the console/TV/SSH. There’s nothing displayed on the screen yet, we’ll do a test to make sure everything is perfect first!
Run the following commands to startx on the /dev/fb1 framebuffer, a.k.a PiTFT screen:
- sudo mv /usr/share/X11/xorg.conf.d/99–fbturbo.conf ~
- export FRAMEBUFFER=/dev/fb1
You should see the Pi desktop show up on the TFT! Congrats, you’ve completed the first test perfectly.
Hit Control-C in the console to quit the X server so we can continue configuration
Next up we’ll add support for the touch screen automatically on boot. Edit the module list with
sudo nano /etc/modules
and add stmpe-ts on a line at the end
Save the file and reboot the Pi with sudo reboot and look at the console output (or run dmesg in the console window after logging in) you will see the modules install. Look in particular for the STMPE610 detection and the ILI9340 screen frequency as highlighted here
Create the directory and new calibration configuration file:
sudo mkdir /etc/X11/xorg.conf.d
sudo nano /etc/X11/xorg.conf.d/99-calibration.conf
and enter in the following lines, then save.
- Section “InputClass”
- Identifier “calibration”
- MatchProduct “stmpe-ts”
- Option “Calibration” “3800 200 200 3800”
- Option “SwapAxes” “1”
You can now try to run X again with
Type Control-C to quit X
If you don’t ever want to have to type FRAMEBUFFER=/dev/fb1 before startx, you can make it a default state by editing your profile file: sudo nano ~/.profile and adding
near the top and saving the file. Then reboot to reload the profile file. It will now always assume you want to use /dev/fb1
Setting up the Touchscreen
Now that the screen is working nicely, we’ll take care of the touchscreen. There’s just a bit of calibration to do, but it isn’t hard at all.
Before we start, we’ll make a udev rule for the touchscreen. That’s because the eventX name of the device will change a lot and its annoying to figure out what its called depending on whether you have a keyboard or other mouse installed.
sudo nano /etc/udev/rules.d/95-stmpe.rules
to create a new udev file and copy & paste the following line in:
emove and re-install the touchscreen with
sudo rmmod stmpe_ts; sudo modprobe stmpe_ts
Then type ls -l /dev/input/touchscreen
It should point to eventX where X is some number, that number will be different on different setups since other keyboards/mice/USB devices will take up an event slot
There are some tools we can use to calibrate & debug the touchscreen. Install the “event test” and “touchscreen library” packages with
Unfortunately xstroke hasn’t been actively maintained for a few years so there isn’t a binary package you can directly install. However compiling the tool is straightforward and easy with the steps below. Credit for these installation steps goes to mwilliams03 at ozzmaker.com.
First install a few dependencies by opening a command window on the Pi and executing:
- sudo apt–get –y install build–essential libxft–dev libxpm–dev libxtst–dev
- cd ~
- wget http://mirror.egtvedt.no/avr32linux.org/twiki/pub/Main/XStroke/xstroke-0.6.tar.gz
- tar xfv xstroke–0.6.tar.gz
- cd xstroke–0.6
- sed –i ‘/^X_LIBS = / s/$/ -lXrender -lX11 -lXext -ldl/’ Makefile
- sudo make install
Once xstroke is installed you will want to add a couple menu shortcuts to start and stop xstroke. Execute the following commands to install these shortcuts:
- wget https://github.com/adafruit/PiTFT_Extras/raw/master/xstroke.desktop
- wget https://github.com/adafruit/PiTFT_Extras/raw/master/xstrokekill.desktop
- sudo cp xstroke*.desktop /usr/share/applications/
To use xstroke I highly recommend using a plastic stylus instead of your finger. Also calibrate the touchscreen for X-Windows so you have the best control over the cursor possible.
Click the XStroke menu option to start xstroke. You should see a small pencil icon appear on the bottom right side of the screen. The pencil icon means xstroke is running, however by default it’s not yet looking for gesture input.
Open an application that takes text input, such as LXTerminal. To enable gesture input click the xstroke pencil icon. You should see the pencil turn green and the text ‘abc’ written over top of the icon. You might need to click the icon a few times to get the click to register in the right spot.
When xstroke is looking for gesture input you can drag the mouse cursor in a gesture anywhere on the screen to send specific key strokes. Here’s a picture of the possible gestures you can send:
To draw a gesture from the above image, press anywhere on the screen, start from the circle in the gesture, and follow the gesture pattern towards the arrow. As you draw a gesture you should see a blue line displayed that shows what you’ve drawn. Lift up the stylus when you get to the end of the gesture at the arrow. If xstroke recognizes the gesture it will send the appropriate key press to the active window. Try drawing a few characters from the image above to get the hang of writing gestures.
A few very useful gestures are backspace (which deletes a character), return/enter, and space. To draw a backspace gesture just draw a line going from the right side of the screen to the left side. The gesture for return/enter is a diagonal line from the top right to bottom left. Finally a space is a straight line from the left to the right.
Note that when xstroke is looking for gestures you might not be able to click or control the cursor as you normally would expect. To stop xstroke’s gesture recognition carefully press the xstroke pencil icon again until the ‘abc’ text disappears. I’ve found this process can be a little finicky as the icon is very small and any movement will be interpreted as a gesture. Use a light touch and try a few times to click the icon.
If you get stuck completely and can’t disable xstroke by clicking the icon, connect to the Raspberry Pi in a terminal/SSH connection and run ‘killall xstroke’ (without quotes) to force xstroke to quit. The normal way to stop xstroke is to navigate to the Accessories -> XStroke Kill command, but you might not be able to do that if xstroke is listening for gesture input.
Have fun using xstroke to control your Pi by writing gestures on the PiTFT screen!
My PiTFT used to work, now it doesn’t!
Did you do an
apt-get upgrade? This command may blow away our PiTFT kernel which means that you will no longer have PiTFT support, you will have to redo the easy-install steps to reinstall the kernel.
You may be able to reinstall the Adafruit kernel like so:
sudo apt-get install raspberrypi-bootloader=1.20150309-1
If it tells you that the latest version is already installed, try this instead:
sudo apt-get install --reinstall raspberrypi-bootloader=1.20150309-1
…you can check here and substitute the most recent version you see in the
My PiTFT works for a bit and then I get a black screen with a short line of white pixels in one corner
Sounds like you tried to configure your Pi to ‘boot straight to X’, that is, start up the graphics interface on boot. This doesn’t work by default because the Pi operating system is not expecting a PiTFT so it boots to the HDMI output. See below for how to set up your Pi to boot to X on the PiTFT
To ‘fix’ this, you can either connect an HDMI monitor, then in a terminal window run sudo raspi-config and configure the Pi to boot to the command line not X! If you do not have an HDMI monitor, you can also try a console cable
How can I force the Pi to bring up X on the HDMI/TV monitor?
Use the fb0 framebuffer when you want to display stuff on the HDMI/TV display, for example:
will use the HDMI/TV framebuffer for X windows instead of the PiTFT
That doesn’t work! I can’t get X on HDMI!
FRAMEBUFFER=/dev/fb0 startx &
FRAMEBUFFER=/dev/fb1 startx &
wind up showing the GUI on your PiTFT, enter the following instruction from the command line:
- sudo mv /usr/share/X11/xorg.conf.d/99–fbturbo.conf ~
I’m tring to run startx and I get FATAL: Module g2d_23 not found.
sudo mv /usr/share/X11/xorg.conf.d/99-fbturbo.conf ~
Why doesn’t the tactile button on GPIO #21 work?
All the PiTFT’s we ship now have the button labeled #21 and #27
I want better performance and faster updates!
You can change the SPI frequency (overclock the display) by editing /boot/config.txt and changing the dtoverlay options line to:
Or whatever you like for speed, rotation, and frames-per-second. BUT, here’s the thing, the Pi only supports a fixed number of SPI frequencies. So tweaking the number a little won’t do anything. The kernel will round the number to the closest value. You will always get frequencies that are 250MHz divided by an even number. Here’s the only SPI frequencies this kernel supports
- 15,625,000 (a.k.a 16000000 = 16 MHz)
- 17,857,142 (a.k.a. 18000000 = 18 MHz)
- 20,833,333 (a.k.a 21000000 = 21 MHz)
- 25,000,000 (= 25 MHz)
- 31,250,000 (a.k.a 32000000 = 32MHz)
- 41,666,666 (a.k.a 42000000 = 42MHz)
- 62,500,000 (a.k.a 62000000 = 62MHz)
So if you put in 48000000 for the speed, you won’t actually get 48MHz, you’ll actually only get about 42MHz because it gets rounded down. We tested this display nicely with 32MHz and we suggest that. But you can put in 42MHz or even try 62MHz and it will update faster
You can tweak fps (frames per second) from 20 to 60 and frequency up to 62MHz for tradeoffs in performance and speed. Reboot after each edit to make sure the settings are loaded properly. There’s a trade off that if you ask for higher FPS you’re going to load the kernel more because it’s trying to keep the display updated.
For more detail: Adafruit PiTFT – 2.8 Touchscreen Display for Raspberry Pi