Connecting 1.8″ TFT LCD to Raspberry Pi

Some time ago I stumbled over a little TFT LCD from SainSmart (link) and since it was lying next to a Raspberry Pi stack I decided to buy it. Ever since it was just sitting on my shelf waiting to be used whilst I do my doctorate. But now I found a free night and a free morning in my busy schedule. So I decided to try and connect it to one of my Raspberries and I must say, I got it to work rather quickly (roughly 5h).

First of all, all of the kernel credit must go to Kamal Mostafa and his git repository, since it was him who made the drivers available. Throughout this little explanation I will detail how I acquired, configured, compiled and installed the raspberry-linux kernel. Once that’s done I will show you how I got my Raspberry Pi to use the screen as a video output.

First though, you will require a linux distribution to execute all of the commands. You can use an already set up Raspberry Pi, but compilation of the Kernel apparently takes around 5.5h. So unless you are willing to wait that long, you’re better of installing Ubuntu (it’s free and worked for me).  In my case I have a ubuntu server running on the IP and my Raspberry Pi on the IP My username on the server is root and on the Pi pi (of course these are not the actual credentials, but I list these so it becomes easier to follow the commands). So let’s get started.

Get the Kernel

To control the display you will need to recompile the Raspbian Kernel. But before you can do so you will need to install some programs on your linux distribution.

root@ubuntu1210: ~$ sudo apt-get update
root@ubuntu1210: ~$ sudo apt-get install gcc-arm-linux-gnueabi make git-core ncurses-dev

Next you need to download the Kernel’s source code. This is where you get Kamal Mostafa’s source, since he modified it for the SainSmart TFT LCD (ST7735R).

root@ubuntu1210: ~$ git clone git://

Once the download is complete, change into the directory raspberrypi-linux and check out the Kernel’s source.

root@ubuntu1210: ~$ cd raspberrypi-linux
root@ubuntu1210: ~/raspberrypi-linux$ git checkout rpi-3.6.y+kamal-st7735fb

Kernel configuration export

Now, you’ll need to switch to your Raspberry Pi and export its Kernel configurations. Since my linux distribution and your Raspberry Pi were connected as outlined above, I could simply ssh into my Pi and transfer the files to my linux distribution. In your case simply amend IPs, directories and usernames (incl. their passwords) to suit your setup. Nevertheless, you first need to connect to your Pi:

root@ubuntu1210: ~/raspberrypi-linux$ ssh pi@

Then export the Kernel’s configurations.

pi@raspberrypi ~ $ sudo zcat /proc/config.gz > config

And then transfer the config file directly to the server.

pi@raspberrypi ~ $ scp config root@

For now we are done with the Pi, so simply terminate the connection like so:

pi@raspberrypi ~ $ exit

Modify the Kernel

Back at the linux distribution, you then need to move (or copy if you want to have a backup) the config file into Kernel source code. Since you will have to rename the file to .config let’s do that at the same time:

root@ubuntu1210: ~/raspberrypi-linux$ mv ~/config ~/raspberrypi-linux/.config

To copy instead of move simply replace mv with cp.

Next you need to export the ST7735 Chip’s properties since they are missing in the original configurations file. This is done with the command make which we installed earlier.

root@ubuntu1210: ~/raspberrypi-linux$ make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- oldconfig

A lot of options will pop up and ask you how you want to setup the configurations. Simply hit enter (i.e. accept the default) for all of them, until you reach the configurations for the SainSmart module. Answer these questions as follows:

ST7735 LCD panel 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) y
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) [0] (NEW) 0
ST7735 SPI bus chipselect (FB_ST7735_MAP_SPI_BUS_CS) [0] (NEW) 0
ST7735 SPI bus clock speed (Hz) (FB_ST7735_MAP_SPI_BUS_SPEED) [4000000] (NEW) 32000000
ST7735 SPI bus mode (0, 1, 2, or 3) (FB_ST7735_MAP_SPI_BUS_MODE) [0] (NEW) 0

The configuration has now been enhanced with make, but you still need to do some manual changes. To do so, open the .config file with nano.

root@ubuntu1210: ~/raspberrypi-linux$ nano .config

Use ctrl+w to search strings in the file and look for CONFIG_SPI_BCM2708. Ensure this setting is set to yes i.e.:


Next search for the following configurations and change them accordingly. Initially they were commented out, so just search for the parameters names and change the rows to look like so:

<span style="line-height: 1.5em;">

Compile the Kernel

Now you are ready to compile the Kernel. As I said, doing this on a Pi will take more than 5.5h (even when overclocked). If you have a single core system then use the following command for compilation:

root@ubuntu1210: ~/raspberrypi-linux$ make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- -k

On a multicore system, you can append the -j flag to utilise as many resources as possible for compiling; hence speeding up the process. I have a dual-core server, so the command I used was:

root@ubuntu1210: ~/raspberrypi-linux$ make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- -k -j 3

If you have a quad-core system change the -j 3 to -j 5. And now wait… (It took me 17 minutes to compile)

Compile Kernel Modules

First create a directory for your modules.

root@ubuntu1210: ~/raspberrypi-linux$ mkdir ./modules

Then compile the modules into this directory.

root@ubuntu1210: ~/raspberrypi-linux$ make modules_install ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- INSTALL_MOD_PATH=./modules/

