texy
Forum Moderator
Forum Moderator
Posts: 5174
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

2.8" TFT + Touch Shield Board v4

Sun Mar 29, 2015 6:21 pm

[Update 26/06/2018 - step 7 is still required for Stretch]
[Updated 10/03/2016 - fix for Jessie and pygame issue added]

Hi,
this is the latest version of the first and original TFT touch panel display board designed specifically for the Raspberry Pi. This hardware version is compatible for all 40-way GPIO Pi's, so that is the A+, the B+ and the latest Pi 2B and uses the established HY28B display board which features a resolution of 320 x 240 at 65k colours. As usual the display utilises the excellent fbtft drivers authored by notro, only now those drivers are included in the very latest raspbian image, although not currently included in the image available from the foundations download page. I expect this to change in the very near future so that the rpi-update step is no longer required.

Screen and TP use hardware SPI ( SLCK, MOSI, MISO, CE0 & CE1 ) plus 3 additional GPIO lines ( GPIO17, GPIO18 & GPIO25 ), keeping the other GPIO lines free for other uses - the pcb has a 'breakout' GPIO port to connect too.
These are the steps required to configurethis add-on :

It is recommended to use the latest raspbian image , at the time of posting is dated 2015-02-16, to configure using an SSH session remotely, with no TV/Monitor connected to the HDMI port, and to connect the 2.8" Display board right from the start prior to connecting power to the Pi.

1..Run raspi-config

Code: Select all

sudo raspi-config
to configure your system as you need it, but include the following options :
Expand Filesystem
Advanced Options - Device Tree, select Yes to enable kernel device tree support.
[note you do NOT need to enable SPI as fbtft will utilise SPI automatically]

2..Unneccessary rpi-update step no longer required as later Raspbian images have full fbtft support.

3..Select the HY28B overlay

Code: Select all

sudo nano /boot/config.txt
at the end of the file add the following line

Code: Select all

dtoverlay=hy28b,rotate=90
4a..change the default console font, better for smaller displays

Code: Select all

sudo dpkg-reconfigure console-setup
Go through the following menu choices:
Encoding to use on the console: <UTF-8>
Character set to support: <Guess optimal character set>
Font for the console: Terminus (default is VGA)
Font size: 6x12 (framebuffer only)

4b..Allow the console to be shown on the display from boot-up modify /boot/cmdline.txt :

Code: Select all

sudo nano /boot/cmdline.txt
and add the following TO THE END OF THE LINE :

Code: Select all

 fbcon=map:10
so all of the options are one 1 single line.

5..Reboot the Pi

Code: Select all

sudo reboot
When the Pi reboots the screen will go from white to black - the display has been successfully initialised and boot-up text will appear on the display.

6..To configure the touch panel
In order to use the touch panel with python, X, and to calibrate it, a few packages need loading :

Code: Select all

sudo apt-get update
sudo apt-get install libts-bin evtest xinput python-dev python-pip -y
Then use pip to install evdev :

Code: Select all

sudo pip install evdev
To calibrate the touch panel :

Code: Select all

sudo TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/event0 ts_calibrate
Use a stylus (or a pencil!) to select each point in turn.
Note that if you have other input devices, ie keyboard and/or mouse, /dev/input/event0 may be, for example /dev/input/event1 or /dev/input/event2 or /dev/input/event3, etc.

7..Note that there is an issue with an unstable cursor with pygame and Jessie. A fix (working as of 10/03/2016) is detailed here :
viewtopic.php?f=32&t=131889&p=925861#p925861


Here is a test python program than uses pygame :

Code: Select all

#!/usr/bin/python
# touchv6
# Texy 5/12/13

import pygame, sys, os, time
from pygame.locals import *

from evdev import InputDevice, list_devices
devices = map(InputDevice, list_devices())
eventX=""
for dev in devices:
    if dev.name == "ADS7846 Touchscreen":
        eventX = dev.fn
print eventX

