AndyPi’s latest product is a miniature colour graphic TFT display, 2.2″ wide with 320×240 pixels (we also have a small number of 1.8″ TFT’s at a bargain price) The sky is the limit as to what you could use this for – its more flexible that our HD44780 LCDs, but a little more complicated to set up (only a little!). The drivers have been designed by Raspberry Pi forum member notro (see details here) and other instruction are available on the forums, but you’ll also find full (well… currently under construction) step by step set of instructions here on the following topics:

1. Physical connections to the Raspberry Pi GPIO
2. Setting up with Raspbian (Command line)
3. Setting up with Raspbian (X windows)
4. Playing a movie clip
5. Viewing an image file
6. Drawing graphics directly to the TFT display with PyGame
7. Graphing your data with python
8. Setting up with RASPBMC (media centre) / Using the TFT in combination with the official RaspberryPi camera

These instructions assume you have an internet connection set up already…

 

AndyPi 320×240 TFT display kit details:

1. 2.2″ 320×240 pixel TFT (or 1.8″ 168×120 Pixel TFT) with 4 mounting holes
2. PCB header pins pre-soldered
3. 9-way cable for GPIO & power connection; leaves other pins free, and gives 20 cm cable length to position the display in different case shapes to your own preference.

 

1. Physical connections to the Raspberry Pi GPIO

1.8” TFT Display

(Alternative name)

Raspberry Pi

Raspberry Pi Pin number

Rev 2 Board (Rev 1 Board )

GND

GND

6

VCC

3.3V

1

RESET (RS)

GPIO25

22

A0 (D/C)

GPIO24

18

SDA (DIN)

MOSI

19

SCK (CLK)

SCLK

23

CS

CE0

24

LED+ (BL)

3.3V

17 (2)

LED- (not required on all models)

GND

9

(6 – requires soldering to the other ground wire – Rev 1 only)

 

2.2″ TFT Display

Raspberry Pi

Raspberry Pi Pin number

Rev 1 & 2 Board (Rev 1 Board )

SDO (MISO)

GPIO 09

21

LED

GPIO 18

12

SCK

GPIO 11

23

SDI (MOSI)

GPIO 10

19

D/C

GPIO 24

18

RESET

GPIO 25

22

CS

GPIO 08

24

GND

GND

6

VCC

+3v3

1

IMG_0934

2. Setting up with Raspbian

[Update May 2016] The instructions below are a little outdated, please use these here: https://github.com/notro/fbtft/wiki

You may still need to take account of the pin numbering in the modules file.

 

A. Download fresh image of the latest version of Raspbian (tested with 2015-02-16 by Notro with the FBTFT drivers available as loadable modules. (2014-06-20-wheezy-raspbian-2014-07-25-fbtft-master-firmware.zip) https://github.com/notro/fbtft/wiki#image-download).

Write this image to your SD card, and the SSH into your Pi from another computer so you can complete the setup. There are further details on this page which are worth checking out. You then need to update the kernel, which now includes the TFT drivers as standard:

sudo rpi-update

B. On the first boot, setup locales, your timezone and enable the camera using the config program (sudo raspi-config).

C. We need the module to load at start-up, so add the fbtft device to /etc/modules:

sudo nano /etc/modules
add this new line at the endfbtft_device custom name=fb_ili9341 gpios=reset:25,dc:24,led:18 speed=16000000 bgr=1 rotate=270 (for 2.2″ screen, or  name=adafruit22a)
or add this new line at the end: fbtft_device name=sainsmart18 rotate=270 (for 1.8″ screen)

D. We need to confirm we’re using the fbtft device module:

sudo nano /boot/config.txt
add the following at the bottom of the file:
dtparam=spi=on

E. Next set the the console to use the framebuffer by editing /boot/cmdline.txt:

sudo nano /boot/cmdline.txt
add the following at the end of the line (NOTE: not on a new line!):
fbcon=map:10 fbcon=rotate:4 fbcon=font:VGA8x8
(use MINI4×6 on 1.8” screen is better size font)

It’s worth knowing that the screen will go blank after 30 minutes to protect it, if there has been no activity on it (actually important on these small TFTs). Check out this information if you need to change it.

F. If you restart your Pi, you should now have the console viewable on the mini-TFT!

 

3. Setting up with Raspbian (X windows)

Once you’ve completed step 2 above, you can also use X-windows (although the display is small, but you may find a use for it):

sudo FRAMEBUFFER=/dev/fb1 startx

NOTE (25/112015): This command is not working on latest versions of Raspbian as it hardwires x to use fb0. Please see this page for tips on how to edit your settings to get displaying on the TFT.
4. Playing a movie clip
Install the mplayer program which can play movies:

sudo apt-get install mplayer

Play the movie, (you need one less than 320×240 (168×120 for 1.8″):

mplayer -vo fbdev2:/dev/fb1 yourmoviefile.mp4

And to stop the video: Ctrl-C

It’s better to resize any video you want to play in advance (with ffmpeg or freemake video converter), you can look at the mplayer options to resize on the fly (mplayer -vo fbdev2:/dev/fb1 -x 320 -y 240 -vf -zoom yourmoviefile.mp4), but the raspeberry pi is not powerful enough to handle it, so your video will play too slowly.

 

5. Viewing an image file

Install fbi, a command line picture viewer:

sudo apt-get install fbi

Get the picture you want to display (your need to rotate it to the correct orientation with an editor first), and then use the following command:

fbi -d /dev/fb1 -T 1 -noverbose -a your_pic.jpg

If you want to view a slideshow of images in the current directory, using *.jpg as the filename

sudo fbi -d /dev/fb1 -T 1 -a -noverbose -t 1 *.jpg

and to stop it: sudo pkill fbi

 

6. Drawing graphics directly to the TFT display with PyGame

Download this python script to your Pi, and run it

sudo wget http://download.andypi.co.uk/pygame_test.py

sudo python pygame_test.py

And to stop the script: Ctrl-C

You can edit the script using nano – check out the pygame website for instructions for how to draw other shapes!

7. Graphing your data with python

I’ve created a python class to help easily graph you data and display it on the AndyPi TFT.

You’ll need to download this class AndyPiPlot.py, and install python & python-setuptools python-matplotlib and python-scipy (use pip).

You’ll be able to make a scatter plot, a single line plot and a plot with 2 lines and a legend (see example below), and set up all the axes and titles etc. You can load the data from csv files (using the readData function in the AndyPiPlot class), or directly put in the variables for your script.

Download these example data and use script to check out how to use it – the comments explain in more detail! [sample.csv, sample2.csv, usetest.py]

 

tft

 

8. Setting up with RASPBMC (media centre) / Using the TFT in combination with the official RaspberryPi camera

Coming soon!

https://raw.githubusercontent.com/t $ https://raw.githubusercontent.com/Hexxeh/rpi-update/master/