UPDATED 29/03/2015
Update - fbtft has now been included in the latest raspbian image and uses Device Tree - see this thread on how to configure the very latest raspbian os
http://www.raspberrypi.org/forums/viewt ... 5&t=105797
UPDATED 23/09/2014
The extremely talented notro has beening working hard to produce a raspbian based image that has the drivers built into the kernel.
This means that the console output goes to the TFT display much sooner into the boot sequence. Also he has created a ready-made image for you to download so that you do not need to go through the configuration procedure below

The image came be downloaded from here :
http://tronnes.org/downloads/2014-06-20 ... -hy28b.zip
Notes and further setup details can be found here :
https://github.com/notro/fbtft-spindle/wiki/FBTFT-image
Slightly updated python test program (remember to run sudo ts_calibrate before running :
sudo TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/event0 ts_calibrate) :
Code: Select all
#!/usr/bin/python
# touchv7
# Texy 5/2/2014
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()
As always many thanks to Notro for the excellent fbtft drivers, without which these products would not exist.
This new version 2 board was required because the original HY28A display has been discontinued and replaced by the HY28B. Although no major performance improvements exist, it is wired differently, so required a new pcb layout. The display board now uses the ili9325 control chip and also the touch panel is mounted 180 degrees out compared to the HY28A.
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.
It is recommended to use the latest raspbian image of 2013-12-20.
# Expand root filesystem
Code: Select all
sudo raspi-config
Code: Select all
sudo nano /etc/modprobe.d/raspi-blacklist.conf
Code: Select all
#blacklist spi-bcm2708
Code: Select all
sudo wget https://raw.github.com/Hexxeh/rpi-update/master/rpi-update -O /usr/bin/rpi-update && sudo chmod +x /usr/bin/rpi-update
# Issue: https://github.com/Hexxeh/rpi-update/issues/106
Code: Select all
sudo mv /lib/modules/$(uname -r) /lib/modules/$(uname -r).bak
Code: Select all
sudo REPO_URI=https://github.com/notro/rpi-firmware rpi-update
sudo shutdown -r now
Code: Select all
sudo modprobe fbtft dma
sudo modprobe fbtft_device name=hy28b rotate=90
Then to configure the touch panel
Code: Select all
sudo modprobe ads7846_device pressure_max=255 y_min=190 y_max=3850 gpio_pendown=17 x_max=3850 x_min=230 x_plate_ohms=100 swap_xy=1 verbose=3
Code: Select all
sudo nano /etc/modules
Code: Select all
fbtft dma
fbtft_device name=hy28b rotate=90
ads7846_device pressure_max=255 y_min=190 y_max=3850 gpio_pendown=17 x_max=3850 x_min=230 x_plate_ohms=100 swap_xy=1 verbose=3
Code: Select all
[ 13.256262] fbtft_device: SPI devices registered:
[ 13.262834] fbtft_device: spidev spi0.0 500kHz 8 bits mode=0x00
[ 13.271064] fbtft_device: spidev spi0.1 500kHz 8 bits mode=0x00
[ 13.279202] fbtft_device: 'fb' Platform devices registered:
[ 13.286533] fbtft_device: bcm2708_fb id=-1 pdata? no
[ 13.293632] fbtft_device: Deleting spi0.0
[ 13.302483] fbtft_device: GPIOS used by 'hy28b':
[ 13.323198] fbtft_device: 'reset' = GPIO25
[ 13.329223] fbtft_device: 'led' = GPIO18
[ 13.343131] fbtft_device: SPI devices registered:
[ 13.349540] fbtft_device: spidev spi0.1 500kHz 8 bits mode=0x00
[ 13.373288] fbtft_device: fb_ili9325 spi0.0 48000kHz 8 bits mode=0x03
[ 13.547463]
[ 13.547463]
[ 13.547463] ads7846_device: ads7846_device_init()
[ 13.573097] ads7846_device: SPI devices registered:
[ 13.579447] ads7846_device: spidev spi0.1 500kHz 8 bits mode=0x00
[ 13.603051] ads7846_device: fb_ili9325 spi0.0 48000kHz 8 bits mode=0x03
[ 13.611323] ads7846_device:
[ 13.633024] ads7846_device: Settings:
[ 13.638027] ads7846_device: model = 7846
[ 13.653035] ads7846_device: gpio_pendown = 17
[ 13.658833] ads7846_device: swap_xy = 1
[ 13.673041] ads7846_device: x_min = 230
[ 13.678301] ads7846_device: x_max = 3850
[ 13.693042] ads7846_device: y_min = 190
[ 13.698259] ads7846_device: y_max = 3850
[ 13.713035] ads7846_device: x_plate_ohms = 100
[ 13.718840] ads7846_device: pressure_min = 0
[ 13.733041] ads7846_device: pressure_max = 255
[ 13.738817] ads7846_device: keep_vref_on = 1
[ 13.763023] ads7846_device: vref_delay_usecs = 0
[ 13.768933] ads7846_device: vref_mv = 0
[ 13.782789] ads7846_device: settle_delay_usecs = 0
[ 13.791975] ads7846_device: penirq_recheck_delay_usecs = 0
[ 13.810204] ads7846_device: y_plate_ohms = 0
[ 13.823074] ads7846_device: debounce_max = 0
[ 13.828615] ads7846_device: debounce_tol = 0
[ 13.853057] ads7846_device: debounce_rep = 0
[ 13.858615] ads7846_device: Deleting spi0.1
[ 13.873570] ads7846_device: SPI devices registered:
[ 13.879570] ads7846_device: fb_ili9325 spi0.0 48000kHz 8 bits mode=0x03
[ 13.903090] ads7846_device: ads7846 spi0.1 2000kHz 8 bits mode=0x00
[ 13.910789] ads7846_device:
[ 14.567335] graphics fb1: fb_ili9325 frame buffer, 320x240, 150 KiB video mem ory, 4 KiB DMA buffer memory, fps=50, spi0.0 at 48 MHz
[ 14.604318] ads7846 spi0.1: touchscreen, irq 187
[ 14.648385] input: ADS7846 Touchscreen as /devices/platform/bcm2708_spi.0/spi _master/spi0/spi0.1/input/input0
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.
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


With this configuration, the screen has been rotated for landscape use. In order to use the touch panel with X, the touch panel input also needs rotating.
Do this by
Code: Select all
sudo nano /etc/X11/xinit/xinitrc
Code: Select all
DISPLAY=:0 xinput --set-prop 'ADS7846 Touchscreen' 'Evdev Axis Inversion' 0 0
Code: Select all
sudo nano /usr/share/X11/xorg.conf.d/99-fbturbo.conf
Code: Select all
Option "fbdev" "/dev/fb0"
This allows X11 to be used with, or without the TFT display.
Then to run X use
Code: Select all
FRAMEBUFFER=/dev/fb1 startx -- -dpi 60
Code: Select all
sudo nano /boot/cmdline.txt
Code: Select all
fbcon=map:10 fbcon=font:VGA8x8
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
Much more information and discussion can be found in this thread : http://www.raspberrypi.org/phpBB3/viewt ... 64&t=34007
Many thanks again to Notro for the drivers, and also Andybiker for the inspiration

NOTE THAT APT-GET UPGRADE WILL BREAK THE DRIVERS - SO USE THE FOLLOWING PROCEDURE TO UPDATE THE SYSTEM :
Code: Select all
sudo apt-mark hold raspberrypi-bootloader
sudo apt-get update
sudo apt-get upgrade
Code: Select all
sudo REPO_URI=https://github.com/notro/rpi-firmware rpi-update
Texy