os.environ["SDL_FBDEV"] = "/dev/fb1"
os.environ["SDL_MOUSEDRV"] = "TSLIB"
os.environ["SDL_MOUSEDEV"] = eventX

pygame.init()

# set up the window
screen = pygame.display.set_mode((320, 240), 0, 32)
pygame.display.set_caption('Drawing')

# set up the colors
BLACK = (  0,   0,   0)
WHITE = (255, 255, 255)
RED   = (255,   0,   0)
GREEN = (  0, 255,   0)
BLUE  = (  0,   0, 255)
CYAN  = (  0, 255, 255)
MAGENTA=(255,   0, 255)
YELLOW =(255, 255,   0)

# Fill background
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill(WHITE)
box = pygame.draw.rect(background, YELLOW,(40, 0, 40, 240))
box = pygame.draw.rect(background,  CYAN, (80, 0, 40, 240))
box = pygame.draw.rect(background, GREEN, (120, 0, 40, 240))
box = pygame.draw.rect(background,MAGENTA,(160, 0, 40, 240))
box = pygame.draw.rect(background, RED,   (200, 0, 40, 240))
box = pygame.draw.rect(background, BLUE  ,(240, 0, 40, 240))
box = pygame.draw.rect(background, BLACK ,(280, 0, 40, 240))

# Display some text
font = pygame.font.Font(None, 36)
text = font.render("Touch here to quit", 1, (BLACK))
#text = pygame.transform.rotate(text,270)
textpos = text.get_rect(centerx=background.get_width()/2,centery=background.get_height()/2)
background.blit(text, textpos)

screen.blit(background, (0, 0))
pygame.display.flip()

running = True
# run the game loop
while running:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
            running = False
        elif event.type == pygame.MOUSEBUTTONDOWN:
            print("Pos: %sx%s\n" % pygame.mouse.get_pos())
            if textpos.collidepoint(pygame.mouse.get_pos()):
                pygame.quit()
                sys.exit()
                running = False
        elif event.type == KEYDOWN and event.key == K_ESCAPE:
            running = False
    pygame.display.update()
Copy and paste using nano, eg :

Code: Select all

sudo nano touchv6.py
Then to run the program use

Code: Select all

sudo python touchv6.py
8..Using the display with X Windows
In order to use the display or a HDMI screen the 99-fbturbo.conf file can be modified using

Code: Select all

sudo nano /usr/share/X11/xorg.conf.d/99-fbturbo.conf
to become like this :

Code: Select all

# FBTFT xorg config file
#
# startx -- -layout TFT
# startx -- -layout HDMI
#
# startx
# When -layout is not set, the first is used: TFT
#

Section "ServerLayout"
    Identifier "TFT"
    Screen 0 "ScreenTFT"
EndSection

Section "ServerLayout"
    Identifier "HDMI"
    Screen 0 "ScreenHDMI"
EndSection

Section "Screen"
    Identifier "ScreenHDMI"
    Monitor "MonitorHDMI"
    Device "DeviceHDMI"
Endsection

Section "Screen"
    Identifier "ScreenTFT"
    Monitor "MonitorTFT"
    Device "DeviceTFT"
Endsection

Section "Monitor"
    Identifier "MonitorHDMI"
Endsection

Section "Monitor"
    Identifier "MonitorTFT"
Endsection

Section "Device"
    Identifier "DeviceHDMI"
    Driver "fbturbo"
    Option "fbdev" "/dev/fb0"
    Option "SwapbuffersWait" "true"
EndSection

Section "Device"
    Identifier "DeviceTFT"
    Option "fbdev" "/dev/fb1"
EndSection
This means you can just use the usual

Code: Select all

startx
command to run X whether you have the display board fitted or not.

9..The touch panel needs configuring and calibrating for X use.
install :

Code: Select all

