WaveShare Electronics touchscreen on Raspberry Pi model B

Tutorial on how to connect and use the old Raspberry Pi Model B with a WaveShare Electronics Touch Screen Display

Posted on July 08, 2015 by @MaurizioDimonte

Some weeks ago now I have lent my Raspberry Pis Model B+ and Model 2 to friends, so this very short tutorial is on how to connect and use the old Raspberry Pi Model B with a Touch Screen Display. Unfortunately, there aren’t many displays of this type on the market, and since I needed a HDMI interface for the connection with my first generation PI, I bought a 5inch Resistive LCD Display with these features from Aliexpress:

  • Vendor: WaveShare Electronics
  • Resolution: 800 x 480 px
  • Screen Type: Resistive screen (with 1 x Touch pen)
  • Working Voltage/Current: DC 5V / 2A
  • HDMI Interface (with 1 x HDMI connector)

This TFT (thin-film transistor) display has a ADS7843 / XPT2046 resistive 4-wire touch controller and is directly pluggable into any new version of Raspberry Pi. It is provided with custom Raspbian images, documents and drivers (the standard version of Raspbian does not include the drivers for LCD touch-screens). So I think: wow!, if this screen is specially designed for Rpi (so it is said), I can't wait to try it! This is what I did to test its compatibility (and ‘touchability’) with my old Pi.

All the HW components which you need are:

  • 1 x Raspberry Pi (any version) with Internet connection
  • 1 x HDMI cable (the provided HDMI connector is not fine with Pi Model B)
  • 1 x 8Gb SD card or microSD card with adapter (or more, don’t use the 4Gb or less)
  • 1 x DC 5v 500mA power supply

I used two separate 5v DC power supplies for the Touch Screen and the Pi (maybe a single one is not enough for both because a device must power the other via the GPIOs pin block). These are the steps:

  • Download the appropriate system image for your Pi (here or here), unzip it and flash your SD card with dd command (in Linux) or Win32DiskImager (in Windows). I have used this image: 5inch_HDMI_Raspbian-1215-02-05
  • Download the appropriate drivers for the chosen system and distro (here or here) and safe them in a directory without unzipping or uncompressing. I have used this one (5inch_HDMI_LCD.tar) because older driver packages gave me a common error at the end of the calibration process: “no calibratable device found”
  • With the new custom image installed in your Pi, this will boot directly to the desktop GUI. With a USB mouse and USB keyboard you can open the desktop terminal and run the ifconfig command to find your Pi’s IP address. In the latest custom image you’ll find a on-screen virtual keyboard, while the terminal is in the menu bar tools (Menu > Accessories > Terminal). However, for the scanning of the network, I am comfortable with the useful mobile app Fing (Android and iOS).
  • Now, from a remote terminal, you can login in your target Pi through the pre-enabled ssh service (with PuTTY or WinSCP if you are in Windows). The username is pi (or root if enabled) and the password is raspberry (enter yes to accept the remote host’s authenticity). You can change the root account password running:
# ssh pi@your_ip_address
$ sudo -i
# passwd root

After updating the packages with sudo apt-get update you may run sudo raspi-config and select the first menu-option Expand Filesystem to fill the SD card partition (enter OK).

  • Enter Advanced Option, enter SPI ENABLE/DISABLE AUTOMATIC LOADING, enter YES and finally run sudo reboot at the command prompt.
  • Perhaps with an older Raspian version (before 01-31-2015) you need to manually enable the SPI (serial peripheral interface) by commenting with a # the line: blacklist spi-bcm2708 at the head of the blacklist file /etc/modprobe.d/raspi-blacklist.conf (see this tutorial).

$ sudo nano /etc/modprobe.d/raspi-blacklist.conf

Press Ctrl-X then Y to exit nano text editor and save the changes. Also make sure that the file /boot/config.txt contains the following uncommented lines:

# uncomment if hdmi display is not detected and composite is being output
hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (here we are forcing 800x480!)
hdmi_group=2
hdmi_mode=1
hdmi_mode=87
hdmi_cvt 800 480 60 6 0 0 0

I don’t know if also the required following lines (and the comment before gpu mem=128) are actually needed

start_file=start_x.elf
fixup_file=fixup_x.elf
#gpu_mem=128

Now you can create a directory to keep the previously downloaded 5inch_HDMI_LCD.tar.gz file. The file can be copied into it from the browser, from a USB pen-drive or from a remote host with the command

scp /your_directory/5inch_HDMI.tar.gz pi@ip_address:/opt/drivers_hdmi/

Remember to give the appropriate permissions to the directory:

$ sudo mkdir /opt/drivers_hdmi/
$ sudo chmod -R 777 /opt/drivers_hdmi/

Move to the new directory and uncompress the downloaded .tar.gz file

$ cd /opt/drivers_hdmi/
$ tar xvf 5inch_HDMI_LCD.tar.gz

Move to the extracted directory and launch the script you find there:

$ cd /opt/drivers_hdmi/5inch_HDMI_LCD/
$ sudo ./5inch_HDMI_LCD

The script will install and configure the appropriate kernel modules stored in the directory. After the automatic rebooting, return to the same directory and run the command for the touch-screen calibration:

$ cd /opt/drivers_hdmi/5inch_HDMI_LCD/
$ su pi
$ DISPLAY=:0.0 xinput_calibrator

The document says that after the calibration you should save the edited values in the /etc/X11/xorg.conf.d/99-calibration.conf. If the file and directory do not exist you must create them, but I had to remove the file and the directory just created because that caused a black screen on startup after the rebooting.

$ sudo mkdir /etc/X11/xorg.conf.d
$ sudo nano /etc/X11/xorg.conf.d/99-calibration.conf

Unfortunately, once the process is terminated the display doesn’t display any touch function. I also used a latest driver package (this one) but it’s the same story: I’m not in touch with the touch-screen! Actually I don’t know if with a Raspberry Pi 2 (second generation) and most recent images and drivers (like this and this) the story can change. As soon as I can I will try this way.

Other useful links: