Monday, May 2, 2016

Raspberry Pi 3 All-in-One PC with LCD Monitor (2): Revenge

Last time, I got as far as turning the Raspberry Pi 3 into a wireless Linux terminal.
The final step was downloading LCD-show.tar.gz, but that version doesn't work correctly on the current Raspbian Jessie.
This is actually noted in the Waveshare manual — I just missed it.

Also: if you install Raspbian from the URL in the Amazon product listing, it works temporarily, but the LCD stops displaying after an OS update.

This time we'll install a Jessie-compatible driver to get the LCD working properly.

Auto-start X Window on boot


pi@raspberrypi:~ $ sudo raspi-config

Under Boot Options, select Desktop Autologin.
Note: Autologin is required for a later step, so don't skip this.
raspi-config boot options menu raspi-config desktop autologin selection

Installing the LCD driver




Download the Jessie-compatible LCD driver from the Image section of the Waveshare manual and load the 4-inch driver:
http://www.waveshare.com/wiki/4inch_RPi_LCD_(A)#Image
pi@raspberrypi:~ $ wget http://www.waveshare.com/w/upload/9/9d/LCD-show-151020.tar.gz
pi@raspberrypi:~ $ tar xzfv LCD-show-151020.tar.gz
pi@raspberrypi:~ $ cd LCD-show
pi@raspberrypi:~/LCD-show $ sudo ./LCD4-show

After a moment it reboots automatically and the LCD starts displaying.
Here's what it looks like — no cables except power. Clean.
Raspberry Pi 3 with 4-inch LCD running Raspbian desktop

Calibrating the touchscreen


With just the driver installed, the touchscreen coordinates are vertically flipped for some reason. Calibration fixes this.

First, install xinput-calibrator, which is bundled with the driver:
pi@raspberrypi:~/LCD-show $ sudo dpkg -i -B xinput-calibrator_0.7.5-1_armhf.deb


Then run xinput_calibrator — note that it requires the pi user to be logged into the display, which is why Autologin was needed earlier:
pi@raspberrypi:~ $ DISPLAY=:0.0 xinput_calibrator
Calibrating EVDEV driver for "ADS7846 Touchscreen" id=6
current calibration values (from XInput): min_x=3950, max_x=172 and min_y=3871, max_y=194


A calibration screen appears with markers to tap. Touch each marker and calibration is complete.
Touchscreen calibration screen with target markers

Bonus: connecting a Bluetooth keyboard


Since we're cable-free, let's set up a Bluetooth keyboard too.
The Raspberry Pi 3 has built-in Bluetooth, so pairing is all it takes:
pi@raspberrypi:~ $ bluetoothctl
[bluetooth]# scan on
Discovery started
[CHG] Controller xx:xx:xx:xx:xx:xx Discovering: yes
[bluetooth]# scan off
Discovery stopped
[bluetooth]# pair xx:xx:xx:xx:xx:xx
Attempting to pair with xx:xx:xx:xx:xx:xx
Pairing successful
[CHG] Device xx:xx:xx:xx:xx:xx Connected: no
[bluetooth]# connect xx:xx:xx:xx:xx:xx
Attempting to connect to xx:xx:xx:xx:xx:xx
Connection successful
[bluetooth]# trust
[bluetooth]# exit


Done


And there we have it — a compact little YouTube terminal.
Completed Raspberry Pi 3 all-in-one touchscreen unit

[Update]
You can also fix the cursor alignment without calibration by editing the X Window config directly:
pi@raspberrypi:~ $ sudo vi /etc/X11/xorg.conf.d/99-calibration.conf
pi@raspberrypi:~ $ cat /etc/X11/xorg.conf.d/99-calibration.conf
Section "InputClass"
Identifier      "calibration"
MatchProduct    "ADS7846 Touchscreen"
Option  "Calibration"   "3950 172 194 3871"
#Option  "Calibration"   "3950 172 3871 194"
Option  "SwapAxes"      "1"
EndSection

The original value was "3950 172 3871 194" — just swap the last two numbers.


[Update 2]
There appears to be a way to get the display working without using the Waveshare driver at all:
http://www.orsx.net/archives/5422

No comments:

Post a Comment