cd /tmp
wget http://tronnes.org/downloads/xinput-calibrator_0.7.5-1_armhf.deb
sudo dpkg -i -B xinput-calibrator_0.7.5-1_armhf.deb
rm xinput-calibrator_0.7.5-1_armhf.deb
10..As X/Y axis are swapped on this display, a touch panel config file needs creating.

Code: Select all

sudo mkdir /etc/X11/xorg.conf.d/
sudo nano /etc/X11/xorg.conf.d/99-ads7846-cal.conf
and add the following section.

Code: Select all

Section "InputClass"
        Identifier      "calibration"
        MatchProduct    "ADS7846 Touchscreen"
        Option  "SwapAxes"      "1"
EndSection
11..Configure xinput-calibrator to autostart with X windows.

Code: Select all

sudo wget -O /etc/X11/Xsession.d/xinput_calibrator_pointercal https://raw.github.com/tias/xinput_calibrator/master/scripts/xinput_calibrator_pointercal.sh
echo "sudo /bin/sh /etc/X11/Xsession.d/xinput_calibrator_pointercal" | sudo tee -a /etc/xdg/lxsession/LXDE-pi/autostart
Now start X with

Code: Select all

startx
On first start of X windows a calibration window will be displayed. Delete

Code: Select all

/etc/pointercal.xinput
to recalibrate.

Note all of the instructions in this post assume you wish to use the display/touch panel in landscape mode, with the hdmi connector at the top as you look at the pi/shield.
Of course, there are 3 other orientations possible, so notro's github page for further information - https://github.com/notro/fbtft/wiki

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

User avatar
4drq
Posts: 3
Joined: Tue Mar 19, 2013 8:00 am

Re: 2.8" TFT + Touch Shield Board v4

Thu Apr 02, 2015 8:35 pm

As always an excellent guide. Thank you texy!
Greetings from Leipzig, Germany
4drq

bigme666
Posts: 1
Joined: Sat Apr 04, 2015 9:05 pm

Re: 2.8" TFT + Touch Shield Board v4

Sat Apr 04, 2015 9:08 pm

I tried the above to install my brand new 2.8TFT touch shield to my Raspberry P1 model and this does not seem to work.
After step 5 my screen is still white and nothing appears on it.
I'm using the latest raspbian image dated 2015-02-16.
Please help.

texy
Forum Moderator
Forum Moderator
Posts: 5174
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: 2.8" TFT + Touch Shield Board v4

Sat Apr 04, 2015 10:55 pm

bigme666 wrote:I tried the above to install my brand new 2.8TFT touch shield to my Raspberry P1 model and this does not seem to work.
After step 5 my screen is still white and nothing appears on it.
I'm using the latest raspbian image dated 2015-02-16.
Please help.

Hi
Which display board do you have? This instrustions here are specifically for v4 of the displays I supply.
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

workhouse
Posts: 1
Joined: Thu Feb 12, 2015 7:12 pm

Re: 2.8" TFT + Touch Shield Board v4

Sun May 10, 2015 9:57 am

hi texy - there's nothing after "for sale here:" - are you still selling those boards somewhere?

texy
Forum Moderator
Forum Moderator
Posts: 5174
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: 2.8" TFT + Touch Shield Board v4

Sun May 10, 2015 11:06 am

workhouse wrote:hi texy - there's nothing after "for sale here:" - are you still selling those boards somewhere?
Ah -good point, I missed that :o
I have some for sale on eBay, but you can contact me directly via pm here.
Thanks,
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

Claus72
Posts: 6
Joined: Sat Jul 05, 2014 2:24 pm

Re: 2.8" TFT + Touch Shield Board v4

Sun May 24, 2015 1:22 pm

Thanks so much for the detailed istructions.
My tft is working very well.
How can I turn off backlight in terminal mode after 5 minute?

texy
Forum Moderator
Forum Moderator
Posts: 5174
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: 2.8" TFT + Touch Shield Board v4

Sun May 24, 2015 4:26 pm

Claus72 wrote:Thanks so much for the detailed istructions.
My tft is working very well.
How can I turn off backlight in terminal mode after 5 minute?

