Difference between revisions of "Template:4inch HDMI LCD Manual"

From Waveshare Wiki
Jump to: navigation, search
Line 38: Line 38:
 
  dtoverlay=ads7846,cs=1,penirq=25,penirq_pull=2,speed=50000,keep_vref_on=0,swapxy=0,pmax=255,xohms=150,xmin=200,xmax=3900,ymin=200,ymax=3900
 
  dtoverlay=ads7846,cs=1,penirq=25,penirq_pull=2,speed=50000,keep_vref_on=0,swapxy=0,pmax=255,xohms=150,xmin=200,xmax=3900,ymin=200,ymax=3900
 
  display_rotate=3
 
  display_rotate=3
 
+
hdmi_drive=1
 +
hdmi_force_hotplug=1
 
<font color=red>Note: For Raspberry Pi 4, you need to comment out dtoverlay=vc4-fkms-V3D.
 
<font color=red>Note: For Raspberry Pi 4, you need to comment out dtoverlay=vc4-fkms-V3D.
 
  #dtoverlay=vc4-fkms-V3D.</font>
 
  #dtoverlay=vc4-fkms-V3D.</font>

Revision as of 01:47, 30 November 2020

Features

  • 800×480 hardware resolution
  • Resistive touch control
  • IPS technology, high quality, and perfect displaying from the very wide viewing angle.
  • It is compatible and can be directly inserted in any version of Raspberry Pi (For the Raspberry Pi 1 B and Raspberry Pi Zero, HDMI cable is required and should be purchase separately).
  • Drivers provided (works with your own Raspbian/Ubuntu/Kali and Retropie system directly)
  • Also works as a computer monitor, in this case, the touch panel is unavailable and HDMI cable is required.
  • When only used for display, does not occupy any I/O resources (using touch function will occupy I/O resources).
  • Backlight control to lower power consumption.

Video

Getting Started

Hardware Connection

Hardware connection
  1. Plug the LCD to your Raspberry Pi:
    • There are 40 pins on Raspberry Pi Model A+/B+/2 B/3 B but only 26 pins on the LCD, so you should pay attention to connecting the pins to your Pi accordingly.
  2. Connect the HDMI Connector to both the HDMI interfaces on the LCD and the Pi.
    • You should connect the LCD to Raspberry Pi Model B or Raspberry Pi Zero with an HDMI cable rather than an HDMI Connector.
  3. Turn on the "backlight" switch on the back of the LCD.

Install the touch driver

You can enable the touch in two ways: Method 1. install the driver to your Raspbian/Ubuntu Mate OS. Method 2. use the Ready-to-use image file of which LCD driver was pre-installed.

Method 1. Driver installation

Please download the latest version of the image on the Raspberry Pi official website. (Raspbian/Ubuntu Mate/Kali or Retropie)

1) Download the compressed image file to the PC, and unzip it to get the .img file.

2) Connect the TF card to the PC, open the Win32DiskImager software, select the system image downloaded in step 1 and click‘Write’ to write the system image. ( How to write an image to a micro SD card for your Pi? See RPi Image Installation Guides for more details)

3) After the image has finished writing, open the config.txt file in the root directory of the TF card. Add the following code at the end of config.txt, then save and quit the TF card safely.

hdmi_group=2
hdmi_mode=87
hdmi_timings=480 0 40 10 80 800 0 13 3 32 0 0 0 60 0 32000000 3
dtoverlay=ads7846,cs=1,penirq=25,penirq_pull=2,speed=50000,keep_vref_on=0,swapxy=0,pmax=255,xohms=150,xmin=200,xmax=3900,ymin=200,ymax=3900
display_rotate=3
hdmi_drive=1
hdmi_force_hotplug=1

Note: For Raspberry Pi 4, you need to comment out dtoverlay=vc4-fkms-V3D.

#dtoverlay=vc4-fkms-V3D.

4) Connect the TF card to the Raspberry Pi, start the Raspberry Pi. The LCD will display after booting up, and then log in to the Raspberry Pi terminal (you can connect the Raspberry Pi to the HDMI display or log in remotely with SSH).

5) Then open the terminal of Raspberry Pi to install the touch driver which can be found in the /boot/ directory. Note: The Raspberry Pi must be connected to the network, or else the touch driver won't be successfully installed.

