[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
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
Code: Select all
dtoverlay=hy28b,rotate=90
Code: Select all
sudo dpkg-reconfigure console-setup
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
Code: Select all
fbcon=map:10
5..Reboot the Pi
Code: Select all
sudo reboot
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
Code: Select all
sudo pip install evdev
Code: Select all
sudo TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/event0 ts_calibrate
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()
Code: Select all
sudo nano touchv6.py
Code: Select all
sudo python touchv6.py
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
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
Code: Select all
startx
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
Code: Select all
sudo mkdir /etc/X11/xorg.conf.d/
sudo nano /etc/X11/xorg.conf.d/99-ads7846-cal.conf
Code: Select all
Section "InputClass"
Identifier "calibration"
MatchProduct "ADS7846 Touchscreen"
Option "SwapAxes" "1"
EndSection
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
Code: Select all
startx
Code: Select all
/etc/pointercal.xinput
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