Hi
Try this :
viewtopic.php?f=45&t=64993&p=494111#p494111
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

Claus72
Posts: 6
Joined: Sat Jul 05, 2014 2:24 pm

Re: 2.8" TFT + Touch Shield Board v4

Sun May 24, 2015 5:04 pm

Thank you for your quick answer but I have already tried to change BLANK_TIME in /etc/kbd/config with 2 minutes.
After 2 minutes the tft goes black but with backlight on and I would like backlight be off.

texy
Forum Moderator
Forum Moderator
Posts: 5174
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: 2.8" TFT + Touch Shield Board v4

Sun May 24, 2015 6:48 pm

Can you manually turn off the backlight using the code in that post?
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

Claus72
Posts: 6
Joined: Sat Jul 05, 2014 2:24 pm

Re: 2.8" TFT + Touch Shield Board v4

Sun May 24, 2015 7:48 pm

texy wrote:Can you manually turn off the backlight using the code in that post?
Yes, manually I can turn off and on with the code in the post.

texy
Forum Moderator
Forum Moderator
Posts: 5174
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: 2.8" TFT + Touch Shield Board v4

Tue May 26, 2015 11:35 am

Hi,
sorry I do not know a way of doing this. Perhaps there is a way of checking that the screen blanking has been activated, and then toggle the GPIO pin if True (and visa versa).
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

Cerin
Posts: 11
Joined: Sat Aug 15, 2015 2:28 pm

Re: 2.8" TFT + Touch Shield Board v4

Mon Aug 24, 2015 1:36 pm

texy wrote:"2.8inch TFT LCD + Touch screen" add-on boards for sale here :
viewtopic.php?f=45&t=105797
It's odd that you'd put this in your signature, yet mention no way to buy these in this entire thread.

texy
Forum Moderator
Forum Moderator
Posts: 5174
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: 2.8" TFT + Touch Shield Board v4

Mon Aug 24, 2015 2:27 pm

Cerin wrote:
texy wrote:"2.8inch TFT LCD + Touch screen" add-on boards for sale here :
viewtopic.php?f=45&t=105797
It's odd that you'd put this in your signature, yet mention no way to buy these in this entire thread.
Very observant ;)
PM works well however.....

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

fredaunger
Posts: 20
Joined: Wed May 14, 2014 6:24 pm

Re: 2.8" TFT + Touch Shield Board v4

Sun Nov 01, 2015 4:18 pm

Hi Texy,
I am trying to configure my 2.8 touch screen but it does not seem to work. I noticed yur coment that the procedure was for v4 boards I have a v2 ie Pi TFT 28 Shield V2b 2014 is there a different setup.
I have gone through the set up and get a black screen but nothing appears on it? Could you please advise.
Fred Aunger

texy
Forum Moderator
Forum Moderator
Posts: 5174
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: 2.8" TFT + Touch Shield Board v4

Mon Nov 02, 2015 8:39 am

Hi Fred,
yes your v2 board uses the same HY28B display that the v4 uses, so the instructions are the same, however there is no longer a need to do step 2 as fbtft is already incorporated into the latest image. You are using the latest jesse raspbian image?

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

fredaunger
Posts: 20
Joined: Wed May 14, 2014 6:24 pm

Re: 2.8" TFT + Touch Shield Board v4

Tue Nov 03, 2015 7:08 pm

Hi, thanks for the prompt reply I muusrt have done something wrong. I am using an original A board with ethernet and the latest release of Jessie..
Will try the upgrade again
Regards
Fred Aunger

fredaunger
Posts: 20
Joined: Wed May 14, 2014 6:24 pm

Re: 2.8" TFT + Touch Shield Board v4

Thu Nov 05, 2015 4:21 pm

