We have an alternative solution for Raspberry Pi compatible HDMI display; the 3.2 inch Resistive TFT Touch Screen Display, which uses SPI Protocol (serial peripheral interface) to communicate with the main processor. It can be mounted directly to the GPIO pins and it doesn’t require any external power source. In here we have detailed explanation on how to install LCD drivers in a custom Raspbian image. The standard version of Raspbian does not include drivers for LCD touchscreens, so we will have to install and configure them manually.
- Raspberry Pi 2
- 3.2 inch Touch Display
- Touch pen
- SD card (Min. 8 GB)
Steps For Touchscreen Configuration
- The 3.2″ touchscreen uses SPI (serial peripheral interface) to communicate with the main processor. In an RPi board SPI communication is disabled by default. To enable it enter sudo raspi-config in the command prompt. The command will open up configuration menu, inside the configuration menu select “Advanced Options” (see below):
- Inside ‘Advanced Options‘, find the line that says “SPI ENABLE/DISABLE AUTOMATIC LOADING“. Select it and that will open up a confirmation box:
- Select Yes and press the enter key. Exit the configuration menu and type in sudo reboot ,for the changes to take effect :Note: This will work only on those Raspbian versions released after 1-31-2015.
- Now we will have to download the LCD driver, for which enter the following code in command prompt.
1sudo REPO_URI=https://github.com/notro/rpi-firmware rpi-update
- After that, configure the fbturbo video driverto divert the RPi display out from HDMI bus to the SPI bus. Enter the below given code in command prompt,
1sudo nano /usr/share/X11/xorg.conf.d/99-fbturbo.conf
It will open up a configuration file, find the line, : Option “fbdev” “/dev/fb0″ and change the fb0 to fb1. The fb0 option will output to HDMI bus, and the fb1 option will output to the SPI bus.Press Ctrl+X to exit and Y to save the file. Enter sudo reboot.
- After a reboot there wont be any output on HDMI screen. To input further commands in terminal window we will have to use the SSH method for remote connection with the Raspberry Pi board. Click here for details on how to setup the remote connection.
- Next step is to configure the kernel modules for display and touch functionality. To configure these kernel modules, we need to edit the /etc/modules file. In the command prompt, enter:
1sudo nano /etc/modules
- Currently, the kernel module for Raspberry Pi’s Broadcom processor snd-bcm2835 is set to load automatically. Add this code below the snd-bcm2835 line to support fbtft_device and ads7846_device modules:
12345678910111213spi-bcm2708ads7846fbtft_device rotate=270 name=waveshare32b gpios=dc:22,reset:27 speed=48000000fb_ili9340 width=320 height=240buswidth=8init=-1,0xCB,0x39,0x2C,0x00,0x34,0x02,-1,0xCF,0x00,0XC1,0X30,-1,0xE8,0x85,0x00,0x78,-1,0xEA,0x00,0x00,-1,0xED,0x64,0x03,0X12,0X81,-1,0xF7,0x20,-1,0xC0,0x23,-1,0xC1,0x10,-1,0xC5,0x3e,0x28,-1,0xC7,0x86,-1,0x36,0x28,-1,0x3A,0x55,-1,0xB1,0x00,0x18,-1,0xB6,0x08,0x82,0x27,-1,0xF2,0x00,-1,0x26,0x01,-1,0xE0,0x0F,0x31,0x2B,0x0C,0x0E,0x08,0x4E,0xF1,0x37,0x07,0x10,0x03,0x0E,0x09,0x00,-1,0XE1,0x00,0x0E,0x14,0x03,0x11,0x07,0x31,0xC1,0x48,0x08,0x0F,0x0C,0x31,0x36,0x0F,-1,0x11,-2,120,-1,0x29,-1,0x2c,-3
Note: “Starting from fb_ili9340 to the end of the line, ‘-3′, should be entered ALL IN ONE LINE !!!” fbtft_device denotes the kernel module of LCD and ads7846_device denotes the kernel module of touchscreen. ads7846 is the touchscreen controller chip used in the Waveshare 3.2″ LCD and many other touchscreen displays.
- Press Ctrl+X to exit and Y to save the changes.
- Now we need to edit the /boot/cmdline.txt file, which is the RPi’s boot-up configuration file. Use the following code in command prompt to open the file.
1sudo nano /boot/cmdline.txt
Replace it with all the below code in one line:
1dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p6 rootfstype=ext4 elevator=deadline rootwait fbtft_device.custom fbtft_device.name=waveshare32b fbtft_device.gpios=dc:22,reset:27 fbtft_device.bgr=1 fbtft_device.speed=48000000 fbcon=map:10 fbcon=font:ProFont6x11 logo.nologo dma.dmachans=0x7f35 console=tty1 consoleblank=0 fbtft_device.fps=50 fbtft_device.rotate=0
- Press Ctrl+X to exit and Y to save the changes. Now enter sudo reboot.
- Now we will have to activate the touch screen, use the following code:
1sudo nano /boot/config.txt
- Insert the below line at the end of config.txt,
- For touch screen calibration, enter:
1sudo nano /usr/share/X11/xorg.conf.d/99-calibration.conf
Add the code shown below in the configuration file.
12345Section "InputClass"Identifier "calibration"MatchProduct "ADS7846 Touchscreen"Option "Calibration" "3900 240 3900 240"EndSection
- Enter sudo reboot. Check whether the LCD and the touch screen are working properly.
- Some people have seems to have issues with touch panel, having x-axis inverted in X11. If you see this problem you’ll have to modify usr/share/X11/xorg.conf.d/10-evdev.conf. For that enter
1sudo nano /usr/share/X11/xorg.conf.d/10-evdev.conf
You need to modify the Section “InputClass” as shown below;
1234567Section "InputClass"Identifier "evdev touchscreen catchall"MatchIsTouchscreen "on"MatchDevicePath "/dev/input/event*"Driver "evdev"Option "InvertX" "true"EndSection
- Thats it! You are all set with your new I/O interface
Shop With Us:
- Click here to buy Raspberry Pi 2 from RhydoLabz.
- Click here to buy Raspberry Pi 2 Starter Kit from RhydoLabz.
- Click here to buy 3.2 inch Resistive Touch Screen TFT LCD for Raspberry Pi
Q: Will this LCD module support Rsapberry Pi versions B and B+?
Ans: Yes it will support the B and B+ versions with latest NOOBS image. The installation procedures are the same for these versions.