© Warren Gay 2018
Warren GayAdvanced Raspberry Pihttps://doi.org/10.1007/978-1-4842-3948-3_24

24. LCD HDMI Display

Warren Gay1 
(1)
St. Catharine’s, Ontario, Canada
 

Some Pi projects are best served with a simple LCD display. The associated touch control frees you from a keyboard and mouse. This chapter will examine one example of a 5-inch 800x480 pixel LCD touchscreen and describe how to set it up.

The Display Unit

The featured display unit was advertised as “5 Inch 800 x 480 HD TFT LCD Touch Screen For Raspberry PI 2 Model B /​ B+ /​ A+ /​ B” and sold for approximately $42 USD. It features a 4-wire resistive XPT2046 touch controller. Figure 24-1 illustrates what comes in the kit.
../images/326071_2_En_24_Chapter/326071_2_En_24_Fig1_HTML.jpg
Figure 24-1

The 5 Inch HDMI Display kit with stylus, DVD, and LCD unit (with plastic covering still attached). USB power cable is not included.

The backside of the LCD shows an HDMI connector (Figure 24-2, bottom middle), a power USB connector (right of HDMI connector), a backlight switch (upper right), a 13x2 connector (upper center), and a LVDS connector (bottom left).
../images/326071_2_En_24_Chapter/326071_2_En_24_Fig2_HTML.jpg
Figure 24-2

The backside of the 5 Inch HDMI Display with four stand-offs screwed in

If you read the included DVD instructions, you are expected to run a script named LCD5-show but don’t run it—it is out of step with the current releases of Raspbian Linux. In fact, the script may leave your Pi unbootable after it is run. This chapter will use the script for a guide, with the corrections applied.

Installation

The first thing to do is to copy the software from DVD or fetch it with git. The following git command fetches the software and places it into the ~pi/LCD directory:
$ git clone https://github.com/goodtft/LCD-show.git ./LCD
$ cd ./LCD

Install Script