Hi Texy,
Sorry to bother you again, I have redone the instructions, but still seem to have a problem (silly me).The pi boots to the screen but seems to stop displaying with the cursor in the top left of the screen it continues to boot( I assume) and I am able to SSH into it. I have done the touch screen validation and it seems ok. Have you any advise as to what I am doing wrong.
Regards
Fred Aunger

texy
Forum Moderator
Forum Moderator
Posts: 5174
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: 2.8" TFT + Touch Shield Board v4

Thu Nov 05, 2015 5:13 pm

You don't have a hdmi display connected also?
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

fredaunger
Posts: 20
Joined: Wed May 14, 2014 6:24 pm

Re: 2.8" TFT + Touch Shield Board v4

Sat Nov 07, 2015 9:49 am

Hi Texy,

No i disconnected the hdmi connector before doing a reboot. As an experiment I did a reboot with the hdmi cable connected and the boot was the same except when the cursor stopped at the top of the touch screen, the pi continued is boot and presented the home screen on the hdmi telly.
Bit of a loss as to what to do?
Fred Aunger

fredaunger
Posts: 20
Joined: Wed May 14, 2014 6:24 pm

Re: 2.8" TFT + Touch Shield Board v4

Sun Nov 08, 2015 3:29 pm

Hi Texy
Just an update, I have tried the update using latest raspi and have the same result(as using Jessie). On close inspection on boot it appears to address the touch screen until it reaches the point of processing the user GUI at this point it seems to send the GUI info to the HDMI output and finishes ok. I am able at this point to use putty and connect to the pi. Wonder if this is any clue as to what is happening?
Regards
Fred Aunger

texy
Forum Moderator
Forum Moderator
Posts: 5174
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: 2.8" TFT + Touch Shield Board v4

Sun Nov 08, 2015 7:23 pm

fredaunger wrote:Hi Texy
Just an update, I have tried the update using latest raspi and have the same result(as using Jessie). On close inspection on boot it appears to address the touch screen until it reaches the point of processing the user GUI at this point it seems to send the GUI info to the HDMI output and finishes ok. I am able at this point to use putty and connect to the pi. Wonder if this is any clue as to what is happening?
Regards
Fred Aunger
Hi Fred,
yes that could well be a clue. I have spent some time on this today, and can confirm I get the same as you with a Pi B. Using the same uSD card in a Pi2B works as it should. Seems there is an issue with the Jessie/FBTFT/Pi B combination - redirection to /dev/fb1/ is taking place during boot, but then re-diverts to /dev/fb0 later on.
Can you please raise this as an issue to notro, the author of fbtft here :
https://github.com/notro/fbtft/issues/

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

fredaunger
Posts: 20
Joined: Wed May 14, 2014 6:24 pm

Re: 2.8" TFT + Touch Shield Board v4

Wed Nov 11, 2015 2:57 pm

Hi Texy,

I have raised the matter as you requested with Gthub and am awaiting a reply.

A further detailed look at the boot sequence and It starts booting to HDMI then switches to the 2.8 screen and then when it processes the user GUI information it again switches back to HDMI to finish.

Just a little more info

Regards
Fred Aunger.

texy
Forum Moderator
Forum Moderator
Posts: 5174
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: 2.8" TFT + Touch Shield Board v4

Sun Nov 22, 2015 11:25 am

Apologies for the delay, but I believe I have found the issue. By default now the Raspbian image boots to desktop. If you SSH into your Pi, run

Code: Select all

sudo raspi-config
select Boot Options, and either B1, or B2 to boot to Console, reboot, and your pi should behave as you want it too.
Hope this helps,
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

fredaunger
Posts: 20
Joined: Wed May 14, 2014 6:24 pm

Re: 2.8" TFT + Touch Shield Board v4

Fri Nov 27, 2015 8:18 pm

Hi Texy,
I am using an early Raspberry Pi board model A with 256 meg ram. The additional info does not work. Just the same old same old switching. Is it possible that these early boards are not compatible with these software mods. Will try with my other pi with 512 meg and see if that works.
Regards
Fred Aunger

Return to “HATs and other add-ons”