And then clean the directory by removing all temporary files.

root@ubuntu1210: ~/raspberrypi-linux$ rm -rf ./modules/lib/modules/3.6.11+/build ./modules/lib/modules/3.6.11+/source

Install the Kernel and its modules

Just like before, connect to your Raspberry Pi and delete the currently installed modules and firmware.

pi@raspberrypi ~ $ sudo rm -rf /lib/modules /lib/firmware

Then you need to copy the previously compiled modules ti your Pi. I did this just like before but instead of scping from my Pi to linux, I copied from linux to my Pi.

pi@raspberrypi ~ $ scp root@ /

And finally, copy over the compiled Kernel. This needs to be copied into the Raspberry’s boot directory.

pi@raspberrypi ~ $ scp root@ /boot/kernel.img

Load the Kernel

After having swapped the Kernel as well as its modules, a reboot is required to load them into your OS. When doing so (as you may expect) the connection to the Pi will be lost. Hence reconnect once the Pi rebooted. You can trigger a reboot with the following command.

pi@raspberrypi ~ $ sudo shutdown -t now

Once Raspbian has rebooted and you reconnected to your Pi, you can check whether the frame buffer device-files have been generated.

pi@raspberrypi ~ $ ls -la /dev/fb*
crw-rw---T 1 root video 29, 0 Jan 1 1970 /dev/fb0
crw-rw---T 1 root video 29, 1 Jan 1 1970 /dev/fb1

The hardware

Now it’s time to connect the SainSmart TFT LCD module to the Pi. I recommend you shut down the Pi before connecting the screen to avoid damaging the hardware. Then connect the screen as follows:


When you reboot the Pi you should see the standard 2×2 image like so:




Linux Terminal

To get a terminal output to your SinSmart 1.8″ TFT LCD module, you need to edit the cmdline.txt file of the raspberry. Either log in via ssh (like above) or modify the file on the SD-Card. I chose the former and did this:

pi@raspberrypi ~ $ nano /boot/cmdline.txt

At the end of the 1st (and only) line in this document you need to add the following parameters:

fbcon=map:10 fbcon=rotate:1 fbcon=font:ProFont6x11

The parameter rotate can be modified to adjust the screen rotation like so:

  • 0: Normal orientation
  • 1: 90° rotation
  • 2: 180° rotation
  • 3: 270° rotation

After you saved the file with ctrl+o you need to reboot the Pi with:

pi@raspberrypi ~ $ sudo shutdown -r now


Display graphics

First you need to update the Raspberry’s packages:

pi@raspberrypi ~ $ sudo apt-get update

Next, you can install the Linux frame-buffer image viewer:

pi@raspberrypi ~ $ sudo apt-get install fbi

And finally display a graphic of resolution 128×160 with the following command:

pi@raspberrypi ~ $ sudo fbi -noverbose -T 1 -a -d /dev/fb1 raspberry-test-image.jpg

The image I choose is this one:


And the result is:


Python clock

First you need to create a new Python script file.

pi@raspberrypi ~ $ nano

Then write the following lines into the file.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import time
import pygame


os.environ["SDL_FBDEV"] = "/dev/fb1"

def displaytext(text,size,line,color,clearscreen):
    if clearscreen:

    font = pygame.font.Font(None,size)
    text = font.render(text,0,color)
    rotated = pygame.transform.rotate(text,90)
    textpos = rotated.get_rect()
    textpos.centery = 80
    if line == 1:
        textpos.centerx = 99
    elif line == 2:
        textpos.centerx = 61
    elif line == 3:
        textpos.centerx = 25

def main():
    global screen

    size = width,height = 128,160
    screen = pygame.display.set_mode(size)

    while True:

if __name__ == '__main__':

Next, you need to make the script executable.

pi@raspberrypi ~ $ chmod 0755

And in the end, you can run the script.

pi@raspberrypi ~ $ sudo ./

The result should look something like this:


11 Responses to “ Connecting 1.8″ TFT LCD to Raspberry Pi ”

  1. Very instructive I’ll try the next weekend. Thak you very much for sharing this information and mostly for spend your time writing this clever tutorial.

  2. Would this work with the new debian jessie image?

  3. Tried to do this with debian jessie on a pi zero and could not get it to work. After following the step could not get the pi to restart. Would you expect this to work on a pi zero?

    • Well, the hardware is the same, so I don’t see why it shouldn’t work. The linux I used for this tutorial was based on Raspbian wheezy (?) if I’m not mistaken. Unfortunately, I don’t have a RPi zero to try it out myself…

  4. I am trying this over RaspberryPi 2 and simultaneously followed Kamal Mostafa blog and using the AdaFruit Tft but still its doesn’t work. I checked that its generating 1 frame buffer device file. Also I did connection for AdaFruit.
    Any suggestions what is going wrong as my screen is still white and not displaying anything.

  5. What OS does this work on? Will it work on RetroPie?

    • I believe this used to only work for Raspbian I’m afraid. If you manage to compile it for RetroPie, that would be cool!

      • I believe RetroPie is built on Raspbian, it says something about that on its website. I haven’t ever done something like this, but if I just use this tutorial, with a Pi Zero on RetroPie, do you think it would work? Also, for the Ubuntu server, could I run that on my PC? I also have a Pi B that I could run it on if that’s how it works.

Leave a Reply