Listing 24-1 shows the provided install script that will act as our guide but cannot be used directly. It may render your Pi unbootable. The underlined lines in the listing highlight some problem areas. Let’s step through the corrected steps manually in the sections that follow.
0001: #!/bin/bash
0002:  sudo rm -rf /etc/X11/xorg.conf.d/40-libinput.conf
0003:  sudo cp -rf ./boot/config-5.txt /boot/config.txt
0004: if [ -b /dev/mmcblk0p7 ]; then
0005: sudo cp ./usr/cmdline.txt-noobs /boot/cmdline.txt
0006: else
0007: sudo cp ./usr/cmdline.txt /boot/
0008: fi
0009: sudo cp ./usr/inittab /etc/
0010: sudo cp -rf ./usr/99-fbturbo.conf-HDMI /usr/share/X11/xorg.conf.d/99-fbturbo.conf
0011: sudo mkdir /etc/X11/xorg.conf.d
0012: sudo cp -rf ./usr/99-calibration.conf-5 /etc/X11/xorg.conf.d/99-calibration.conf
0013: nodeplatform=`uname -n`
0014: kernel=`uname -r`
0015: version=`uname -v`
0016: if test "$nodeplatform" = "raspberrypi";then
0017: echo "this is raspberrypi kernel"
0018: version=${version%% *}
0019: version=${version#*#}
0020: echo $version
0021: if test $version -lt 970;then
0022: echo "reboot"
0023: else
0024: echo "need to update touch configuration"
0025: if test $version -ge 1023;then
0026: echo "install xserver-xorg-input-evdev_2.10.5-1"
0027: sudo dpkg -i -B xserver-xorg-input-evdev_2.10.5-1_armhf.deb
0028: else
0029: echo "install xserver-xorg-input-evdev_1%3a2.10.3-1"
0030: sudo dpkg -i -B xserver-xorg-input-evdev_1%3a2.10.3-1_armhf.deb
0031: fi
0032: sudo cp -rf /usr/share/X11/xorg.conf.d/10-evdev.conf
                  /usr/share/X11/xorg.conf.d/45-evdev.conf
0033: echo "reboot"
0034: fi
0035: else
0036: echo "this is not raspberrypi kernel, no need to update touch configure, reboot"
0037: fi
0038: sudo reboot
Listing 24-1

Provided LCD5-show install script (do not run!)

Backup

Before changing anything on your system, back up a couple of critical files in case you want to restore the configuration later. Copy the following two files to your home directory or a place of your own choosing:
# cp /boot/config.txt ~pi/config.txt.bak
# cp /boot/cmdline.txt ~pi/cmdline.txt.bak

To restore your original configuration, you merely need to copy these back and reboot.

File 40-libinput.conf

The install script in Listing 24-1, line 2 attempts to delete a file that does not exist (there is no /etc/X11/xorg.conf.d directory provided by Raspbian Linux). But there is a file in /usr/share/X11/xord.conf.d/40-libinput.conf. You may find that you can leave it there but I recommend that you rename it, to avoid any possible conflict. You’ll need to undo this later, if you choose to restore your system to its original state.

To disable it without deleting it, simply rename it with a different suffix (like .was).
# mv /usr/share/X11/xorg.conf.d/40-libinput.conf
     /usr/share/X11/xorg.conf.d/40-libinput.conf.was
Now is a good time to change to your LCD software directory, if you are not already at that directory:
# cd ~pi/LCD

Edit /boot/config.txt

If you ran the install script from Listing 24-1, line 3 would have wiped out any changes that you previously made to your /boot/config.txt file. Worse, the old install file may not be fully applicable to the current version of Raspbian. You are better off to edit the file making the changes you actually need.
# nano /boot/config.txt

If you think you have messed up badly, you can recover by copying the backup file over it and start over.

When making changes, you can sometimes just uncomment a line. In other cases you will need to add lines (at the end of the file is best). If you have a directive in conflict, you can comment it out with a hash (#) character in the first column and simply add your change at the end of the file.

Make the following changes:
dtparam=spi=on
max_usb_current=1
hdmi_force_hotplug=1
config_hdmi_boost=7
hdmi_group=2
hdmi_mode=1
hdmi_mode=87
hdmi_drive=1
hdmi_cvt 800 480 60 6 0 0 0
dtoverlay=ads7846,cs=1,penirq=25,penirq_pull=2,speed=50000,ke

Save your changes. This step replaces line 3 of the install script.

Edit /boot/cmdline.txt

The non-noobs step that is performed next is line 7 of Listing 24-1. Like the previous step, it clobbers the file with potentially incompatible options (it may affect the path to the root device). It is better to simply edit the file with the changes needed. Add the following text at the end of the line, with a space separating any previous text (for noobs and non-noobs):
fbcon=map:10 fbcon=font:ProFont6x11

Save the changes.

File 99-fbturbo.conf

Line 9 of the Listing 24-1 install script no longer applies. For better or for worse, Raspbian Linux, like Debian, uses systemd. There is no longer a /etc/inittab file so that step can be skipped.

Line 10 on the other hand instructs us to copy the following:
# cp -rf ./usr/99-fbturbo.conf-HDMI /usr/share/X11/xorg.conf.d/99-fbturbo.conf

File 99-calibration.conf-5

Script line 11 does not apply (directory /etc/X11/xorg.conf.d is not searched) and should be skipped.

Perform the following copy, noting the change in the second pathname (underlined):
# cp -rf ./usr/99-calibration.conf-5 /usr/share/X11/xorg.conf.d/99-calibration.conf

The script used target directory /etc/X11, but the correct directory name is /usr/share/X11 in the command above.

Driver Install

The install script attempts to determine if:
  1. 1.

    This is a Raspberry Pi (lines 16–17), and

     
  2. 2.

    The version of the Raspbian Linux (lines 18–19).

     

Test #1 depends upon the host name of your Pi being “raspberrypi.” If you had already customized the host name and ran that script, it would have installed the wrong driver, thinking it was not a Pi. Oops!

There are some tests for the version of Raspbian Linux performed in script lines 21 and 25. These are based upon the results of:
# uname -v
#1110 SMP Mon Apr 16 15:18:51 BST 2018

The version number in this example is 1110. Line 21 indicates that no driver install is required if your Raspbian version is less than 970. In that case it is time to simply reboot (perform a shutdown and power off instead). On the other hand, a recent version of Raspbian, version 1023 or later requires that a driver be installed.

In your ~pi/LCD directory, there should exist the debian driver package you want to install. To see what you’re installing, query the package file with -c using the file name shown:
# dpkg -c xserver-xorg-input-evdev_2.10.5-1_armhf.deb
drwxr-xr-x root/root         0 2017-01-18 18:26 ./
drwxr-xr-x root/root         0 2017-01-18 18:26 ./usr/
drwxr-xr-x root/root         0 2017-01-18 18:26 ./usr/lib/
drwxr-xr-x root/root         0 2017-01-18 18:26 ./usr/lib/xorg/
drwxr-xr-x root/root         0 2017-01-18 18:26 ./usr/lib/xorg/modules/
drwxr-xr-x root/root         0 2017-01-18 18:26 ./usr/lib/xorg/modules/input/
-rw-r--r-- root/root     39292 2017-01-18 18:26 ./usr/lib/xorg/modules/input/evdev_drv.so
drwxr-xr-x root/root         0 2017-01-18 18:26 ./usr/share/
drwxr-xr-x root/root         0 2017-01-18 18:26 ./usr/share/X11/
drwxr-xr-x root/root         0 2017-01-18 18:26 ./usr/share/X11/xorg.conf.d/
-rw-r--r-- root/root      1099 2017-01-18 18:26 ./usr/share/X11/xorg.conf.d/10-evdev.conf
drwxr-xr-x root/root         0 2017-01-18 18:26 ./usr/share/bug/
drwxr-xr-x root/root         0 2017-01-18 18:26 ./usr/share/bug/xserver-xorg-input-evdev/
drwxr-xr-x root/root         0 2017-01-18 18:26 ./usr/share/doc/
drwxr-xr-x root/root         0 2017-01-18 18:26 ./usr/share/doc/xserver-xorg-input-evdev/
-rw-r--r-- root/root      6293 2017-01-18 18:26 ./usr/share/doc/
                               xserver-xorg-input-evdev/changelog.Debian.gz
-rw-r--r-- root/root     83217 2017-01-18 07:15 ./usr/share/doc/
                               xserver-xorg-input-evdev/changelog.gz
-rw-r--r-- root/root      4988 2017-01-18 18:26 ./usr/share/doc/
                               xserver-xorg-input-evdev/copyright
drwxr-xr-x root/root         0 2017-01-18 18:26 ./usr/share/man/
drwxr-xr-x root/root         0 2017-01-18 18:26 ./usr/share/man/man4/
-rw-r--r-- root/root      4306 2017-01-18 18:26 ./usr/share/man/man4/evdev.4.gz
lrwxrwxrwx root/root         0 2017-01-18 18:26 ./usr/share/bug/xserver-xorg-
                               input-evdev/script -> ../xserver-xorg-core/script
Install the debian package using the following command:
# dpkg -i -B xserver-xorg-input-evdev_2.10.5-1_armhf.deb
After that install completes, perform the last copy command, from line 32 of the script:
# cp -rf /usr/share/X11/xorg.conf.d/10-evdev.conf /usr/share/X11/xorg.conf.d/45-evdev.conf

Shutdown

Now it is time to hook up the hardware with the Pi powered off. Perform a system shutdown:
# sync
# /sbin/shutdown -h now

The shutdown procedure will normally perform the sync command for you, but I like the comfort of knowing it has been done (it flushes out your unwritten disk cache).

Plugging In

At this point the software and configuration is ready. With the power off, plug the LCD unit into the Pi with the 13x2 connector interfacing one end of the Pi’s GPIO strip as shown in Figure 24-3. The illustration is from the GPIO side, not fully seated so that you can see the pins being inserted.
../images/326071_2_En_24_Chapter/326071_2_En_24_Fig3_HTML.jpg
Figure 24-3

The 5 inch LCD 13x2 connector being attached to the GPIO strip, at the end opposite of the USB connectors (Pi 3 B+). The connector is not yet fully seated.

It is very easy to get this wrong, so check and double-check. A mistake here might ruin your day. If this is mated correctly, the HDMI connectors should line up on the opposite side as shown in Figure 24-4.
../images/326071_2_En_24_Chapter/326071_2_En_24_Fig4_HTML.jpg
Figure 24-4

The LCD attached to the Pi using the supplied HDMI to HDMI side adapter

If the HDMI adapters don’t seem to be aligned, recheck that you have the 13x2 connector plugged into the GPIO strip correctly.

With the power cables in inserted, power the unit on. The LCD should display a brief flicker of light as the backlighting starts up. If you see no activity at all, it might be wise to immediately power off and recheck connections.

Boot

Once the Pi is booting up, watch for the desktop to appear. Once your desktop appears and a little mouse arrow is displayed, try tapping the screen to move the arrow. If the touch controls fail to work, check the following:
  • Recheck the mating of connections. A bad connection or misplaced connection will affect the touch control.

  • Recheck the /boot/config.txt and /boot/cmdline.txt files.

  • Check the power usage (next section).

  • Check the revision of the LCD panel. Older units used GPIO 22 for the penirq. This is specified in the /boot/config.txt file, underlined below:
    dtoverlay=ads7846,cs=1,penirq=25,penirq_pull=2,speed=50000,ke

Power

The unit I have consumes about 242 mA with backlight on and 168 mA when off. Be sure that your Pi and LCD panel are adequately supplied. A 2.5 A supply is recommended for the Pi 3 B+ but with the LCD plugged into a USB port, you might run out of current capacity during peak usage.

Connections

The connections on the 13x2 connector are described in Table 24-1. When wiring the touch controls manually, be careful not to confuse connections “MO” and “MI.” These curiously labeled connections indicate MISO (MO) and MOSI (MI) respectively, using the slave device point of view.
Table 24-1

Connections of the 13x2 LCD Connector

Description

Pin

#

#

Pin

Description

Power (+5V)

+5V

2

1

+3.3V

 

Power (+5V)

+5V

4

3

  

Ground

Gnd

6

5

  

NC

 

8

7

  

NC

 

10

9

Gnd

Ground

NC

 

12

11

  

Gnd

Gnd

14

13

  

NC

 

16

15

  

NC

 

18

17

+3.3V

 

Gnd

Gnd

20

19

MI

MOSI

Pen IRQ

GPIO 25

22

21

MO

MISO

NC

 

24

23

SCK

SCK

Pen Chip Select

GPIO-7

26

25

Gnd

Ground

Summary

One problem that often occurs is that hardware gets sale priced when the software becomes stale. This happens as the operating systems are updated and the software remains static. This can work in your favor, if you can work through the details of the install manually, as was done in this chapter.

The LCD screen presented provides you with a flavor of what to expect in similar offerings. One thing to be careful of is to make sure that any necessary driver support exists for your version of Linux before you buy.

A touch-sensitive LCD screen opens many new possibilities for your imagination.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.111.33