March 12, 2017 by Daniel P. Clark

Installing the Adafruit 2.8″ TFT Display on the Raspberry Pi

One thing I’ve learned over and over from working on the Raspberry Pi is that it’s most likely going to take a chunk of time to get things set up just the way you want.  And this display is no different.

I’ve written in the past about How to Play HD Video on a Raspberry Pi  so this is a continuation from a Raspbian Linux distribution image already in that state.  I was feeling lazy and didn’t want to write this post, but if I ever have to do this again I don’t want to have to google so many steps again.  So hopefully you’ll find this useful as well.

First of all, it’s not plug and play… No, you need to update the Linux kernel, modify boot configurations, change terminal font sizes, and deal with other issues that come up along the way like the mirrors for the packages you need to install not working.  Yes, it’s a mess.

Starting Out

First I tried the instructions from here: Adafruit: Detailed Installation before realizing the available manual has an auto-configure option.  But I couldn’t get these working at first because the Debian package mirrors wouldn’t work so I had to modify my apt sources list to use some working mirrors. The download of the adafruit-pitft-helper package was still unavailable to me via apt but you can get it from Github.

The Details

You can have the screen plugged in if you want but you won’t see anything on it for some time so use an external screen for now.

First Adafruit has a script for downloading and installing the kernel.  This also adds them to your apt sources list.

curl -SLs https://apt.adafruit.com/add-pin | sudo bash

Next you need to install the boot loader and install helper:

sudo apt-get install raspberrypi-bootloader adafruit-pitft-helper

If the helper script doesn’t get retrieved then you’ll need to grab it from Github:

curl -SLs https://raw.githubusercontent.com/adafruit/Adafruit-PiTFT-Helper/master/adafruit-pitft-helper > adafruit-pitft-helper.sh
bash adafruit-pitft-helper.sh

You need to run this script adafruit-pitft-helper specifically to enable the console on your display.  The manual instructions on their website do not tell you how to do this, only for enabling the display for the graphical interface X11.  This script does the heavy lifting.

BEFORE REBOOTING you need to set your console font with:

sudo dpkg-reconfigure console-setup

Then choose:

  • UTF8
  • Guess optimal character set
  • <OK>
  • VGA
  • 8×8

If you accidentally rebooted and the fonts are too big to run the ncurses menu system then you can temporarily set your console font with:

setfont /usr/share/consolefonts/Uni1-VGA8.psf.gz

At this point the terminal is all set for your display.  Following this I will show you how to enable high definition video playback on your TFT display from the command line.  I won’t go into setting up the touchscreen for the X11 desktop, you can refer to the manual for that.  Personally I don’t think the Raspberry Pi makes a good desktop system as it’s slow, I much prefer the console.

Playing High Def Video

If you try the omxplayer from the previous blog post you’ll find the video doesn’t show up on the display.  The reason is that it’s rendering on frame buffer 0 when the TFT is using frame buffer 1.  To get around this you need to use frame buffer copying with the fbcp program.  The instructions they provide are close but don’t follow the second modprobe command (as it messed up my display).

Before I get to the modified instructions on installing fbcp I had to change my apt sources list as I couldn’t install cmake because the mirror wouldn’t respond.

So I commented out the raspbian mirror in /etc/apt/sources.list and added the following:

deb http://rpi.rutgers.edu/raspbian/raspbian/ wheezy main contrib non-free rpi
deb http://rpi.rutgers.edu/raspberrypi.collabora.com wheezy rpi
deb http://rpi.rutgers.edu/archive.raspberrypi.org/debian/ wheezy main

And for the SSH keys

wget http://rpi.rutgers.edu/raspbian/raspbian.public.key -O - | sudo apt-key add -

After you have these run sudo apt-get update .  Now you should be able to install cmake .

Installing fbcp

sudo apt-get install cmake
git clone https://github.com/tasanakorn/rpi-fbcp
cd rpi-fbcp/
mkdir build
cd build/
cmake ..
make
sudo install fbcp /usr/local/bin/fbcp
sudo modprobe fbtft dma

Now that you have it installed you’re ready to play some HD video.  One problem with fbcp is it changes the console resolution and makes it a bit unusable as a console, so you want to toggle it on and off around your video playback.  This is simple enough so lets write a bash command to do that for us for omxplayer.

Edit your .bashrc file in your home directory and put this in it.

omx() {
  fbcp &
  omxplayer $1
  killall fbcp
  sleep 0.1
  clear
}

Run source ~/.bashrc to load it into the current console.

Now when you want to play a video you type omx myvideo.mp4 and it switches to frame buffer copying, plays the video given as the first parameter with omxplayer (taking advantage of GPU high speed graphics), after omxplayer exits fbcp is closed out with the killall command, we then clear the display of any visual artifacts left behind and we’re back to where we need to be with a nice looking display!

Summary!

That’s it!  It’s a bit of a hassle especially when additional problems come up, but it’s doable!

As always I hope you found this educational and enjoyable!  Please feel free to comment, share, subscribe to my RSS Feed, and follow me on twitter @6ftdan!

God Bless!
-Daniel P. Clark

Image by Paul Keeling via the Creative Commons Attribution-NonCommercial 2.0 Generic License

#display#HD#how-to#howto#linux#Raspberry Pi#RPI#TFT#video

Leave a Reply

Your email address will not be published / Required fields are marked *