The 1.8″ TFT from Adafruit is the perfect display to attached to a Raspberry Pi.
These instructions also help with the Sainsmart display and you can find more info for both here: http://www.whence.com/rpi/
The TFT isn’t ‘plug & play’ with the Raspberry, a patch has to be applied to the kernel to be able to interface via SPI with the ST7735R controller chip on the TFT. Once working, the display will act as a framebuffer device.
I spent two weeks trying to get it working, so I thought I would document it to help others.
1.8TFT Kernel (36.2 MiB)
###UPDATE 14th Nov 2013###
After a large number of request, I have now posted the compiled version of the kernel that supports the 1.8” TFT. Based on 2013-09-25-wheezy-raspbian.img. There are two links below, one for the Kernel the other is the instructions.
README1.8TFT Kernel 3.6.11 Tar (654.0 B)
Thanks go to Kamal (http://www.whence.com/rpi/) and Neil for responding to my emails & forum post, and their work on the ST7735R driver.
Thanks also go to Adafruit for their cool products.
As it takes over three hours to compile the kernel on the PI, I will show how to cross compile from another Linux PC. In my case, it is Ubuntu 12.10 running within VMWare on a Windows 7 Quad core PC. Kernel compile time is 15 mins.
Wire it up
Sainsmart wiring details are here on Kamal’s page: http://www.whence.com/rpi/
You could also use a shield to make the wiring a lot easier, look here
Prepare the Raspberry Pi
-Download and install Raspbian “wheezy”.
This guide is based on 2013-02-09-wheezy-raspbian which is running 3.6.11 kernel
-Configure your Pi. E.g. Memory split, overclocking, etc..
-Update firmware and reboot. I use Hexxeh’s script to update my firmware, which also needs GIT.
pi@raspberrypi ~ $ sudo apt-get update
pi@raspberrypi ~ $ sudo apt-get install git-core
pi@raspberrypi ~ $ sudo wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update
pi@raspberrypi ~ $ sudo chmod +x /usr/bin/rpi-update
pi@raspberrypi ~ $ sudo rpi-update
Compile the Kernel
We will be cross compiling the kernel as compiling a kernel on the Raspberry Pi takes forever.
-Install packages used for cross compiling on the Ubuntu box.
-Get Kamal’s source which has the patch for ST7735R controller and the branch for the kernel that is used in 2013-02-09-wheezy-raspbian, which is 3.6.y;
mark@ubuntu~$ cd raspberrypi-linux
mark@ubuntu~$ git checkout rpi-3.6.y+kamal-st7735fb
-Grab the current config off the Raspberry Pi.
-Copy config from the Raspberry Pi to the Ubuntu box using SCP. Replace ‘raspberrypi’ below with the IP address of your Raspberry Pi if hostname lookup fails.
We will then rename it once it is on the Ubuntu box
mark@ubuntu~/raspberrypi-linux$ mv config .config
-Configure .config to include the new patch and options.
You will be asked some questions for the new driver. If you are unsure of what values to use, then use these;
BCM2708 SPI controller driver (SPI0) (SPI_BCM2708) [N/m/y/?] (NEW) Y
ST7735 framebuffer support (FB_ST7735) [N/m/y/?] (NEW) Y
ST7735 ‘red tab’ panel type? (FB_ST7735_PANEL_TYPE_RED_TAB) [Y/n/?] (NEW) Y
ST7735 panel has reversed RGB? (FB_ST7735_RGB_ORDER_REVERSED) [N/y/?] (NEW) N (or Y if red and blue are reversed)
ST7735 framebuffer mapping to GPIO/SPI (FB_ST7735_MAP) [Y/n/m/?] (NEW) Y
ST7735 RST gpio pin number (FB_ST7735_MAP_RST_GPIO) [-1] (NEW) 25
ST7735 D/C gpio pin number (FB_ST7735_MAP_DC_GPIO) [-1] (NEW) 24
ST7735 SPI bus number (FB_ST7735_MAP_SPI_BUS_NUM)  (NEW) 0
ST7735 SPI bus chipselect (FB_ST7735_MAP_SPI_BUS_CS)  (NEW) 0
ST7735 SPI bus clock speed (Hz) (FB_ST7735_MAP_SPI_BUS_SPEED)  (NEW) 4000000 (or 32000000 for SainSmart)
ST7735 SPI bus mode (0, 1, 2, or 3) (FB_ST7735_MAP_SPI_BUS_MODE)  (NEW) 0
You will need to confirm that “BCM2708 SPI controller driver” is set to Y;
If the above result is N or M, you will need to edit .config and change it to Y.
If you are planning on displaying the console on the TFT, then enabling these options in .config will allow you to change the font size and rotate the display later on.
-Now compile the kernel.
To enable parallel processing for a faster compile. If you have a dual core processor add -j 3 to the end of the command below. If you have quad core, add -j 6
-Create modules on the Ubuntu box which we will copy over later.
mark@ubuntu:~/raspberrypi-linux$ sudo make modules_install ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- INSTALL_MOD_PATH=../modules/
-Copy the new kernel over to the Raspberry Pi
pi@raspberrypi ~ $ sudo cp Image /boot/kernel.img
-Now copy over the new modules. First remove the unneeded directories, otherwise you will be copying over 1.9GB
The last step below is to SCP the files from from Ubuntu to the Raspberry Pi. If you have trouble SCPing into your Ubuntu box you may need to install open SSH on Ubuntu with sudo apt-get install openssh-server. This step also copies the files from my home folder ‘mark’… yours would be different.
mark@ubuntu:~/raspberrypi-linux$ sudo rm -f -r ../modules/lib/modules/3.6.11+/source
pi@raspberrypi ~ $ sudo rm -f -r /lib/modules
pi@raspberrypi ~ $ sudo rm -f -r /lib/firmware
pi@raspberrypi ~ $ sudo scp -r mark@ubuntu:/home/mark/modules/lib /
If everything went well, you should now have /dev/fb1.
Displaying the console on the TFT;
If you build the st7735 driver pair as built-in, add these options to the end of the line in
/boot/cmdline.txt. This will display the console on the TFT.
Some programs that work with framebuffer devices
mplayer2 = video playback
pi@raspberrypi ~ $sudo mplayer -vo fbdev2:/dev/fb1 -x 128 -y 160 -zoom file
FBI = image viewer
Links2 = web browser
Links2 uses directfb to speak to the TFT. And we need to configure directfb with our TFT details.
-Add these lines to the end of the file
geometry 128 160 128 160 16
timings 0 0 0 0 0 0 0
-Update /etc/directfbrc. If the file doesn’t exist, create it.
-Add these lines to the end of the file
pi@raspberrypi ~ $sudo links2 -g -mode 128x160x32k www.google.com
Start Xwindows with;