Adafruit PiTFT - 2.
Guide Contents Guide Contents Overview Original PiTFT PiTFT Plus Assembly Easy Install Ready to go image DIY Installer script Step 1. Expand Filesystem Step 2. Install new Kernel Step 3.
My PiTFT's rotation/calibration isn't working in X11 Playing Videos How To Play Videos Converting/Resizing Videos Displaying Images Using FBCP Backlight Control PWM Backlight Control with GPIO 18 On / Off Using STMPE GPIO For older versions of PiTFT Kernel PiTFT PyGame Tips Install pip & pygame Ensure you are running SDL 1.
Overview Is this not the cutest little display for the Raspberry Pi? It features a 2.8" display with 320x240 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.
PiTFT Plus The newer PiTFTs are updated to fit perfectly onto the Pi Zero, Pi 3, Pi 2 or Model A+, B+! (Any Pi with a 2x20 connector) Not for use with an old Pi 1 with 2x13 connector © Adafruit Industries https://learn.adafruit.
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.
This tutorial series shows you how to install the software, as well as calibrate the touchscreen, splay videos, display images such as from your PiCam and more! © Adafruit Industries https://learn.adafruit.
Assembly This tutorial page is for PiTFT that came as a kit. If your PiTFT is already assembled, skip this step! Before you start check that you have the parts you need: an assembled PiTFT plate with the 2.8" screen, extra tall female header and the 2x13 IDC socket. Note that it is normal for the screen to be 'loose' - this is so its easier for you to solder the connector on! © Adafruit Industries https://learn.adafruit.
Check also on the back that the TFT is attached and that the flex connector is seated into the onboard FPC socket. The easiest way to attach the header is if you have a Raspberry Pi as a 'stand' - make sure its powered off & unplugged! © Adafruit Industries https://learn.adafruit.
Plug the extra tall female header into the GPIO port on the Pi as shown. Make sure its seated nice and flat Place the PiTFT shield on top so all the pins stick through the connector on the side. Gently flip the TFT so its off to the side and wont be in your way while you solder Heat up your soldering iron, and grab some solder. Start by tack-soldering one of the corners while pressing on the plate to make it sit flat. Once you have one or two pins done you can continue to solder each of the pins.
© Adafruit Industries https://learn.adafruit.
Before attaching the display, check that all the pins are soldered nicely and there's no bridging, cold solder, shorts, or unsoldered pins. Now we can attach the screen. Remove the two thin tape cover strips. Line up the screen on the white outline, make sure there's some space from the header you just soldered in and the metal sides of the screen. As long as you don't really press down on the screen you can reposition it once or twice. © Adafruit Industries https://learn.adafruit.
Once you have the screen so it is definitely not touching the header, you can gently press on the sides to secure the tape. If the protective plastic cover is still on the screen you can press it against a clean table from above. That way you will really securely attach it! If you want to attach an Adafruit Cobbler or similar, you can solder in the optional 2x13 IDC on the bottom of the screen as shown here. This will keep the top side clean and flat.
You can attach a 26-pin IDC cable just make sure the pin 1 indicator is on the right as indicated in this photo there's also a #1 marking on the PCB! © Adafruit Industries https://learn.adafruit.
Easy Install 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 two for Raspbian.
sudo raspi-config (expand filesystem) sudo reboot Step 2. Install new Kernel Then, once the filesys is expanded, download and install t he new kernel by running the following commands: curl -SLs https://apt.adafruit.com/add-pin | sudo bash sudo apt-get install raspberrypi-bootloader adafruit-pitft-helper raspberrypi-kernel and type y (yes) when prompted The first command adds apt.adafruit.
It's normal for the Pi to pause and/or take a while at this step for many minutes, theres a lot of kernel software to replace Step 3. Enable & Configure the PiTFT OK now the kernel and helper are 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 3.2" and 2.
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! Thats it! Run sudo reboot to try out your fancy new PiTFT :) © Adafruit Industries https://learn.adafruit.
Detailed Installation If you've grabbed our Easy Install image, or use the script, this step is not required, it's already done! This is just for advanced users who are curious on how to configure and customize the kernel install 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.
To run these all the setup and config commands you'll need to be logged into a proper Terminal - use ssh, a console cable, or the main text console (on a TV). The WebIDE console may not work. 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-pin | sudo bash To add apt.adafruit.
OK since you're not going to run the helper, lets add the device tree overlay manually. Edit /boot/config.txt with sudo nano /boot/config.txt and add the following lines at the end: [pi1] device_tree=bcm2708-rpi-b-plus.dtb [pi2] device_tree=bcm2709-rpi-2-b.dtb [all] dtparam=spi=on dtparam=i2c1=on dtparam=i2c_arm=on dtoverlay=pitft28r,rotate=90,speed=32000000,fps=20 © Adafruit Industries https://learn.adafruit.
The rotate= variable tells the driver to rotate the screen 0 90 180 or 270 degrees. 0 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.
sudo mv /usr/share/X11/xorg.conf.d/99-fbturbo.conf ~ export FRAMEBUFFER=/dev/fb1 startx 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.
after logging in) you will see the modules install. Look in particular for the STMPE610 detection and the ILI9340 screen frequency as highlighted here We can set up the touchscreen for rotate=90 configuration by doing the following (for more delicate calibration or for other rotate=XX values, see the next section) 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.
You can now try to run X again with FRAMEBUFFER=/dev/fb1 startx 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 export FRAMEBUFFER=/dev/fb1 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 © Adafruit Industries https://learn.adafruit.
© Adafruit Industries https://learn.adafruit.
Resistive Touchscreen Manual Install & Calibrate If you've grabbed our Easy Install image, or used the installer script, this step is not required, it's already done! This is just for advanced users who are curious on how to configure and customize the touchscreen This procedure is identical for the 2.4", 2.8", 3.2" and 3.5" Resistive PiTFTs. Not for use with the Capacitive PiTFT! Setting up the Touchscreen Now that the screen is working nicely, we'll take care of the touchscreen.
Remove 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 sudo apt-get install evtest tslib libts-bin © Adafruit Industries https://learn.
Running evtest Now you can use some tools such as sudo evtest /dev/input/touchscreen which will let you see touchscreen events in real time, press on the touchscreen to see the reports. © Adafruit Industries https://learn.adafruit.
AutoMagic Calibration Script If you rotate the display you need to recalibrate the touchscreen to work with the new screen orientation. You can manually run the calibration processes in the next section, or you can run a small Python script which will automatically set a default touchscreen calibration based on the screen orientation.
Try using this default calibration script to easily calibrate your touchscreen display. Note that the calibration values might not be exactly right for your display, but they should be close enough for most needs. If you need the most accurate touchscreen calibration, follow the steps in the next section to manually calibrate the touchscreen.
Next you can run sudo TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/touchscreen ts_test which will let you draw-test the touch screen. Go back and re-calibrate if you feel the screen isn't precise enough! X Calibration You can also calibrate the X input system but you have to use a different program called xinput_calibrator You can do this if the calibration on the screen isnt to your liking or any time you change the rotate=XX module settings for the screen.
Before you start the xinput_calibrator you will need to delete the old calibration data so run sudo rm /etc/X11/xorg.conf.d/99-calibration.conf Before running startx and the calibrator - otherwise it gets really confused! Now you'll have to run the xcalibrator while also running X.
Run sudo nano /etc/X11/xorg.conf.d/99-calibration.conf and copy the Section "InputClass" Identifier "calibration" MatchProduct "stmpe-ts" Option "Calibration" "172 3763 3769 164" Option "SwapAxes" "1" EndSection or whatever you got, into there. You can quit X if you want by typing fg to bring that command into the foreground, and then Control-C to quit.
Console Configuration If you've used our installer script, this step is not required, it's already done! This is just for advanced users who are curious on how to configure and customize the console One fun thing you can do with the display is have it as your main console instead of the HDMI/TV output. Even though it is small, with a good font you can get 20 x 40 of text. For more details, check out https://github.
the font, run sudo dpkg-reconfigure console-setup and go thru to select Terminus 6x12 © Adafruit Industries https://learn.adafruit.
Turn off Console Blanking You may notice the console goes black after 30 minutes, this is a sort of 'power saving' or 'screensaver' feature. Raspbian Jessie Add the following line to /etc/rc.local sudo sh -c "TERM=linux setterm -blank 0 >/dev/tty0" on the line before the final exit 0 Raspbian Wheezy © Adafruit Industries https://learn.adafruit.
You can disable this by editing /etc/kbd/config and looking for BLANK_TIME=30 and setting the blank time to 0 (which turns it off) BLANK_TIME=0 © Adafruit Industries https://learn.adafruit.
Userspace Tools Major updates to Raspbian often break PiTFT support. The PiTFT kernel package doesn’t work across different OS releases, and it’s a lot of work to prepare a new one. We’ve experimented with an alternate approach that doesn’t rely on a custom kernel — it instead works in “user space.” So far it’s worked well regardless of the OS version being used! There are tradeoffs.
/usr/local/bin/tftcp & The screen looks best if the HDMI resolution exactly matches the PiTFT resolution, so the final step is to configure the system for 320x240 video: sudo nano /boot/config.txt Append the following lines to the bottom of the file: disable_overscan=1 hdmi_force_hotplug=1 hdmi_group=2 hdmi_mode=87 hdmi_cvt=320 240 60 1 0 0 0 OPTIONAL: you can also use “640 480” in place of “320 240” above.
reboot and both PiTFT and touch should be active now. © Adafruit Industries https://learn.adafruit.
HELP! (FAQ) My PiTFT used to work, now it doesn't! Did you do an apt-get upgrade or rpi-update ? This command will 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. If you had already made a working PiTFT setup, you may be able to reinstall the Adafruit kernel like so: sudo apt-get install raspberrypi-kernel=1.
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 runsudo 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? There's two ways to do it.
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.
Once you have a PiTFT installation setup you can add a custom X windows configuration to use the PiTFT by default. Then you can use the normal raspi-config boot to console/desktop options to control if the Pi boots to a console or desktop. See the detailed instructions on this page of the guide for more information. My screen isn't working/works erratically/looks funny Check to make syre that the flat flex cable is fully seated in the connetor and the 'ears' are pushed in to secure it.
isn't being picked up: Check /usr/share/X11/xorg.conf.d for a file called 10-evdev.conf If you don't see that file 1. You need to sudo apt-get install xserver-xorg-input-evdev , and then... 2. If you do have a 40-libinput.conf in that same directory, you must remove it even if/once evdev is installed, since it will override the 10-evdev.conf otherwise. Thanks to cerebrate in the forums for the hint! © Adafruit Industries https://learn.adafruit.
Playing Videos How To Play Videos You can play many types of videos on the screen, using mplayer you don't even need to run X and you can script the movies to play using Python. We'll show you how to just play one video for now. To demo, we'll use an mp4 of Big Buck Bunny for 320 pixel wide screens. Below we show you how to create/resize videos, but to make it easy, just download our version with: wget http://adafruit-download.s3.amazonaws.com/bigbuckbunny320p.
OK now you just have to run: sudo SDL_VIDEODRIVER=fbcon SDL_FBDEV=/dev/fb1 mplayer -vo sdl -framedrop bigbuckbunny320p.mp4 If your video is not sized for 320 wide, you may need to add a -zoom after -framedrop so that it will resize - note that this is quite taxing for the Pi, so it may result in a choppy or mis-synced video! Converting/Resizing Videos © Adafruit Industries https://learn.adafruit.
It's possible to play full length videos on the TFT plate, but since the screen is small and the Pi cant use hardware accelleration to play the videos its best to scale them down to 320x240 pixels. This will be easier for the Pi to play and also save you tons of storage space. For this demo, we'll be using the famous Big Buck Bunny video, which is creative commons and also very funny! You can download it from the link above, we'll be using the 720p AVI version.
Click START to begin the conversion, it will take a minute or two. That's it! You now have a smaller file. Don't forget to play it on your computer to make sure it plays right before copying it to your Pi © Adafruit Industries https://learn.adafruit.
Displaying Images You can display every day images such as GIFs, JPGs, BMPs, etc on the screen. To do this we'll install fbi which is the frame buffer image viewer (not to be confused with the FBI agency!) sudo apt-get install fbi will install it Grab our lovely wallpapers with wget http://adafruit-download.s3.amazonaws.com/adapiluv320x240.jpg wget http://adafruit-download.s3.amazonaws.com/adapiluv480x320.png For 320x240 PiTFTs (2.2", 2.4", 2.8" or 3.
That's it! © Adafruit Industries https://learn.adafruit.
Using FBCP The Ideal: Adafruit’s PiTFT displays are razor sharp. Whereas small composite screens on the Raspberry Pi usually require some video scaling (resulting in blurriness), PiTFT uses the GPIO header, digitally controlled pixel-by-pixel for a rock steady image. Though not a lot of pixels, it works great for retro gaming (and the display neatly stacks above the board, no side protuberances for video cables).
Backlight Control The backlight of the 2.8" PiTFT has 4 LEDs in series and it draws ~75mA at all times, controlled by a transistor. The PiTFT 3.5" display has 6 LEDs in a row, and we use a boost converter to get the 5V from the Pi up to the ~20V needed to light up all the LEDs. There might be times you'd like to save some power and turn off the backlight. The screen and touchplate will still work, you just can't see anything.
On / Off Using STMPE GPIO Another option is to just turn it on and off using the extra GPIO created by the touchscreen driver Thanks to the raspberry Pi overlay system, this GPIO is already set up for you in a file called /sys/class/backlight/soc:backlight/brightness To turn the backlight off run sudo sh -c 'echo "0" > /sys/class/backlight/soc\:backlight/brightness' To turn it back on, run sudo sh -c 'echo "1" > /sys/class/backlight/soc\:backlight/brightness' For older versions of PiTFT Kernel On older ve
© Adafruit Industries https://learn.adafruit.
PiTFT PyGame Tips Since the PiTFT screen is fairly small, you may need to write custom UI programs. Pygame is the easiest way by far to do this. Jeremy Blythe has an excellent tutorial here on getting started. However, before you follow that link you'll want to set up pygame for the best compatibility: Install pip & pygame Install Pip: sudo apt-get install python-pip Install Pygame: sudo apt-get install python-pygame (this will take a while) Ensure you are running SDL 1.2 SDL 2.x and SDL 1.2.
Edit a new file with sudo nano installsdl.sh and paste in the following text: #!/bin/bash #enable wheezy package sources echo "deb http://archive.raspbian.org/raspbian wheezy main " > /etc/apt/sources.list.d/wheezy.list #set stable as default package source (currently jessie) echo "APT::Default-release \"oldstable\"; " > /etc/apt/apt.conf.d/10defaultRelease #set the priority for libsdl from wheezy higher then the jessie package echo "Package: libsdl1.
it will force install SDL 1.2 OK now you can continue with pygame © Adafruit Industries https://learn.adafruit.
Extras! Tactile switch as power button Its a good idea to safely turn off your Pi with a good sudo shutdown -h now but that often means pulling out a keyboard or connecting to the console. With our kernel we added a cool module that will let you turn any GPIO into a power button. Since there's a couple of tactile switches right there on the front, lets turn one into a power button. Press once to properly turn off the pi, press again to start it up.
Making it easier to click icons in X If you want to double-click on icons to launch something in X you may find it annoying to get it to work right. In LXDE you can simply set it up so that you only need to single click instead of double.
Boot to X Windows on PiTFT To enable booting straight to X windows on the PiTFT follow the steps below. First make sure a display configuration which would conflict is not present by executing in a terminal on the Pi: sudo mv /usr/share/X11/xorg.conf.d/99-fbturbo.conf ~ Don't worry if the command fails with an error that the file doesn't exist. This failure is normal and should happen on a good PiTFT install. You can ignore it and move on.
If you want to disable booting to X, just use the raspi-config command again to choose the console boot option. Right-click on a touchscreen Obviously if you have a touchscreen, it cannot tell what finger you are pressing with. This means that all 'clicks' are left clicks. But if you want a right-click, you can do it. Just add the following lines into your InputClass of /etc/X11/xorg.conf.d/99-calibration.
Gesture Input With the PiTFT touchscreen and xstroke you can enter text in applications by drawing simple character gestures on the screen! Check out the video below for a short demonstration and overview of gesture input with xstroke: Installation 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.
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.
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! © Adafruit Industries https://learn.adafruit.
Downloads The latest kernel fork that adds all the TFT, touchscreen, and other addons is here on github Datasheet for the 'raw' 2.8" TFT display Original 2.8" PiTFT EagleCAD PCB Files on GitHub PiTFT Plus 2.8" EagleCAD PCB Files on GitHub PiTFT Plus 3.2" EagleCAD PCB Files on GitHub Fritzing Files in the Adafruit Fritzing Library 2.8" PiTFT Plus Schematic & Layout For the Pi B+ & Pi 2 version (2x20 header) © Adafruit Industries https://learn.adafruit.
© Adafruit Industries https://learn.adafruit.
PiTFT 3.2" Plus Schematic Original PiTFT 2.8" Schematic & Layout For the Original Pi 1 version (2x13 header) © Adafruit Industries https://learn.adafruit.
© Adafruit Industries Last Updated: 2018-02-15 10:32:51 PM UTC Page 70 of 70