git clone https://github.com/waveshare/LCD-show.git
cd LCD-show/
chmod +x LCD4-800x480-show
./LCD4-800x480-show

The touch function will work after restart. For ease of use, you can set the screen orientation, see: #Screen orientation settings.

Method 2. Using Ready-to-use image

The image file with the pre-installed driver is located in the IMAGE directory of the CD. Extract the .7z file and you will get a .img file. Write the image to your micro SD card (How to write an image to a micro SD card for your Pi? See RPi Image Installation Guides for more details). Then insert the card to your Pi, power up and enjoy it.

Screen orientation settings

After touch driver installed, the screen orientation can be set by these commands:

  • 0 degree rotation
cd LCD-show/
./LCD4-800x480-show 0
  • 90 degree rotation
cd LCD-show/
./LCD4-800x480-show 90
  • 180 degree rotation
cd LCD-show/
./LCD4-800x480-show 180
  • 270 degree rotation
cd LCD-show/
./LCD4-800x480-show 270

Touch screen calibration

This LCD can be calibrated through the xinput-calibrator program. Note: The Raspberry Pi must be connected to the network, or else the program won't be successfully installed.

  • Run the following command to install:
sudo apt-get install xinput-calibrator 
  • Click the "Menu" button on the taskbar, choose "Preference" -> "Calibrate Touchscreen".
  • Finish the touch calibration following the prompts. Maybe rebooting is required to make calibration active.
  • You can create a 99-calibration.conf file to save the touch parameters (not necessary if file exists).
sudo mkdir /etc/X11/xorg.conf.d
sudo nano /etc/X11/xorg.conf.d/99-calibration.conf
  • Save the touch parameters (may differ depending on LCD) to 99-calibration.conf, as shown in the picture:

5inch HDMI LCD FAQ1.jpg

  • Press the keys Ctrl+X, and select option Y to save the modification.
  • The modification will be valid after rebooting the system. Enter the following command for system reboot:
sudo reboot

Install virtual keyboard

1.Execute the following code to install the corresponding software.

sudo apt-get update
sudo apt-get install matchbox-keyboard
sudo nano /usr/bin/toggle-matchbox-keyboard.sh

2.Copy the following content to toggle-matchbox-keyboard.sh, save and exit.

#!/bin/bash
#This script toggle the virtual keyboard
PID=`pidof matchbox-keyboard`
if [ ! -e $PID ]; then
killall matchbox-keyboard
else
matchbox-keyboard &
fi

3.Execute the following code.

sudo chmod +x /usr/bin/toggle-matchbox-keyboard.sh
sudo mkdir /usr/local/share/applications
sudo nano /usr/local/share/applications/toggle-matchbox-keyboard.desktop

4. Copy the following content to toggle-matchbox-keyboard.desktop, save and exit.

[Desktop Entry]
Name=Toggle Matchbox Keyboard
Comment=Toggle Matchbox Keyboard`
Exec=toggle-matchbox-keyboard.sh
Type=Application
Icon=matchbox-keyboard.png
Categories=Panel;Utility;MB
X-MB-INPUT-MECHANSIM=True

5.Execute the following code, this step must use the "pi" user authority, if you use the administrator authority, the file will not be found.

sudo nano /etc/xdg/lxpanel/LXDE-pi/panels/panel

6.Find the code similar to the following.(the icon of different versions may be different)

Plugin {
type = launchbar
Config {
Button {
id=lxde-screenlock.desktop
}
Button {
id=lxde-logout.desktop
}
}

7. Add the following code to add a Button item, as shown below.

Button {
id=/usr/local/share/applications/toggle-matchbox-keyboard.desktop
}

RPILCD-INSTALL-KEYBOARD01.png

8. Execute the following code to restart the system, you can see a virtual keyboard icon in the upper left corner of the LCD.

sudo reboot

Interface

PIN NO. SYMBOL DESCRIPTION
1, 17 3.3V Power positive (3.3V power input)
2, 4 5V Power positive (5V power input)
3, 5, 7, 8, 10, 11, 12, 13, 15, 16, 18, 24 NC NC
6, 9, 14, 20, 25 GND Ground
19 TP_SI SPI data input of Touch Panel
21 TP_SO SPI data output of Touch Panel
22 TP_IRQ Touch Panel interrupt, low level while the Touch Panel detects touching
23 TP_SCK SPI clock of Touch Panel
26 TP_CS Touch Panel chip selection, low active